This repository has been archived by the owner on Jan 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d93ac5d
commit 447ff24
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
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
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 |