github.com/decred/dcrlnd@v0.7.6/contrib/dcrlncli.bash-completion (about) 1 # bash programmable completion for dcrlncli 2 # copy to /etc/bash_completion.d and restart your shell session 3 # Copyright (c) by Andreas M. Antonopoulos 4 # Distributed under the MIT software license, see the accompanying 5 # file COPYING or http://www.opensource.org/licenses/mit-license.php. 6 7 _dcrlncli() { 8 local cur prev words=() cword 9 local dcrlncli 10 11 # dcrlncli might not be in $PATH 12 dcrlncli="$1" 13 14 COMPREPLY=() 15 _get_comp_words_by_ref -n = cur prev words cword 16 17 case "$prev" in 18 # example of further completion 19 newaddress) 20 COMPREPLY=( $( compgen -W "p2pkh" -- "$cur" ) ) 21 return 0 22 ;; 23 esac 24 25 case "$cur" in 26 -*=*) # prevent nonsense completions 27 return 0 28 ;; 29 *) 30 local helpopts globalcmds 31 32 # get the global options, starting with -- 33 if [[ -z "$cur" || "$cur" =~ ^- ]]; then 34 globalcmds=$($dcrlncli help 2>&1 | awk '$1 ~ /^-/ { sub(/,/, ""); print $1}') 35 fi 36 37 # get the regular commands 38 if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then 39 helpopts=$($dcrlncli help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }' ) 40 fi 41 42 COMPREPLY=( $( compgen -W "$helpopts $globalcmds" -X "*," -- "$cur" ) ) 43 esac 44 } && 45 complete -F _dcrlncli dcrlncli 46 47 # Local variables: 48 # mode: shell-script 49 # sh-basic-offset: 4 50 # sh-indent-comment: t 51 # indent-tabs-mode: nil 52 # End: 53 # ex: ts=4 sw=4 et filetype=sh