diff options
author | Erik Arvstedt <erik.arvstedt@gmail.com> | 2023-09-19 13:42:51 +0200 |
---|---|---|
committer | Erik Arvstedt <erik.arvstedt@gmail.com> | 2023-09-19 13:45:22 +0200 |
commit | 360b917674e63c1e95119040463b3f50976bf331 (patch) | |
tree | 103148c4b0d687d0e122d0a2445b70a20783c14f /contrib/completions/bash/bitcoind.bash | |
parent | f01416e23c9c820517c37003a2a98dd46d1022ba (diff) |
contrib/bash-completions: use package naming conventions
This naming scheme supports auto-detection and on-demand loading of completions.
See
https://github.com/scop/bash-completion/blob/ba109693ee2284f6a82f8f0e1563baf071252df9/README.md#faq,
section "Where should I put it to be sure that interactive bash shells will find it and source it".
Previously, distro package maintainers had to rename these files manually.
Diffstat (limited to 'contrib/completions/bash/bitcoind.bash')
-rw-r--r-- | contrib/completions/bash/bitcoind.bash | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/contrib/completions/bash/bitcoind.bash b/contrib/completions/bash/bitcoind.bash new file mode 100644 index 0000000000..c11d99ef31 --- /dev/null +++ b/contrib/completions/bash/bitcoind.bash @@ -0,0 +1,56 @@ +# bash programmable completion for bitcoind(1) and bitcoin-qt(1) +# Copyright (c) 2012-2022 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +_bitcoind() { + local cur prev words=() cword + local bitcoind + + # save and use original argument to invoke bitcoind for -help + # it might not be in $PATH + bitcoind="$1" + + COMPREPLY=() + _get_comp_words_by_ref -n = cur prev words cword + + case "$cur" in + -conf=*|-pid=*|-loadblock=*|-rpccookiefile=*|-wallet=*) + cur="${cur#*=}" + _filedir + return 0 + ;; + -datadir=*) + cur="${cur#*=}" + _filedir -d + return 0 + ;; + -*=*) # prevent nonsense completions + return 0 + ;; + *) + + # only parse -help if sensible + if [[ -z "$cur" || "$cur" =~ ^- ]]; then + local helpopts + helpopts=$($bitcoind -help 2>&1 | awk '$1 ~ /^-/ { sub(/=.*/, "="); print $1 }' ) + COMPREPLY=( $( compgen -W "$helpopts" -- "$cur" ) ) + fi + + # Prevent space if an argument is desired + if [[ $COMPREPLY == *= ]]; then + compopt -o nospace + fi + return 0 + ;; + esac +} && +complete -F _bitcoind bitcoind bitcoin-qt + +# 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 |