Last active
May 7, 2024 18:08
-
-
Save urza/c46259099eda5223baa7e84737e53bd7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bash programmable completion for core lightning | |
# 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. | |
# modified by Tomas Stary (2018) for lightning-cli | |
# modified by urza (2024) for cln alias ("lightning-cli" must be in path and "cln" is alias for that) | |
_cln_cli() { | |
local cur prev words=() cword | |
local lightning_cli | |
# lightning_cli might not be in $PATH | |
lightning_cli="lightning-cli" | |
COMPREPLY=() | |
_get_comp_words_by_ref -n = cur prev words cword | |
case "$cur" in | |
-*=*) # prevent nonsense completions | |
return 0 | |
;; | |
*) | |
local helpopts globalcmds | |
# get the global options, starting with -- | |
if [[ -z "$cur" || "$cur" =~ ^- ]]; then | |
globalcmds=$($lightning_cli --help 2>&1 | tr '|' '\n' | sed -n -e 's/ .*//' -e 's/\(-[-a-z0-9A-Z]*\).*/\1/p') | |
fi | |
# get the regular commands | |
if [[ -z "$cur" || "$cur" =~ ^[a-z] ]]; then | |
helpopts=$($lightning_cli help 2>/dev/null | sed -n 's/^\([a-z][a-z_-]*\).*/\1/p' | sed '$ d') | |
fi | |
COMPREPLY=( $( compgen -W "$helpopts $globalcmds" -X "*," -- "$cur" ) ) | |
esac | |
} && | |
complete -F _cln_cli cln | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment