Skip to content

Instantly share code, notes, and snippets.

@MattSegal
Created October 3, 2022 01:53
Show Gist options
  • Save MattSegal/d8396561cf5a4c676b7c9cb5d24a96ad to your computer and use it in GitHub Desktop.
Save MattSegal/d8396561cf5a4c676b7c9cb5d24a96ad to your computer and use it in GitHub Desktop.
a tiny bash function that turns a folder containing bash scripts into a CLI with auto complete
function matt {
if [[ ! -d "./matt "]]; then
echo "No matt folder found."
else
options=$(ls matt | grep ".*\.sh$" | cut -d. -f1)
if [[ -z "$1" ]]; then
echo -e "Options:\n\n$options\n"
else
echo "Running $1"
bash ./matt/$1.sh ${@:2}
fi
fi
}
function _matt_completions {
if [[ -d "./matt" ]]; then
if [ "${#COMP_WORDS[@]}" != "2" ]; then
return
fi
options=$(ls matt | grep ".*\.sh$" | cut -d. -f1)
COMPREPLY=($(compgen -W "$options" "${COMP_WORDS[1]}"))
fi
}
complete -F _matt_completions matt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment