fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerMerge branch 'completions-to-use-expanded-tokens'a9618477e

master
2.6 KiB84 linesraw
1function __fish_eselect_cmd
2    eselect --brief --colour=no $argv
3end
4
5function __fish_complete_eselect_modules
6    set -l sedregexp 's/^  ([a-zA-Z0-9_-]*)[ ]*/\1\t/g'
7    __fish_eselect_cmd modules list | string match -r '^  ' | sed -r $sedregexp
8end
9
10function __fish_complete_eselect_actions
11    set -l sedregexp 's/^  ([a-zA-Z0-9_-]*)[ ]*/\1\t/g'
12    set -l cmdl (commandline -pxc)
13    __fish_eselect_cmd $cmdl[2..-1] usage | string match -r '^  [^ -]' | sed -r $sedregexp
14end
15
16function __fish_complete_eselect_action_options
17    set -l parseregexp 's/^    ([a-zA-Z0-9_-]*)[ ]*/\1\t/g'
18    set -l cmdl (commandline -pxc)
19
20    # Alter further php completion
21    if test (__fish_print_cmd_args_without_options)[2] = php
22        eselect php list-modules 2>/dev/null | string split " "
23        return
24    end
25
26    switch $cmdl[-1]
27        case -'*'
28            return
29    end
30
31    set -l findregexp '/^  '$cmdl[-1]'/,/^  [^ ]/p'
32
33    set cmdl[-1] usage
34    __fish_eselect_cmd $cmdl[2..-1] | sed -n -re $findregexp | string match -r '^    --' | sed -re $parseregexp
35end
36
37function __fish_complete_eselect_php_actions
38    set -l sedregexp 's/^\s*\[([0-9]+)\]\s+([A-Za-z0-9\.]+).*/\1\t\2/'
39
40    if test (__fish_print_cmd_args_without_options)[3] = set
41        eselect php list (__fish_print_cmd_args_without_options)[-1] 2>/dev/null | sed -r $sedregexp
42    end
43end
44
45function __fish_complete_eselect_targets
46    set -l sedregexp 's/^  \[([0-9]+)\][ ]*/\1\t/g'
47    set -l cmdl (commandline -pxc)
48
49    # Disable further php completion
50    if test (__fish_print_cmd_args_without_options)[2] = php
51        return
52    end
53
54    switch $cmdl[-1]
55        case -'*'
56            set cmdl[-2] list
57        case '*'
58            set cmdl[-1] list
59    end
60
61    eselect --colour=no $cmdl[2..-1] | string match -r '^  [^ -]' | sed -r $sedregexp
62end
63
64complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
65    -xa '(__fish_complete_eselect_modules)'
66
67complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
68    -l brief -d 'Make output shorter'
69
70complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 1" \
71    -l colour \
72    -d "=<yes|no|auto> Enable or disable colour output (default 'auto')"
73
74complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 2" \
75    -xa '(__fish_complete_eselect_actions)'
76
77complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 3" \
78    -xa '(__fish_complete_eselect_targets)'
79
80complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 3" \
81    -xa '(__fish_complete_eselect_action_options)'
82
83complete -c eselect -n "test (__fish_number_of_cmd_args_wo_opts) = 4" \
84    -xa '(__fish_complete_eselect_php_actions)'