aboutsummaryrefslogtreecommitdiffstats
path: root/completions/gitctl.bash
diff options
context:
space:
mode:
Diffstat (limited to 'completions/gitctl.bash')
-rw-r--r--completions/gitctl.bash48
1 files changed, 48 insertions, 0 deletions
diff --git a/completions/gitctl.bash b/completions/gitctl.bash
new file mode 100644
index 0000000..0b680dd
--- /dev/null
+++ b/completions/gitctl.bash
@@ -0,0 +1,48 @@
+# bash completion for gitctl
+# install: cp completions/gitctl.bash /etc/bash_completion.d/gitctl
+# or: source completions/gitctl.bash (from ~/.bashrc)
+
+_gitctl() {
+ local cur prev words cword
+ _init_completion 2>/dev/null || {
+ # minimal fallback if bash-completion's _init_completion is absent
+ cur=${COMP_WORDS[COMP_CWORD]}
+ prev=${COMP_WORDS[COMP_CWORD-1]}
+ words=("${COMP_WORDS[@]}")
+ cword=$COMP_CWORD
+ }
+
+ local group=${words[1]} action=${words[2]}
+
+ # complete section names from the live server (one ssh call). Only when the
+ # previous word is --section, so we do not pay it on every Tab.
+ if [[ $prev == "--section" ]]; then
+ local secs
+ secs=$(gitctl sections list 2>/dev/null)
+ local IFS=$'\n'
+ COMPREPLY=($(compgen -W "$secs" -- "$cur"))
+ return
+ fi
+
+ case $cword in
+ 1)
+ COMPREPLY=($(compgen -W "sections sync repo" -- "$cur"))
+ return ;;
+ 2)
+ case $group in
+ sections) COMPREPLY=($(compgen -W "list add" -- "$cur")) ;;
+ repo) COMPREPLY=($(compgen -W "create desc add-remote" -- "$cur")) ;;
+ esac
+ return ;;
+ esac
+
+ # flags, by subcommand
+ if [[ $cur == -* ]]; then
+ case "$group $action" in
+ "repo create") COMPREPLY=($(compgen -W "--section --desc --owner" -- "$cur")) ;;
+ "repo add-remote") COMPREPLY=($(compgen -W "--remote-name" -- "$cur")) ;;
+ esac
+ return
+ fi
+}
+complete -F _gitctl gitctl