bitcoin-tx.fish raw
1 # Disable files from being included in completions by default
2 complete --command bitcoin-tx --no-files
3
4 # Modified version of __fish_seen_subcommand_from
5 # Uses regex to detect cmd= syntax
6 function __fish_bitcoin_seen_cmd
7 set -l cmd (commandline -oc)
8 set -e cmd[1]
9 for i in $cmd
10 for j in $argv
11 if string match --quiet --regex -- "^$j.*" $i
12 return 0
13 end
14 end
15 end
16 return 1
17 end
18
19 # Extract options
20 function __fish_bitcoin_tx_get_options
21 set --local cmd (commandline -oc)[1]
22 if string match --quiet --regex -- '^-help$|-\?$' $cmd
23 return
24 end
25
26 for option in ($cmd -help 2>&1 | string match -r '^ -.*' | string replace -r ' -' '-' | string replace -r '=.*' '=')
27 echo $option
28 end
29 end
30
31 # Extract commands
32 function __fish_bitcoin_tx_get_commands
33 argparse 'commandsonly' -- $argv
34 set --local cmd (commandline -oc)[1]
35 set --local commands
36
37 if set -q _flag_commandsonly
38 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 '=.*' '')
39 else
40 set --append commands ($cmd -help | sed -e '1,/Commands:/d' -e 's/=/=\t/' -e 's/(=/=/' -e '/^ [a-z]/ p' -e d | string replace -r '\ \ ' '')
41 end
42
43 for command in $commands
44 echo $command
45 end
46 end
47
48 # Add options
49 complete \
50 --command bitcoin-tx \
51 --condition "not __fish_bitcoin_seen_cmd (__fish_bitcoin_tx_get_commands --commandsonly)" \
52 --arguments "(__fish_bitcoin_tx_get_options)" \
53 --no-files
54
55 # Add commands
56 complete \
57 --command bitcoin-tx \
58 --arguments "(__fish_bitcoin_tx_get_commands)" \
59 --no-files
60
61 # Add file completions for load and set commands
62 complete \
63 --command bitcoin-tx \
64 --condition 'string match --regex -- "(load|set)=" (commandline -pt)' \
65 --force-files
66