fork/fish-shell

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

gitmprhighlight: add fish_color_builtin and fish_color_function43e3aa4e6

master
8.0 KiB150 linesraw
1#
2# Completions for the 'set' builtin
3#
4
5#
6# Various helper functions
7#
8
9function __fish_set_is_color -a foreground background -d 'Test if We are specifying a color value for the prompt'
10    set -l cmd (commandline -pxc)
11    set -e cmd[1]
12    for i in $cmd
13        switch $i
14            case fish_color_search_match fish_color_selection fish_pager_color_selected_background
15                $background
16                return
17            case 'fish_color_*' 'fish_pager_color_*'
18                $foreground
19                return
20
21            case '-*'
22
23            case '*'
24                return 1
25        end
26    end
27    return 1
28end
29
30function __fish_set_is_locale -d 'Test if We are specifying a locale value for the prompt'
31    set -l cmd (commandline -pxc)
32    set -e cmd[1]
33    set -l locale_vars (__fish_locale_vars)
34    for i in $cmd
35        switch $i
36
37            case $locale_vars
38                return 0
39
40            case '-*'
41                continue
42
43            case '*'
44                return 1
45        end
46    end
47    return 1
48end
49
50function __fish_complete_special_vars_ifndef -a varname description
51    if not set -q $varname
52        printf "%s\t%s\n" $varname "Undefined Variable; $description"
53    end
54end
55
56function __fish_complete_special_vars
57    printf "%s\t%s\n" \
58        PATH "list of dirs to look for commands in" \
59        CDPATH "list of dirs under which that cd searches" \
60        FISH_DEBUG "list of enabled debug categories" \
61        FISH_DEBUG_OUTPUT "debug output path" \
62        umask "current file creation mask" \
63        fish_ambiguous_width "affects computed width of east asian chars" \
64        fish_autosuggestion_enabled "set to 0 to turn autosuggestions off" \
65        fish_cursor_end_mode "set to 'inclusive' to disallow moving the cursor beyond the command line end" \
66        fish_cursor_selection_mode "set to 'inclusive' if selections should include the cursor" \
67        fish_emoji_width "cols wide fish assumes emoji render as" \
68        fish_escape_delay_ms "How long fish waits to distinguish escape and alt" \
69        fish_greeting "The message to display at start (also a function)" \
70        fish_handle_reflow "if fish should repaint prompt when the term resizes" \
71        fish_history "The session id to store history under" \
72        fish_key_bindings "name of function that sets binds" \
73        fish_term24bit "set to 0 to use the color palette instead of true-colors" \
74        fish_term256 "set to 0 to use the 16-color palette instead of 256" \
75        fish_trace "Enables execution tracing (if set to non-empty value)" \
76        fish_transient_prompt "set to 1 to re-run prompts before pushing them to scrollback" \
77        fish_user_paths "A list of dirs to prepend to PATH"
78    __fish_complete_special_vars_ifndef fish_color_option 'defaults to $fish_color_param'
79    __fish_complete_special_vars_ifndef fish_color_keyword 'defaults to $fish_color_command'
80    __fish_complete_special_vars_ifndef fish_color_builtin 'defaults to $fish_color_command'
81    __fish_complete_special_vars_ifndef fish_color_function 'defaults to $fish_color_command'
82end
83
84#
85# Completions
86#
87
88# Regular switches, set only accepts these before the variable name,
89# so we need to test using "__fish_is_nth_token 1"
90
91complete -c set -n "__fish_is_nth_token 1" -s e -l erase -d "Erase variable"
92complete -c set -n "__fish_is_nth_token 1" -s x -l export -d "Export variable to subprocess"
93complete -c set -n "__fish_is_nth_token 1" -s u -l unexport -d "Do not export variable to subprocess"
94complete -c set -n "__fish_is_nth_token 1" -s f -l function -d "Make variable function-scoped"
95complete -c set -n "__fish_is_nth_token 1" -s g -l global -d "Make variable scope global"
96complete -c set -n "__fish_is_nth_token 1" -s l -l local -d "Make variable scope local"
97complete -c set -n "__fish_is_nth_token 1" -s L -l long -d 'Do not truncate long lines'
98complete -c set -n "__fish_is_nth_token 1" -s U -l universal -d "Share variable persistently across sessions"
99complete -c set -n "__fish_is_nth_token 1" -s q -l query -d "Test if variable is defined"
100complete -c set -n "__fish_is_nth_token 1" -s h -l help -d "Display help and exit"
101complete -c set -n "__fish_is_nth_token 1" -s n -l names -d "List the names of the variables, but not their value"
102complete -c set -n "__fish_is_nth_token 1" -s a -l append -d "Append value to a list"
103complete -c set -n "__fish_is_nth_token 1" -s p -l prepend -d "Prepend value to a list"
104complete -c set -n "__fish_is_nth_token 1" -s S -l show -d "Show variable"
105complete -c set -n "__fish_is_nth_token 1" -l path -d "Make variable as a path variable"
106complete -c set -n "__fish_is_nth_token 1" -l unpath -d "Make variable not as a path variable"
107complete -c set -n "__fish_is_nth_token 1" -l no-event -d "Don't emit an event"
108
109#TODO: add CPP code to generate list of read-only variables and exclude them from the following completions
110
111# Complete using preexisting variable names
112set -l maybe_filter_private_vars '
113    string match (
114        if string match -qr -- "^_" "$(commandline -t)": then
115            echo "*"
116        else
117            echo -rv
118            echo "^__"
119        end
120    )'
121# We do not *filter* these by the given scope because you might want to set e.g. a global to shadow a universal.
122complete -c set -n '__fish_is_nth_token 1; and not __fish_seen_argument -s e -l erase' -x -a "(set -U | $maybe_filter_private_vars | string replace ' ' \t'Universal Variable: ')"
123complete -c set -n '__fish_is_nth_token 1; and not __fish_seen_argument -s e -l erase' -x -a "(set -g | $maybe_filter_private_vars | string replace -r '^((?:history|fish_killring) ).*' '\$1' | string replace ' ' \t'Global Variable: ')"
124complete -c set -n '__fish_is_nth_token 1; and not __fish_seen_argument -s e -l erase' -x -a "(set -l | $maybe_filter_private_vars | string replace ' ' \t'Local Variable: ')"
125# Complete some fish configuration variables even if they aren't set.
126complete -c set -n '__fish_is_nth_token 1; and not __fish_seen_argument -s e -l erase' -x -a "(__fish_complete_special_vars)"
127
128# Complete using preexisting variable names for `set --erase`
129complete -c set -n '__fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s U -s g -l local -l global -l Universal' -f -a "(set -U | string replace ' ' \tUniversal\ Variable:\ )"
130complete -c set -n '__fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s U -s g -l local -l global -l Universal' -f -a "(set -g | string replace ' ' \tGlobal\ Variable:\ )"
131complete -c set -n '__fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s U -s g -l local -l global -l Universal' -f -a "(set -l | string replace ' ' \tLocal\ Variable:\ )"
132# Complete scope-specific variables for `set --erase`
133complete -c set -n '__fish_seen_argument -s e -l erase; and __fish_seen_argument -s U -l universal' -f -a "(set -U | string replace ' ' \t'Universal Variable: ')"
134complete -c set -n '__fish_seen_argument -s e -l erase; and __fish_seen_argument -s g -l global' -f -a "(set -g | string replace ' ' \t'Global Variable: ')"
135complete -c set -n '__fish_seen_argument -s e -l erase; and __fish_seen_argument -s l -l local' -f -a "(set -l | string replace ' ' \t'Local Variable: ')"
136
137# Color completions
138complete -c set -n '__fish_set_is_color true false' -x -a '(set_color --print-colors)' -d 'text color'
139complete -c set -n '__fish_set_is_color false true' -a '--background=(set_color --print-colors)'
140complete -c set -n '__fish_set_is_color false true' -a '--underline-color=(set_color --print-colors)'
141complete -c set -n '__fish_set_is_color true false' -a --bold -x
142complete -c set -n '__fish_set_is_color true false' -a --dim -x
143complete -c set -n '__fish_set_is_color true false' -a --italics -x
144complete -c set -n '__fish_set_is_color true false' -a --strikethrough -x
145complete -c set -n '__fish_set_is_color true true' -a --reverse -x
146complete -c set -n '__fish_set_is_color true false' -a --underline -x
147complete -c set -n '__fish_set_is_color true false' -a--underline={double,curly,dotted,dashed} -x
148
149# Locale completions
150complete -c set -n '__fish_set_is_locale; and not __fish_seen_argument -s e -l erase' -x -a '(command -sq locale; and locale -a)' -d Locale