Last active
February 17, 2022 10:53
-
-
Save szymonlesisz/8dc07fbdc1ee90272cac20a8f3a1ed4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# suite workspace autocomplete | |
# HOW TO: | |
# 1. download to ~/.bash_suite | |
# 2. update SUITE_REPO variable | |
# 3. edit ~/.bash_profile and add source ~/.base_suite line | |
# 4. reload shell: source ~/.bash_profile | |
# 5. type sui<tab> <tab> | |
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