fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
3dc36f74b
master
1# localization: skip(private) 2# 3# Initializations that should only be performed when entering interactive mode. 4# 5# This function is called by the __fish_on_interactive function, which is defined in config.fish. 6# 7function __fish_config_interactive -d"Initializations that should be performed when entering interactive mode" 8functions -e __fish_config_interactive 9 10set -g __fish_active_key_bindings 11 12functions -q __fish_webconfig_update_color_hook 13 14# 15# Generate man page completions if not present. 16# 17# Don't do this if we're being invoked as part of running unit tests. 18if not set -q FISH_UNIT_TESTS_RUNNING 19if not test -d $__fish_cache_dir /generated_completions 20# We cannot simply do `fish_update_completions &` because it is a function. 21# We don't want to call `fish -c` since that is unnecessary and sources config.fish again. 22mkdir -p$__fish_cache_dir /generated_completions 23fish_update_completions_detach=true fish_update_completions2> /dev/null 24end 25end 26 27# 28# Print a greeting. 29# The default just prints a variable of the same name. 30# 31# NOTE: This status check is necessary to not print the greeting when `read`ing in scripts. See #7080. 32if not status is-interactive-read 33and functions -q fish_greeting 34fish_greeting 35end 36 37# Display SHELL_WELCOME if set. This is a standard environment variable (introduced by 38# systemd v257) intended for shells to display when they first initialize. 39if not status is-interactive-read 40and set -q SHELL_WELCOME[ 1 ] 41string join --' ' $SHELL_WELCOME 42end 43 44# 45# Completions for SysV startup scripts. These aren't bound to any 46# specific command, so they can't be autoloaded. 47# 48if test -d /etc/init.d 49complete -x -p"/etc/init.d/*" -a start --description'Start service' 50complete -x -p"/etc/init.d/*" -a stop --description'Stop service' 51complete -x -p"/etc/init.d/*" -a status --description'Print service status' 52complete -x -p"/etc/init.d/*" -a restart --description'Stop and then start service' 53complete -x -p"/etc/init.d/*" -a reload --description'Reload service configuration' 54end 55 56# 57# Only a few builtins take filenames; initialize the rest with no file completions 58# 59complete -c( builtin -n| string match -rv'(\.|:|source|cd|contains|count|echo|exec|fish_indent|printf|random|realpath|set|\\[|test|for)' ) --no-files 60 61# Reload key bindings when binding variable change 62function __fish_reload_key_bindings -d"Reload key bindings when binding variable change" --on-variable fish_key_bindings 63# Make sure some key bindings are set 64if not set --query fish_key_bindings 65set --global fish_key_bindings fish_default_key_bindings 66return 67end 68 69# Do nothing if the key bindings didn't actually change. 70# This could be because the variable was set to the existing value 71# or because it was a local variable. 72# If fish_key_bindings is empty on the first run, we still need to set the defaults. 73if test " $fish_key_bindings " = " $__fish_active_key_bindings " -a -n " $fish_key_bindings " 74return 75end 76# Check if fish_key_bindings is a valid function. 77# If not, either keep the previous bindings (if any) or revert to default. 78# Also print an error so the user knows. 79if not functions -q" $fish_key_bindings " 80echo "There is no fish_key_bindings function called: ' $fish_key_bindings '" >&2 81# We need to see if this is a defined function, otherwise we'd be in an endless loop. 82if functions -q$__fish_active_key_bindings 83echo "Keeping $__fish_active_key_bindings " >&2 84# Set the variable to the old value so this error doesn't happen again. 85set fish_key_bindings$__fish_active_key_bindings 86return 1 87else if functions -q fish_default_key_bindings 88echo "Reverting to default bindings" >&2 89set fish_key_bindings fish_default_key_bindings 90# Return because we are called again 91return 0 92else 93# If we can't even find the default bindings, something is broken. 94# Without it, we would eventually run into the stack size limit, but that'd print hundreds of duplicate lines 95# so we should give up earlier. 96echo "Cannot find fish_default_key_bindings, falling back to very simple bindings." >&2 97echo "Most likely something is wrong with your installation." >&2 98return 0 99end 100end 101set -g __fish_active_key_bindings" $fish_key_bindings " 102set -g fish_bind_mode default 103$fish_key_bindings 104# Load user key bindings if they are defined 105if functions --query fish_user_key_bindings> /dev/null 106fish_user_key_bindings 107end 108end 109 110# Load key bindings 111__fish_reload_key_bindings 112 113# Detect whether the terminal reflows on its own 114# If it does we shouldn't do it. 115# Allow $fish_handle_reflow to override it. 116if not set -q fish_handle_reflow 117# VTE reflows the text itself, so us doing it inevitably races against it. 118# Guidance from the VTE developers is to let them repaint. 119# Konsole reflows since version 21.04. Konsole added XTVERSION 120# in v22.03.80~7. 121# TODO(term-workaround) 122if string match -rq --'^(?:VTE\b|Konsole |WezTerm )' ( status terminal) 123or begin 124set -q KONSOLE_VERSION 125and test " $KONSOLE_VERSION " -ge 210400 2> /dev/null 126end 127or string match -q --'alacritty*' $TERM 128set -g fish_handle_reflow0 129else 130set -g fish_handle_reflow1 131end 132end 133 134function __fish_winch_handler --on-signal WINCH -d"Repaint screen when window changes size" 135if test " $fish_handle_reflow " = 1 2> /dev/null 136commandline -f repaint> /dev/null2> /dev/null 137end 138end 139 140# Notify terminals when $PWD changes via OSC 7 (issue #906). 141if not functions --query __fish_update_cwd_osc 142function __fish_update_cwd_osc --description'Notify terminals when $PWD might have changed' \ 143 --on-variable=PWD --on-event=fish_prompt 144set -l host$hostname 145# if set -l konsole_version (string match -r -- '^Konsole (\d+)\..*' (status terminal))[2] 146# # To-do: use a Konsole version where KF6_DEP_VERSION is >= 6.12 147# and $konsole_version -lt ??? 148# end 149# TODO(term-workaround) 150if set -q KONSOLE_VERSION 151set host'' 152end 153if [ -n " $MSYSTEM " ] && string match -rq --'^(Konsole|WezTerm) ' ( status terminal) 154return 155end 156if [ " $TERM " = dumb] 157return 158end 159printf \e\] 7 \; file://%s%s\a ( string escape --style=url --$host $PWD ) 160end 161end 162__fish_update_cwd_osc # Run once because we might have already inherited a PWD from an old tab 163end