aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/completions/eselect.fish
blob: 0b891230a18205f8cd3c10811c8caf61cef935ea (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function __fish_eselect_cmd
    eselect --brief --colour=no $argv
end

function __fish_complete_eselect_modules
    set -l sedregexp 's/^  ([a-zA-Z0-9_-]*)[ ]*/\1\t/g'
    __fish_eselect_cmd modules list | __fish_sgrep '^  ' | sed -r $sedregexp
end

function __fish_complete_eselect_actions
    set -l sedregexp 's/^  ([a-zA-Z0-9_-]*)[ ]*/\1\t/g'
    set -l cmdl (commandline -poc)
    __fish_eselect_cmd $cmdl[2..-1] usage | __fish_sgrep '^  [^ -]' | sed -r $sedregexp
end

function __fish_complete_eselect_action_options
    set -l parseregexp 's/^    ([a-zA-Z0-9_-]*)[ ]*/\1\t/g'
    set -l cmdl (commandline -poc)

    # Alter further php completion
    if [ (__fish_print_cmd_args_without_options)[2] = 'php' ]
        eselect php list-modules ^/dev/null | string split " "
        return
    end

    switch $cmdl[-1]
        case -'*'
            return
    end

    set -l findregexp '/^  '$cmdl[-1]'/,/^  [^ ]/p'

    set cmdl[-1] usage
    __fish_eselect_cmd $cmdl[2..-1] | sed -n -re $findregexp | __fish_sgrep '^    --' | sed -re $parseregexp
end

function __fish_complete_eselect_php_actions
    set -l sedregexp 's/^\s*\[([0-9]+)\]\s+([A-Za-z0-9\.]+).*/\1\t\2/'

    if test (__fish_print_cmd_args_without_options)[3] = 'set'
        eselect php list (__fish_print_cmd_args_without_options)[-1] ^/dev/null | sed -r $sedregexp
    end
end

function __fish_complete_eselect_targets
    set -l sedregexp 's/^  \[([0-9]+)\][ ]*/\1\t/g'
    set -l cmdl (commandline -poc)

    # Disable further php completion
    if [ (__fish_print_cmd_args_without_options)[2] = 'php' ]
        return
    end

    switch $cmdl[-1]
        case -'*'
            set cmdl[-2] list
        case '*'
            set cmdl[-1] list
    end

    eselect --colour=no $cmdl[2..-1] | __fish_sgrep '^  [^ -]' | sed -r $sedregexp
end

complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
    -xa '(__fish_complete_eselect_modules)'

complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
    -l brief -d 'Make output shorter'

complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
    -l colour \
    -d "=<yes|no|auto> Enable or disable colour output (default 'auto')"

complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 2" \
    -xa '(__fish_complete_eselect_actions)'

complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 3" \
    -xa '(__fish_complete_eselect_targets)'

complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 3" \
    -xa '(__fish_complete_eselect_action_options)'

complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 4" \
    -xa '(__fish_complete_eselect_php_actions)'