Created
February 17, 2022 10:49
-
-
Save szymonlesisz/cae26e1b08842e5a61a5c2789a102b68 to your computer and use it in GitHub Desktop.
suite bash autocomplete
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. 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