2006-01-16 04:03:03 +08:00
#
# Completions for the 'set' builtin
#
#
2006-01-16 23:01:10 +08:00
# Various helper functions
2006-01-16 04:03:03 +08:00
#
2005-09-20 21:31:55 +08:00
2021-12-16 00:59:12 +08:00
function __fish_set_is_color -a foreground background -d 'Test if We are specifying a color value for the prompt'
2024-01-22 14:42:45 +08:00
set -l cmd ( commandline -pxc )
2019-05-05 18:53:09 +08:00
set -e cmd [ 1 ]
for i in $cmd
switch $i
2021-12-16 00:59:12 +08:00
case fish_color_search_match fish_color_selection fish_pager_color_selected_background
$background
return
2019-05-05 18:53:09 +08:00
case 'fish_color_*' 'fish_pager_color_*'
2021-12-16 00:59:12 +08:00
$foreground
return
2005-09-20 21:31:55 +08:00
2019-05-05 18:53:09 +08:00
case '-*'
2010-09-18 10:18:26 +08:00
2019-05-05 18:53:09 +08:00
case '*'
return 1
end
end
return 1
2005-09-20 21:31:55 +08:00
end
2006-01-16 04:03:03 +08:00
function __fish_set_is_locale -d 'Test if We are specifying a locale value for the prompt'
2024-01-22 14:42:45 +08:00
set -l cmd ( commandline -pxc )
2019-05-05 18:53:09 +08:00
set -e cmd [ 1 ]
for i in $cmd
switch $i
2022-02-08 02:02:46 +08:00
case LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME
2019-05-05 18:53:09 +08:00
return 0
case '-*'
continue
case '*'
return 1
end
end
return 1
2006-01-16 04:03:03 +08:00
end
2021-12-14 08:22:03 +08:00
function __fish_complete_special_vars
printf "%s\t%s\n" \
2021-12-16 00:59:12 +08:00
PATH "list of dirs to look for commands in" \
CDPATH "list of dirs under which that cd searches" \
FISH_DEBUG "list of enabled debug categories" \
FISH_DEBUG_OUTPUT "debug output path" \
umask "current file creation mask" \
fish_handle_reflow "if fish should repaint prompt when the term resizes" \
fish_trace "print cmds as they execute, like set -x" \
fish_emoji_width "cols wide fish assumes emoji render as" \
fish_key_bindings "name of function that sets binds" \
fish_autosuggestion_enabled "turns autosuggestions on or off" \
fish_ambiguous_width "affects computed width of east asian chars" \
fish_escape_delay_ms "How long fish waits to distinguish escape and alt" \
fish_greeting "The message to display at start (also a function)" \
fish_history "The session id to store history under" \
fish_trace "Enables execution tracing (if set to non-empty value)" \
fish_user_paths "A list of dirs to prepend to PATH"
2019-05-21 23:00:32 +08:00
end
2006-01-16 04:03:03 +08:00
#
# Completions
#
2006-01-18 03:34:50 +08:00
# Regular switches, set only accepts these before the variable name,
2022-02-09 16:46:07 +08:00
# so we need to test using "__fish_is_nth_token 1"
2021-06-30 08:26:49 +08:00
2022-02-09 16:46:07 +08:00
complete -c set -n "__fish_is_nth_token 1" -s e -l erase -d "Erase variable"
complete -c set -n "__fish_is_nth_token 1" -s x -l export -d "Export variable to subprocess"
complete -c set -n "__fish_is_nth_token 1" -s u -l unexport -d "Do not export variable to subprocess"
complete -c set -n "__fish_is_nth_token 1" -s f -l function -d "Make variable function-scoped"
complete -c set -n "__fish_is_nth_token 1" -s g -l global -d "Make variable scope global"
complete -c set -n "__fish_is_nth_token 1" -s l -l local -d "Make variable scope local"
complete -c set -n "__fish_is_nth_token 1" -s L -l long -d 'Do not truncate long lines'
complete -c set -n "__fish_is_nth_token 1" -s U -l universal -d "Share variable persistently across sessions"
complete -c set -n "__fish_is_nth_token 1" -s q -l query -d "Test if variable is defined"
complete -c set -n "__fish_is_nth_token 1" -s h -l help -d "Display help and exit"
complete -c set -n "__fish_is_nth_token 1" -s n -l names -d "List the names of the variables, but not their value"
complete -c set -n "__fish_is_nth_token 1" -s a -l append -d "Append value to a list"
complete -c set -n "__fish_is_nth_token 1" -s p -l prepend -d "Prepend value to a list"
complete -c set -n "__fish_is_nth_token 1" -s S -l show -d "Show variable"
complete -c set -n "__fish_is_nth_token 1" -l path -d "Make variable as a path variable"
complete -c set -n "__fish_is_nth_token 1" -l unpath -d "Make variable not as a path variable"
2006-08-31 23:44:00 +08:00
2018-04-04 03:40:51 +08:00
#TODO: add CPP code to generate list of read-only variables and exclude them from the following completions
2006-01-18 03:34:50 +08:00
# Complete using preexisting variable names
2022-02-09 16:46:07 +08:00
complete -c set -n '__fish_is_nth_token 1; and not __fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s g -s U -l local -l global -l universal' -x -a "(set -l | string match -rv '^__' | string replace ' ' \t'Local Variable: ')"
complete -c set -n '__fish_is_nth_token 1; and not __fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s g -s U -l local -l global -l universal' -x -a "(set -g | string match -rv '^__' | string replace ' ' \t'Global Variable: ')"
complete -c set -n '__fish_is_nth_token 1; and not __fish_seen_argument -s e -l erase; and not __fish_seen_argument -s l -s g -s U -l local -l global -l universal' -x -a "(set -U | string match -rv '^__' | string replace ' ' \t'Universal Variable: ')"
2019-05-21 23:00:32 +08:00
# Complete some fish configuration variables even if they aren't set.
2022-02-09 16:46:07 +08:00
complete -c set -n '__fish_is_nth_token 1; and not __fish_seen_argument -s e -l erase' -x -a "(__fish_complete_special_vars)"
2018-04-04 03:40:51 +08:00
# Complete scope-specific variables
2022-02-09 16:46:07 +08:00
complete -c set -n '__fish_is_nth_token 1; and __fish_seen_argument -s l -l local' -x -a "(set -l | string replace ' ' \t'Local Variable: ')"
complete -c set -n '__fish_is_nth_token 1; and __fish_seen_argument -s g -l global' -x -a "(set -g | string replace ' ' \t'Global Variable: ')"
complete -c set -n '__fish_is_nth_token 1; and __fish_seen_argument -s U -l universal' -x -a "(set -U | string replace ' ' \t'Universal Variable: ')"
2018-04-04 03:40:51 +08:00
# Complete using preexisting variable names for `set --erase`
2020-06-20 15:51:29 +08:00
complete -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:\ )"
complete -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:\ )"
complete -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:\ )"
2018-04-04 03:40:51 +08:00
# Complete scope-specific variables for `set --erase`
2020-06-20 15:51:29 +08:00
complete -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: ')"
complete -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: ')"
complete -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: ')"
2006-01-16 04:03:03 +08:00
# Color completions
2021-12-16 00:59:12 +08:00
complete -c set -n '__fish_set_is_color true false' -x -a '(set_color --print-colors)' -d 'text color'
complete -c set -n '__fish_set_is_color false true' -a '--background=(set_color --print-colors)'
complete -c set -n '__fish_set_is_color true false' -a --bold -x
complete -c set -n '__fish_set_is_color true false' -a --dim -x
complete -c set -n '__fish_set_is_color true false' -a --italics -x
complete -c set -n '__fish_set_is_color true true' -a --reverse -x
complete -c set -n '__fish_set_is_color true false' -a --underline -x
2006-01-16 04:03:03 +08:00
# Locale completions
2020-03-10 02:36:12 +08:00
complete -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