Skip to content

Instantly share code, notes, and snippets.

@carestad
Created April 23, 2018 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carestad/13927004688748997a16b12f57ac10e4 to your computer and use it in GitHub Desktop.
Save carestad/13927004688748997a16b12f57ac10e4 to your computer and use it in GitHub Desktop.
Bash completion for jotta-cli
#!/bin/bash
function _jottacli() {
local config_params cmds cur first params prev second
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
first=${COMP_WORDS[1]}
second=${COMP_WORDS[2]}
prev=${COMP_WORDS[COMP_CWORD-1]}
cmds="add archive config help ignores login logout rem scan status tailf version web webhook"
params="-help -host --remote --nogui --share"
config_params="logscanignores scaninterval webhookstatusinterval"
case "$first" in
add|archive)
COMPREPLY=($(compgen -W "$(ls -1)" -- $cur))
;;
config|ignores)
case "$second" in
get|set)
if [[ "$first" == "config" ]]; then
COMPREPLY=($(compgen -W "$config_params" -- $cur))
elif [[ "$first" == "ignores" ]] && [[ "$second" == "set" ]]; then
COMPREPLY=($(compgen -W "$(ls -1)" -- $cur))
fi
;;
*)
COMPREPLY=($(compgen -W 'get set' -- $cur))
;;
esac
;;
help|login|logout|status|tailf|version|web) ;;
rem)
COMPREPLY=($(compgen -W "$(ls -1)" -- $cur))
;;
scan)
COMPREPLY=($(compgen -W "$(ls -1)" -- $cur))
;;
webhook)
COMPREPLY=($(compgen -W 'add rem' -- $cur))
;;
*)
COMPREPLY=($(compgen -W "$cmds" -- $cur))
;;
esac
if [[ "$cur" == -* ]]; then
COMPREPLY=($(compgen -W '$params' -- $cur))
fi
}
complete -F _jottacli jotta-cli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment