Last active
July 2, 2024 10:31
-
-
Save szymonlesisz/8dc07fbdc1ee90272cac20a8f3a1ed4e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# 3a. edit ~/.bash_profile and add | |
# ``` | |
# source ~/.bash_suite | |
# ``` | |
# 3b. exit ~/.bashrc and add | |
# ``` | |
# if [ -f ~/.base_suite ]; then | |
# . ~/.bash_suite | |
# fi | |
# ``` | |
# 4. reload current shell: | |
# ``` | |
# source ~/.bash_profile | |
# ``` | |
# 5. type sui<tab> <tab> | |
SUITE_REPO=~/Workspace/suite | |
function suite() { | |
if ([ -f /etc/NIXOS ] || [ -f ~/.nix-profile/bin/nix-shell ]) && [ -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 | |
local params=($@) | |
local workspace="" | |
if [ -d "$SUITE_REPO/packages/${params[0]}" ]; then | |
workspace="@trezor" | |
fi | |
if [ -d "$SUITE_REPO/suite-common/${params[0]}" ]; then | |
workspace="@suite-common" | |
fi | |
echo "yarn workspace $workspace/$@"; | |
yarn workspace $workspace/$@; | |
} | |
_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") | |
$(compgen -d -- $SUITE_REPO/suite-common/ | 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