mirror of https://github.com/bitcoin/bitcoin
Completions are dynamically generated from the respective binary help pages. Completions should be sourced into the shell or added to $XDG_CONFIG/fish/completions.pull/24611/head
parent
a27a445b71
commit
7075848f96
@ -0,0 +1,99 @@
|
||||
# Disable files from being included in completions by default
|
||||
complete --command bitcoin-cli --no-files
|
||||
|
||||
function __fish_bitcoin_cli_get_commands_helper
|
||||
set --local cmd (commandline -oc)
|
||||
|
||||
# Don't return commands if '-help or -?' in commandline
|
||||
if string match --quiet --regex -- '^-help$|^-\?$' $cmd
|
||||
return
|
||||
end
|
||||
|
||||
# Strip help cmd from token to avoid duplication errors
|
||||
set --local cmd (string match --invert --regex -- '^help$' $cmd)
|
||||
# Strip -stdin* options to avoid waiting for input while we fetch completions
|
||||
# TODO: this appears to be broken when run as tab completion (requires ctrl+c to exit)
|
||||
set --local cmd (string match --invert --regex -- '^-stdin.*$' $cmd)
|
||||
|
||||
# Match, format and return commands
|
||||
for command in ($cmd help 2>&1 | string match --invert -r '^\=\=.*' | string match --invert -r '^\\s*$')
|
||||
echo $command
|
||||
end
|
||||
end
|
||||
|
||||
function __fish_bitcoin_cli_get_commands
|
||||
argparse 'nohelp' 'commandsonly' -- $argv
|
||||
set --local commands
|
||||
|
||||
# Exclude description, exclude help
|
||||
if set -q _flag_nohelp; and set -q _flag_commandsonly
|
||||
set --append commands (__fish_bitcoin_cli_get_commands_helper | string replace -r ' .*$' '' | string match --invert -r 'help')
|
||||
# Include description, exclude help
|
||||
else if set -q _flag_nohelp
|
||||
set --append commands (__fish_bitcoin_cli_get_commands_helper | string replace ' ' \t | string match --invert -r 'help')
|
||||
# Exclude description, include help
|
||||
else if set -q _flag_commandsonly
|
||||
set --append commands (__fish_bitcoin_cli_get_commands_helper | string replace -r ' .*$' '')
|
||||
# Include description, include help
|
||||
else
|
||||
set --append commands (__fish_bitcoin_cli_get_commands_helper | string replace ' ' \t)
|
||||
end
|
||||
|
||||
if string match -q -r '^.*error.*$' $commands[1]
|
||||
# RPC offline or RPC wallet not loaded
|
||||
return
|
||||
else
|
||||
for command in $commands
|
||||
echo $command
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function __fish_bitcoin_cli_get_options
|
||||
argparse 'nofiles' -- $argv
|
||||
set --local cmd (commandline -oc)
|
||||
# Don't return options if '-help or -?' in commandline
|
||||
if string match --quiet --regex -- '^-help$|-\?$' $cmd
|
||||
return
|
||||
end
|
||||
set --local options
|
||||
|
||||
if set -q _flag_nofiles
|
||||
set --append options ($cmd -help 2>&1 | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=' | string match --invert -r '^.*=$')
|
||||
else
|
||||
set --append options ($cmd -help 2>&1 | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=' | string match -r '^.*=$')
|
||||
end
|
||||
|
||||
for option in $options
|
||||
echo $option
|
||||
end
|
||||
end
|
||||
|
||||
# Add options with file completion
|
||||
# Don't offer after a command is given
|
||||
complete \
|
||||
--command bitcoin-cli \
|
||||
--no-files \
|
||||
--condition "not __fish_seen_subcommand_from (__fish_bitcoin_cli_get_commands --commandsonly)" \
|
||||
--arguments "(__fish_bitcoin_cli_get_options)"
|
||||
# Enable file completions only if the commandline now contains a `*.=` style option
|
||||
complete --command bitcoin-cli \
|
||||
--condition 'string match --regex -- ".*=" (commandline -pt)' \
|
||||
--force-files
|
||||
|
||||
# Add options without file completion
|
||||
# Don't offer after a command is given
|
||||
complete \
|
||||
--command bitcoin-cli \
|
||||
--no-files \
|
||||
--condition "not __fish_seen_subcommand_from (__fish_bitcoin_cli_get_commands --commandsonly)" \
|
||||
--arguments "(__fish_bitcoin_cli_get_options --nofiles)"
|
||||
|
||||
# Add commands
|
||||
# Permit command completions after `bitcoin-cli help` but not after other commands
|
||||
complete \
|
||||
--command bitcoin-cli \
|
||||
--no-files \
|
||||
--condition "not __fish_seen_subcommand_from (__fish_bitcoin_cli_get_commands --commandsonly --nohelp)" \
|
||||
--arguments "(__fish_bitcoin_cli_get_commands)"
|
@ -0,0 +1,35 @@
|
||||
# Disable files from being included in completions by default
|
||||
complete --command bitcoin-qt --no-files
|
||||
|
||||
# Extract options
|
||||
function __fish_bitcoinqt_get_options
|
||||
argparse 'nofiles' -- $argv
|
||||
set --local cmd (commandline -opc)[1]
|
||||
set --local options
|
||||
|
||||
if set -q _flag_nofiles
|
||||
set --append options ($cmd -help-debug | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=' | string match --invert -r '^.*=$')
|
||||
else
|
||||
set --append options ($cmd -help-debug | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=' | string match -r '^.*=$')
|
||||
end
|
||||
|
||||
for option in $options
|
||||
echo $option
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Add options with file completion
|
||||
complete \
|
||||
--command bitcoin-qt \
|
||||
--arguments "(__fish_bitcoinqt_get_options)"
|
||||
# Enable file completions only if the commandline now contains a `*.=` style option
|
||||
complete -c bitcoin-qt \
|
||||
--condition 'string match --regex -- ".*=" (commandline -pt)' \
|
||||
--force-files
|
||||
|
||||
# Add options without file completion
|
||||
complete \
|
||||
--command bitcoin-qt \
|
||||
--arguments "(__fish_bitcoinqt_get_options --nofiles)"
|
||||
|
@ -0,0 +1,65 @@
|
||||
# Disable files from being included in completions by default
|
||||
complete --command bitcoin-tx --no-files
|
||||
|
||||
# Modified version of __fish_seen_subcommand_from
|
||||
# Uses regex to detect cmd= syntax
|
||||
function __fish_bitcoin_seen_cmd
|
||||
set -l cmd (commandline -oc)
|
||||
set -e cmd[1]
|
||||
for i in $cmd
|
||||
for j in $argv
|
||||
if string match --quiet --regex -- "^$j.*" $i
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
# Extract options
|
||||
function __fish_bitcoin_tx_get_options
|
||||
set --local cmd (commandline -oc)[1]
|
||||
if string match --quiet --regex -- '^-help$|-\?$' $cmd
|
||||
return
|
||||
end
|
||||
|
||||
for option in ($cmd -help 2>&1 | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=')
|
||||
echo $option
|
||||
end
|
||||
end
|
||||
|
||||
# Extract commands
|
||||
function __fish_bitcoin_tx_get_commands
|
||||
argparse 'commandsonly' -- $argv
|
||||
set --local cmd (commandline -oc)[1]
|
||||
set --local commands
|
||||
|
||||
if set -q _flag_commandsonly
|
||||
set --append commands ($cmd -help | sed -e '1,/Commands:/d' -e 's/=/=\t/' -e 's/(=/=/' -e '/^ [a-z]/ p' -e d | string replace -r '\ \ ' '' | string replace -r '=.*' '')
|
||||
else
|
||||
set --append commands ($cmd -help | sed -e '1,/Commands:/d' -e 's/=/=\t/' -e 's/(=/=/' -e '/^ [a-z]/ p' -e d | string replace -r '\ \ ' '')
|
||||
end
|
||||
|
||||
for command in $commands
|
||||
echo $command
|
||||
end
|
||||
end
|
||||
|
||||
# Add options
|
||||
complete \
|
||||
--command bitcoin-tx \
|
||||
--condition "not __fish_bitcoin_seen_cmd (__fish_bitcoin_tx_get_commands --commandsonly)" \
|
||||
--arguments "(__fish_bitcoin_tx_get_options)" \
|
||||
--no-files
|
||||
|
||||
# Add commands
|
||||
complete \
|
||||
--command bitcoin-tx \
|
||||
--arguments "(__fish_bitcoin_tx_get_commands)" \
|
||||
--no-files
|
||||
|
||||
# Add file completions for load and set commands
|
||||
complete \
|
||||
--command bitcoin-tx \
|
||||
--condition 'string match --regex -- "(load|set)=" (commandline -pt)' \
|
||||
--force-files
|
@ -0,0 +1,38 @@
|
||||
# Disable files from being included in completions by default
|
||||
complete --command bitcoin-util --no-files
|
||||
|
||||
# Extract options
|
||||
function __fish_bitcoin_util_get_options
|
||||
set --local cmd (commandline -opc)[1]
|
||||
set --local options
|
||||
|
||||
set --append options ($cmd -help 2>&1 | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=')
|
||||
|
||||
for option in $options
|
||||
echo $option
|
||||
end
|
||||
end
|
||||
|
||||
# Extract commands
|
||||
function __fish_bitcoin_util_get_commands
|
||||
set --local cmd (commandline -opc)[1]
|
||||
set --local commands
|
||||
|
||||
set --append commands ($cmd -help | sed -e '1,/Commands:/d' -e 's/=/=\t/' -e 's/(=/=/' -e '/^ [a-z]/ p' -e d | string replace -r '\ \ ' '')
|
||||
for command in $commands
|
||||
echo $command
|
||||
end
|
||||
end
|
||||
|
||||
# Add options
|
||||
complete \
|
||||
--command bitcoin-util \
|
||||
--condition "not __fish_seen_subcommand_from (__fish_bitcoin_util_get_commands)" \
|
||||
--arguments "(__fish_bitcoin_util_get_options)"
|
||||
|
||||
# Add commands
|
||||
complete \
|
||||
--command bitcoin-util \
|
||||
--condition "not __fish_seen_subcommand_from (__fish_bitcoin_util_get_commands)" \
|
||||
--arguments "(__fish_bitcoin_util_get_commands)"
|
||||
|
@ -0,0 +1,35 @@
|
||||
# Disable files from being included in completions by default
|
||||
complete --command bitcoin-wallet --no-files
|
||||
|
||||
# Extract options
|
||||
function __fish_bitcoin_wallet_get_options
|
||||
set --local cmd (commandline -opc)[1]
|
||||
for option in ($cmd -help 2>&1 | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=')
|
||||
echo $option
|
||||
end
|
||||
end
|
||||
|
||||
# Extract commands
|
||||
function __fish_bitcoin_wallet_get_commands
|
||||
set --local cmd (commandline -opc)[1]
|
||||
for command in ($cmd -help | sed -e '1,/Commands:/d' -e 's/=/=\t/' -e 's/(=/=/' -e '/^ [a-z]/ p' -e d | string replace -r '\ \ ' '')
|
||||
echo $command
|
||||
end
|
||||
end
|
||||
|
||||
# Add options
|
||||
complete \
|
||||
--command bitcoin-wallet \
|
||||
--condition "not __fish_seen_subcommand_from (__fish_bitcoin_wallet_get_commands)" \
|
||||
--arguments "(__fish_bitcoin_wallet_get_options)"
|
||||
|
||||
# Add commands
|
||||
complete \
|
||||
--command bitcoin-wallet \
|
||||
--condition "not __fish_seen_subcommand_from (__fish_bitcoin_wallet_get_commands)" \
|
||||
--arguments "(__fish_bitcoin_wallet_get_commands)"
|
||||
|
||||
# Add file completions for load and set commands
|
||||
complete --command bitcoin-wallet \
|
||||
--condition "string match -r -- '(dumpfile|datadir)*=' (commandline -pt)" \
|
||||
--force-files
|
@ -0,0 +1,35 @@
|
||||
# Disable files from being included in completions by default
|
||||
complete --command bitcoind --no-files
|
||||
|
||||
# Extract options
|
||||
function __fish_bitcoind_get_options
|
||||
argparse 'nofiles' -- $argv
|
||||
set --local cmd (commandline -opc)[1]
|
||||
set --local options
|
||||
|
||||
if set -q _flag_nofiles
|
||||
set --append options ($cmd -help-debug | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=' | string match --invert -r '^.*=$')
|
||||
else
|
||||
set --append options ($cmd -help-debug | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=' | string match -r '^.*=$')
|
||||
end
|
||||
|
||||
for option in $options
|
||||
echo $option
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Add options with file completion
|
||||
complete \
|
||||
--command bitcoind \
|
||||
--arguments "(__fish_bitcoind_get_options)"
|
||||
# Enable file completions only if the commandline now contains a `*.=` style option
|
||||
complete --command bitcoind \
|
||||
--condition 'string match --regex -- ".*=" (commandline -pt)' \
|
||||
--force-files
|
||||
|
||||
# Add options without file completion
|
||||
complete \
|
||||
--command bitcoind \
|
||||
--arguments "(__fish_bitcoind_get_options --nofiles)"
|
||||
|
Loading…
Reference in new issue