2016-05-08 23:27:15 +00:00
|
|
|
#
|
|
|
|
# Initializations that should only be performed when entering interactive mode.
|
|
|
|
#
|
|
|
|
# This function is called by the __fish_on_interactive function, which is defined in config.fish.
|
|
|
|
#
|
|
|
|
function __fish_config_interactive -d "Initializations that should be performed when entering interactive mode"
|
2022-01-09 13:28:41 +00:00
|
|
|
# For one-off upgrades of the fish version
|
|
|
|
if not set -q __fish_initialized
|
|
|
|
set -U __fish_initialized 0
|
|
|
|
end
|
|
|
|
|
2017-07-02 20:41:07 +00:00
|
|
|
set -g __fish_active_key_bindings
|
2016-05-08 23:27:15 +00:00
|
|
|
|
2019-02-15 01:01:28 +00:00
|
|
|
# usage: __init_uvar VARIABLE VALUES...
|
|
|
|
function __init_uvar -d "Sets a universal variable if it's not already set"
|
2019-02-15 05:42:42 +00:00
|
|
|
if not set --query $argv[1]
|
2019-02-15 01:01:28 +00:00
|
|
|
set --universal $argv
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-13 01:47:59 +00:00
|
|
|
# If we are starting up for the first time, set various defaults.
|
2022-01-28 00:38:14 +00:00
|
|
|
if test $__fish_initialized -lt 3400
|
2022-08-14 14:05:26 +00:00
|
|
|
# Create empty configuration directores if they do not already exist
|
|
|
|
test -e $__fish_config_dir/completions/ -a -e $__fish_config_dir/conf.d/ -a -e $__fish_config_dir/functions/ ||
|
|
|
|
mkdir -p $__fish_config_dir/{completions, conf.d, functions}
|
|
|
|
|
|
|
|
# Create config.fish with some boilerplate if it does not exist
|
|
|
|
test -e $__fish_config_dir/config.fish || echo "\
|
|
|
|
if status is-interactive
|
|
|
|
# Commands to run in interactive sessions can go here
|
|
|
|
end" >$__fish_config_dir/config.fish
|
|
|
|
|
2021-12-15 16:59:12 +00:00
|
|
|
# Regular syntax highlighting colors
|
2023-07-25 14:42:24 +00:00
|
|
|
# NOTE: These should only use named colors
|
|
|
|
# to give us the maximum chance they are
|
|
|
|
# visible in whatever terminal setup.
|
|
|
|
#
|
2022-02-03 12:03:05 +00:00
|
|
|
__init_uvar fish_color_normal normal
|
|
|
|
__init_uvar fish_color_command blue
|
|
|
|
__init_uvar fish_color_param cyan
|
|
|
|
__init_uvar fish_color_redirection cyan --bold
|
|
|
|
__init_uvar fish_color_comment red
|
|
|
|
__init_uvar fish_color_error brred
|
|
|
|
__init_uvar fish_color_escape brcyan
|
|
|
|
__init_uvar fish_color_operator brcyan
|
|
|
|
__init_uvar fish_color_end green
|
|
|
|
__init_uvar fish_color_quote yellow
|
2023-07-25 14:42:24 +00:00
|
|
|
__init_uvar fish_color_autosuggestion brblack
|
2022-02-03 12:03:05 +00:00
|
|
|
__init_uvar fish_color_user brgreen
|
|
|
|
__init_uvar fish_color_host normal
|
|
|
|
__init_uvar fish_color_host_remote yellow
|
|
|
|
__init_uvar fish_color_valid_path --underline
|
|
|
|
__init_uvar fish_color_status red
|
|
|
|
|
|
|
|
__init_uvar fish_color_cwd green
|
|
|
|
__init_uvar fish_color_cwd_root red
|
|
|
|
|
|
|
|
# Background color for search matches
|
2022-07-19 14:56:16 +00:00
|
|
|
__init_uvar fish_color_search_match bryellow --background=brblack
|
2022-02-03 12:03:05 +00:00
|
|
|
|
|
|
|
# Background color for selections
|
|
|
|
__init_uvar fish_color_selection white --bold --background=brblack
|
|
|
|
|
|
|
|
__init_uvar fish_color_cancel -r
|
|
|
|
|
|
|
|
# Pager colors
|
2022-07-19 14:56:16 +00:00
|
|
|
__init_uvar fish_pager_color_prefix normal --bold --underline
|
2022-02-03 12:03:05 +00:00
|
|
|
__init_uvar fish_pager_color_completion normal
|
2023-07-25 14:42:24 +00:00
|
|
|
__init_uvar fish_pager_color_description yellow -i
|
2022-02-03 12:03:05 +00:00
|
|
|
__init_uvar fish_pager_color_progress brwhite --background=cyan
|
|
|
|
__init_uvar fish_pager_color_selected_background -r
|
|
|
|
|
|
|
|
#
|
|
|
|
# Directory history colors
|
|
|
|
#
|
|
|
|
__init_uvar fish_color_history_current --bold
|
2016-05-08 23:27:15 +00:00
|
|
|
end
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2013-11-11 15:44:24 +00:00
|
|
|
#
|
2016-05-08 22:57:56 +00:00
|
|
|
# Generate man page completions if not present.
|
2013-11-11 15:44:24 +00:00
|
|
|
#
|
2017-02-12 13:03:54 +00:00
|
|
|
# Don't do this if we're being invoked as part of running unit tests.
|
|
|
|
if not set -q FISH_UNIT_TESTS_RUNNING
|
2020-07-09 16:35:02 +00:00
|
|
|
# Check if our manpage completion script exists because some distros split it out.
|
|
|
|
# (#7183)
|
|
|
|
set -l script $__fish_data_dir/tools/create_manpage_completions.py
|
|
|
|
if not test -d $__fish_user_data_dir/generated_completions; and test -e "$script"
|
2017-02-12 13:03:54 +00:00
|
|
|
# Generating completions from man pages needs python (see issue #3588).
|
|
|
|
|
|
|
|
# We cannot simply do `fish_update_completions &` because it is a function.
|
|
|
|
# We cannot do `eval` since it is a function.
|
|
|
|
# We don't want to call `fish -c` since that is unnecessary and sources config.fish again.
|
|
|
|
# Hence we'll call python directly.
|
|
|
|
# c_m_p.py should work with any python version.
|
2018-03-12 13:34:20 +00:00
|
|
|
set -l update_args -B $__fish_data_dir/tools/create_manpage_completions.py --manpath --cleanup-in '~/.config/fish/completions' --cleanup-in '~/.config/fish/generated_completions'
|
2020-04-28 11:05:20 +00:00
|
|
|
if set -l python (__fish_anypython)
|
|
|
|
# Run python directly in the background and swallow all output
|
|
|
|
$python $update_args >/dev/null 2>&1 &
|
|
|
|
# Then disown the job so that it continues to run in case of an early exit (#6269)
|
2021-02-24 19:25:58 +00:00
|
|
|
disown >/dev/null 2>&1
|
2017-02-12 13:03:54 +00:00
|
|
|
end
|
2017-01-29 04:37:32 +00:00
|
|
|
end
|
2013-11-09 05:59:10 +00:00
|
|
|
end
|
|
|
|
|
2016-05-08 23:27:15 +00:00
|
|
|
#
|
2016-05-08 22:57:56 +00:00
|
|
|
# Print a greeting.
|
2020-05-30 06:53:08 +00:00
|
|
|
# The default just prints a variable of the same name.
|
2016-05-08 23:27:15 +00:00
|
|
|
#
|
2020-06-04 14:57:35 +00:00
|
|
|
# NOTE: This status check is necessary to not print the greeting when `read`ing in scripts. See #7080.
|
|
|
|
if status --is-interactive
|
2020-05-30 06:53:08 +00:00
|
|
|
and functions -q fish_greeting
|
|
|
|
fish_greeting
|
2016-05-08 23:27:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Completions for SysV startup scripts. These aren't bound to any
|
|
|
|
# specific command, so they can't be autoloaded.
|
|
|
|
#
|
2016-09-10 22:07:58 +00:00
|
|
|
if test -d /etc/init.d
|
|
|
|
complete -x -p "/etc/init.d/*" -a start --description 'Start service'
|
|
|
|
complete -x -p "/etc/init.d/*" -a stop --description 'Stop service'
|
|
|
|
complete -x -p "/etc/init.d/*" -a status --description 'Print service status'
|
|
|
|
complete -x -p "/etc/init.d/*" -a restart --description 'Stop and then start service'
|
|
|
|
complete -x -p "/etc/init.d/*" -a reload --description 'Reload service configuration'
|
|
|
|
end
|
2016-05-08 23:27:15 +00:00
|
|
|
|
2018-11-25 09:57:05 +00:00
|
|
|
#
|
|
|
|
# We want to show our completions for the [ (test) builtin, but
|
|
|
|
# we don't want to create a [.fish. test.fish will not be loaded until
|
|
|
|
# the user tries [ interactively.
|
|
|
|
#
|
|
|
|
complete -c [ --wraps test
|
2019-10-29 12:32:26 +00:00
|
|
|
complete -c ! --wraps not
|
2016-05-08 23:27:15 +00:00
|
|
|
|
2019-04-15 19:49:24 +00:00
|
|
|
#
|
|
|
|
# Only a few builtins take filenames; initialize the rest with no file completions
|
|
|
|
#
|
2020-04-06 16:59:10 +00:00
|
|
|
complete -c(builtin -n | string match -rv '(\.|:|source|cd|contains|count|echo|exec|printf|random|realpath|set|\\[|test|for)') --no-files
|
2019-04-15 19:49:24 +00:00
|
|
|
|
2016-05-08 23:27:15 +00:00
|
|
|
# Reload key bindings when binding variable change
|
|
|
|
function __fish_reload_key_bindings -d "Reload key bindings when binding variable change" --on-variable fish_key_bindings
|
2018-04-01 23:11:12 +00:00
|
|
|
# Make sure some key bindings are set
|
2019-02-15 01:01:28 +00:00
|
|
|
__init_uvar fish_key_bindings fish_default_key_bindings
|
2018-04-01 23:11:12 +00:00
|
|
|
|
2017-07-02 20:41:07 +00:00
|
|
|
# Do nothing if the key bindings didn't actually change.
|
2016-05-08 23:27:15 +00:00
|
|
|
# This could be because the variable was set to the existing value
|
2017-07-02 20:41:07 +00:00
|
|
|
# or because it was a local variable.
|
|
|
|
# If fish_key_bindings is empty on the first run, we still need to set the defaults.
|
2016-05-22 17:54:11 +00:00
|
|
|
if test "$fish_key_bindings" = "$__fish_active_key_bindings" -a -n "$fish_key_bindings"
|
2016-05-08 23:27:15 +00:00
|
|
|
return
|
|
|
|
end
|
2017-07-02 20:41:07 +00:00
|
|
|
# Check if fish_key_bindings is a valid function.
|
|
|
|
# If not, either keep the previous bindings (if any) or revert to default.
|
|
|
|
# Also print an error so the user knows.
|
2016-05-22 17:54:11 +00:00
|
|
|
if not functions -q "$fish_key_bindings"
|
|
|
|
echo "There is no fish_key_bindings function called: '$fish_key_bindings'" >&2
|
2016-11-27 13:12:10 +00:00
|
|
|
# We need to see if this is a defined function, otherwise we'd be in an endless loop.
|
|
|
|
if functions -q $__fish_active_key_bindings
|
2016-05-22 17:54:11 +00:00
|
|
|
echo "Keeping $__fish_active_key_bindings" >&2
|
2016-11-27 13:12:10 +00:00
|
|
|
# Set the variable to the old value so this error doesn't happen again.
|
|
|
|
set fish_key_bindings $__fish_active_key_bindings
|
2016-05-22 17:54:11 +00:00
|
|
|
return 1
|
2016-08-15 20:36:21 +00:00
|
|
|
else if functions -q fish_default_key_bindings
|
2016-05-22 17:54:11 +00:00
|
|
|
echo "Reverting to default bindings" >&2
|
|
|
|
set fish_key_bindings fish_default_key_bindings
|
|
|
|
# Return because we are called again
|
|
|
|
return 0
|
2016-08-15 20:36:21 +00:00
|
|
|
else
|
|
|
|
# If we can't even find the default bindings, something is broken.
|
|
|
|
# Without it, we would eventually run into the stack size limit, but that'd print hundreds of duplicate lines
|
|
|
|
# so we should give up earlier.
|
|
|
|
echo "Cannot find fish_default_key_bindings, falling back to very simple bindings." >&2
|
|
|
|
echo "Most likely something is wrong with your installation." >&2
|
|
|
|
return 0
|
2016-05-22 17:54:11 +00:00
|
|
|
end
|
|
|
|
end
|
2016-05-08 23:27:15 +00:00
|
|
|
set -g __fish_active_key_bindings "$fish_key_bindings"
|
|
|
|
set -g fish_bind_mode default
|
|
|
|
if test "$fish_key_bindings" = fish_default_key_bindings
|
2016-05-22 17:54:11 +00:00
|
|
|
# Redirect stderr per #1155
|
2018-04-01 20:42:38 +00:00
|
|
|
fish_default_key_bindings 2>/dev/null
|
2016-05-08 23:27:15 +00:00
|
|
|
else
|
2018-10-21 13:31:49 +00:00
|
|
|
$fish_key_bindings 2>/dev/null
|
2016-05-08 23:27:15 +00:00
|
|
|
end
|
|
|
|
# Load user key bindings if they are defined
|
|
|
|
if functions --query fish_user_key_bindings >/dev/null
|
2018-04-01 20:42:38 +00:00
|
|
|
fish_user_key_bindings 2>/dev/null
|
2016-05-08 23:27:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-22 17:54:11 +00:00
|
|
|
# Load key bindings
|
|
|
|
__fish_reload_key_bindings
|
2016-05-08 23:27:15 +00:00
|
|
|
|
2021-01-12 11:42:52 +00:00
|
|
|
# Detect whether the terminal reflows on its own
|
|
|
|
# If it does we shouldn't do it.
|
|
|
|
# Allow $fish_handle_reflow to override it.
|
|
|
|
if not set -q fish_handle_reflow
|
2020-11-30 19:50:02 +00:00
|
|
|
# VTE reflows the text itself, so us doing it inevitably races against it.
|
2020-11-30 19:01:33 +00:00
|
|
|
# Guidance from the VTE developers is to let them repaint.
|
2020-11-30 19:50:02 +00:00
|
|
|
if set -q VTE_VERSION
|
2023-09-22 15:04:59 +00:00
|
|
|
# Same for these terminals
|
2021-01-12 11:42:52 +00:00
|
|
|
or string match -q -- 'alacritty*' $TERM
|
2023-09-22 15:04:59 +00:00
|
|
|
or test "$TERM_PROGRAM" = WezTerm
|
2021-01-12 11:42:52 +00:00
|
|
|
set -g fish_handle_reflow 0
|
|
|
|
else if set -q KONSOLE_VERSION
|
2021-01-12 11:37:35 +00:00
|
|
|
and test "$KONSOLE_VERSION" -ge 210400 2>/dev/null
|
2021-01-12 11:42:52 +00:00
|
|
|
# Konsole since version 21.04(.00)
|
|
|
|
# Note that this is optional, but since we have no way of detecting it
|
|
|
|
# we go with the default, which is true.
|
|
|
|
set -g fish_handle_reflow 0
|
|
|
|
else
|
|
|
|
set -g fish_handle_reflow 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_winch_handler --on-signal WINCH -d "Repaint screen when window changes size"
|
|
|
|
if test "$fish_handle_reflow" = 1 2>/dev/null
|
|
|
|
commandline -f repaint >/dev/null 2>/dev/null
|
2021-01-12 11:37:35 +00:00
|
|
|
end
|
2016-05-08 23:27:15 +00:00
|
|
|
end
|
|
|
|
|
2024-04-03 10:18:52 +00:00
|
|
|
# Notify terminals when $PWD changes via OSC 7 (issue #906).
|
|
|
|
function __fish_update_cwd_osc --on-variable PWD --description 'Notify terminals when $PWD changes'
|
|
|
|
printf \e\]7\;file://%s%s\a $hostname (string escape --style=url -- $PWD)
|
2016-05-08 23:27:15 +00:00
|
|
|
end
|
2024-04-03 10:18:52 +00:00
|
|
|
__fish_update_cwd_osc # Run once because we might have already inherited a PWD from an old tab
|
2016-05-08 23:27:15 +00:00
|
|
|
|
2019-12-13 11:26:40 +00:00
|
|
|
# Bump this whenever some code below needs to run once when upgrading to a new version.
|
|
|
|
# The universal variable __fish_initialized is initialized in share/config.fish.
|
2022-01-28 00:38:14 +00:00
|
|
|
set __fish_initialized 3400
|
2022-08-14 15:01:22 +00:00
|
|
|
|
|
|
|
functions -e __fish_config_interactive
|
2022-09-01 05:15:16 +00:00
|
|
|
end
|