Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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