# # Keyringer bash completion # _keyringer() { # Standard stuff local cur prev opts config COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" prev="${COMP_WORDS[COMP_CWORD-1]}" # Initial options config="$HOME/.keyringer" opts="`ls $config | sed -e 's/config//'`" # Available instances instances="`echo $opts | sed -e 's/ /|/'`" # The current instance instance="${COMP_WORDS[1]}" # Command completions if [ "${#COMP_WORDS[@]}" == "3" ] && echo "${prev}" | grep -qe "[$instances]"; then opts="`keyringer $instance commands`" elif [ "${#COMP_WORDS[@]}" == "4" ]; then # Process config source $config/config case "${prev}" in options|preferences) opts="ls edit add" ;; recipients) opts="ls edit" ;; ls) # TODO opts="`keyringer $instance ls ${cur}`" ;; *) ;; esac fi # Return the available options COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 } complete -F _keyringer keyringer