From 1bc011ae5a6359d725135bbeb1e0b7e22f52fb50 Mon Sep 17 00:00:00 2001 From: "Andreas M. Antonopoulos" Date: Mon, 30 Jan 2017 09:12:53 +0700 Subject: [PATCH] contrib: add basic bash completion for lncli --- contrib/lncli.bash-completion | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 contrib/lncli.bash-completion diff --git a/contrib/lncli.bash-completion b/contrib/lncli.bash-completion new file mode 100644 index 000000000..cd67786f3 --- /dev/null +++ b/contrib/lncli.bash-completion @@ -0,0 +1,53 @@ +# bash programmable completion for lncli +# copy to /etc/bash_completion.d and restart your shell session +# Copyright (c) by Andreas M. Antonopoulos +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +_lncli() { + local cur prev words=() cword + local lncli + + # lncli might not be in $PATH + lncli="$1" + + COMPREPLY=() + _get_comp_words_by_ref -n = cur prev words cword + + case "$prev" in + # example of further completion + newaddress) + COMPREPLY=( $( compgen -W "p2wkh np2wkh p2pkh" -- "$cur" ) ) + return 0 + ;; + esac + + case "$cur" in + -*=*) # prevent nonsense completions + return 0 + ;; + *) + local helpopts globalcmds + + # get the global options, starting with -- + if [[ -z "$cur" || "$cur" =~ ^- ]]; then + globalcmds=$($lncli help 2>&1 | awk '$1 ~ /^-/ { sub(/,/, ""); print $1}') + fi + + # get the regular commands + if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then + helpopts=$($lncli help 2>/dev/null | awk '$1 ~ /^[a-z]/ { print $1; }' ) + fi + + COMPREPLY=( $( compgen -W "$helpopts $globalcmds" -X "*," -- "$cur" ) ) + esac +} && +complete -F _lncli lncli + +# Local variables: +# mode: shell-script +# sh-basic-offset: 4 +# sh-indent-comment: t +# indent-tabs-mode: nil +# End: +# ex: ts=4 sw=4 et filetype=sh