diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2013-07-11 17:32:29 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2013-07-11 17:32:29 -0300 |
commit | e6e48ab8138d8d91943fda4485203a0ebaf25eef (patch) | |
tree | 0b3a6c25f8788f1013d1a372726303cf386ba2d4 /lib | |
parent | 3fc6dc9f42e5387039c1eb6ff62767c4509c30e9 (diff) | |
download | keyringer-e6e48ab8138d8d91943fda4485203a0ebaf25eef.tar.gz keyringer-e6e48ab8138d8d91943fda4485203a0ebaf25eef.tar.bz2 |
Initial bash completion code (#2)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/keyringer/completions/bash | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/keyringer/completions/bash b/lib/keyringer/completions/bash new file mode 100644 index 0000000..6de93bb --- /dev/null +++ b/lib/keyringer/completions/bash @@ -0,0 +1,38 @@ +# +# Keyringer bash completion +# + +_keyringer() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + # Initial options + opts="`ls $HOME/.keyringer | sed -e 's/config//'`" + + # Available keyrings + keyrings="`echo $opts | sed -e 's/ /|/'`" + + # The current keyring + keyring="${COMP_WORDS[1]}" + + # Command completions + if [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$keyrings]"; then + opts="`keyringer $keyring commands`" + else + case "${prev}" in + ls) + opts="`keyringer $keyring ls ${cur}`" + ;; + *) + ;; + esac + fi + + # Return the available options + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 +} + +complete -F _keyringer keyringer |