2006-01-15 20:03:03 +00:00
#
# Completions for the 'set' builtin
#
#
2006-01-16 15:01:10 +00:00
# Various helper functions
2006-01-15 20:03:03 +00:00
#
2005-09-20 13:31:55 +00:00
2021-12-15 16:59:12 +00:00
function __fish_set_is_color -a foreground background -d 'Test if We are specifying a color value for the prompt'
2024-01-22 06:42:45 +00:00
set -l cmd ( commandline -pxc )
2019-05-05 10:53:09 +00:00
set -e cmd [ 1 ]
for i in $cmd
switch $i
2021-12-15 16:59:12 +00:00
case fish_color_search_match fish_color_selection fish_pager_color_selected_background
$background
return
2019-05-05 10:53:09 +00:00
case 'fish_color_*' 'fish_pager_color_*'
2021-12-15 16:59:12 +00:00
$foreground
return
2005-09-20 13:31:55 +00:00
2019-05-05 10:53:09 +00:00
case '-*'
2010-09-18 02:18:26 +00:00
2019-05-05 10:53:09 +00:00
case '*'
return 1
end
end
return 1
2005-09-20 13:31:55 +00:00
end
2006-01-15 20:03:03 +00:00
function __fish_set_is_locale -d 'Test if We are specifying a locale value for the prompt'
2024-01-22 06:42:45 +00:00
set -l cmd ( commandline -pxc )
2019-05-05 10:53:09 +00:00
set -e cmd [ 1 ]
for i in $cmd
switch $i
2022-02-07 18:02:46 +00:00
case LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME
2019-05-05 10:53:09 +00:00
return 0
case '-*'
continue
case '*'
return 1
end
end
return 1
2006-01-15 20:03:03 +00:00
end
2021-12-14 00:22:03 +00:00
function __fish_complete_special_vars
printf "%s\t%s\n" \
2021-12-15 16:59:12 +00: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 15:00:32 +00:00
end
2006-01-15 20:03:03 +00:00
#
# Completions
#
2006-01-17 19:34:50 +00:00
# Regular switches, set only accepts these before the variable name,
2022-02-09 08:46:07 +00:00
# so we need to test using "__fish_is_nth_token 1"
2021-06-30 00:26:49 +00:00
2022-02-09 08:46:07 +00: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 15:44:00 +00:00
2018-04-03 19:40:51 +00:00
#TODO: add CPP code to generate list of read-only variables and exclude them from the following completions
2006-01-17 19:34:50 +00:00
# Complete using preexisting variable names
2024-04-06 18:47:48 +00:00
set -l maybe_filter_private_vars '
string match (
if string match -qr -- "^_" " $( commandline -t) " : then
echo "*"
else
echo -rv
echo "^__"
end
) '
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 | $maybe_filter_private_vars | 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 | $maybe_filter_private_vars | string replace -r '^((?:history|fish_killring) ).*' ' $1 ' | 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 | $maybe_filter_private_vars | string replace ' ' \t'Universal Variable: ') "
2019-05-21 15:00:32 +00:00
# Complete some fish configuration variables even if they aren't set.
2022-02-09 08:46:07 +00: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-03 19:40:51 +00:00
# Complete scope-specific variables
2022-02-09 08:46:07 +00: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-03 19:40:51 +00:00
# Complete using preexisting variable names for `set --erase`
2020-06-20 07:51:29 +00: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-03 19:40:51 +00:00
# Complete scope-specific variables for `set --erase`
2020-06-20 07:51:29 +00: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-15 20:03:03 +00:00
# Color completions
2021-12-15 16:59:12 +00: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-15 20:03:03 +00:00
# Locale completions
2020-03-09 18:36:12 +00: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