Skip to content

Instantly share code, notes, and snippets.

@szymonlesisz
Created February 17, 2022 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szymonlesisz/cae26e1b08842e5a61a5c2789a102b68 to your computer and use it in GitHub Desktop.
Save szymonlesisz/cae26e1b08842e5a61a5c2789a102b68 to your computer and use it in GitHub Desktop.
suite bash autocomplete
# suite workspace autocomplete
# HOW TO:
# 1. download to ~/.bash_suite
# 2. edit ~/.bash_profile and add source ~/.base_suite line
# 3. reload shell: source ~/.bash_profile
SUITE_REPO=~/Workspace/suite
function suite() {
if [ -f /etc/NIXOS ] && [ -z "$IN_NIX_SHELL" ]; then
echo "Entering nix-shell. Run this command again";
cd $SUITE_REPO && nix-shell
return 0;
fi
if [ $# -eq 0 ]; then
echo "No params";
return 0;
fi
yarn workspace @trezor/$@;
}
_suite () {
local IFS=$' \t\n' # normalize IFS
local cur;
cur=${COMP_WORDS[$COMP_CWORD]};
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $( compgen -d -- $SUITE_REPO/packages/ | xargs --no-run-if-empty -l1 basename | grep "^$cur" ) );
return 0;
fi
if [ $COMP_CWORD -eq 2 ]; then
local SCRIPTS_LIST=("build:lib" "dev" "type-check" "test:unit" "lint") # TODO: read it from package.json
CANDIDATES=($(compgen -W "${SCRIPTS_LIST[*]}" -- "$cur"))
COMPREPLY=($(printf '%q\n' "${CANDIDATES[@]}"));
return 0;
fi
COMPREPLY=(); # do not autocomplete 3+ args
return 0;
}
complete -F _suite suite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment