aboutsummaryrefslogtreecommitdiff
path: root/contrib/completions/fish/bitcoin-util.fish
blob: 0650bf2cb6d3b58a76606f2c87ba47f5972f9cbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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)"