Skip to content
This repository has been archived by the owner on Jan 22, 2023. It is now read-only.

Commit

Permalink
feat: add shell completion
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperupcall committed Jan 25, 2021
1 parent d93ac5d commit 447ff24
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions completions/dotty.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# shellcheck shell=bash

# based on https://tylerthrailkill.com/2019-01-19/writing-bash-completion-script-with-subcommands/
_dotty() {
local i=1 cmd

# iterate over COMP_WORDS (ending at currently completed word)
# this ensures we bm_get command completion even after passing flags
while [[ "$i" -lt "$COMP_CWORD" ]]; do
local s="${COMP_WORDS[i]}"
case "$s" in
# if our current word starts with a '-', it is not a subcommand
-*) ;;
# we are completing a subcommand, set cmd
*)
cmd="$s"
break
;;
esac
(( i++ ))
done

# check if we're completing 'dotty'
if [[ "$i" -eq "$COMP_CWORD" ]]; then
local cur="${COMP_WORDS[COMP_CWORD]}"
# shellcheck disable=SC2207
COMPREPLY=($(compgen -W "status reconcile --version --help" -- "$cur"))
return
fi

# if we're not completing 'dotty', then we're completing a subcommand
case "$cmd" in
status)
COMPREPLY=() ;;
reconcile)
COMPREPLY=() ;;
*)
;;
esac

} && complete -F _dotty dotty

0 comments on commit 447ff24

Please sign in to comment.