2016-05-09 07:27:15 +08: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"
|
2017-05-22 13:22:55 +08:00
|
|
|
if not set -q __fish_init_3_x
|
|
|
|
# Perform transitions relevant to going from fish 2.x to 3.x.
|
|
|
|
|
|
|
|
# Migrate old universal abbreviations to the new scheme.
|
2018-09-20 22:52:28 +08:00
|
|
|
__fish_abbr_old | source
|
2017-05-22 13:22:55 +08:00
|
|
|
|
|
|
|
set -U __fish_init_3_x
|
|
|
|
end
|
|
|
|
|
2016-05-09 06:57:56 +08:00
|
|
|
# Make sure this function is only run once.
|
2016-05-09 07:27:15 +08:00
|
|
|
if set -q __fish_config_interactive_done
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
set -g __fish_config_interactive_done
|
2017-07-03 04:41:07 +08:00
|
|
|
set -g __fish_active_key_bindings
|
2016-05-09 07:27:15 +08:00
|
|
|
|
2016-09-11 11:28:06 +08:00
|
|
|
if not set -q fish_greeting
|
2017-04-21 11:17:50 +08:00
|
|
|
set -l line1 (_ 'Welcome to fish, the friendly interactive shell')
|
|
|
|
set -l line2 ''
|
2016-09-11 11:28:06 +08:00
|
|
|
if not set -q __fish_init_2_3_0
|
2017-04-21 11:17:50 +08:00
|
|
|
set line2 \n(_ 'Type `help` for instructions on how to use fish')
|
2016-09-11 11:28:06 +08:00
|
|
|
end
|
2017-04-21 11:17:50 +08:00
|
|
|
set -U fish_greeting "$line1$line2"
|
2016-09-11 11:28:06 +08:00
|
|
|
end
|
|
|
|
|
2019-11-08 18:08:37 +08:00
|
|
|
if set -q fish_private_mode and string length -q -- $fish_greeting
|
2018-10-22 10:18:27 +08:00
|
|
|
set -l line (_ "fish is running in private mode, history will not be persisted.")
|
|
|
|
set -g fish_greeting $fish_greeting.\n$line
|
|
|
|
end
|
|
|
|
|
2019-02-15 09:01:28 +08:00
|
|
|
# usage: __init_uvar VARIABLE VALUES...
|
|
|
|
function __init_uvar -d "Sets a universal variable if it's not already set"
|
2019-02-15 13:42:42 +08:00
|
|
|
if not set --query $argv[1]
|
2019-02-15 09:01:28 +08:00
|
|
|
set --universal $argv
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-09 07:27:15 +08:00
|
|
|
#
|
2016-09-13 09:47:59 +08:00
|
|
|
# If we are starting up for the first time, set various defaults.
|
|
|
|
#
|
|
|
|
# bump this to 2_4_0 when rolling release if anything changes after 9/10/2016
|
|
|
|
if not set -q __fish_init_2_39_8
|
2019-02-15 09:01:28 +08:00
|
|
|
|
2016-05-09 07:27:15 +08:00
|
|
|
# Regular syntax highlighting colors
|
2019-02-15 09:01:28 +08:00
|
|
|
__init_uvar fish_color_normal normal
|
|
|
|
__init_uvar fish_color_command 005fd7
|
|
|
|
__init_uvar fish_color_param 00afff
|
|
|
|
__init_uvar fish_color_redirection 00afff
|
|
|
|
__init_uvar fish_color_comment 990000
|
|
|
|
__init_uvar fish_color_error ff0000
|
|
|
|
__init_uvar fish_color_escape 00a6b2
|
|
|
|
__init_uvar fish_color_operator 00a6b2
|
|
|
|
__init_uvar fish_color_end 009900
|
|
|
|
__init_uvar fish_color_quote 999900
|
|
|
|
__init_uvar fish_color_autosuggestion 555 brblack
|
|
|
|
__init_uvar fish_color_user brgreen
|
|
|
|
|
|
|
|
__init_uvar fish_color_host normal
|
|
|
|
__init_uvar fish_color_valid_path --underline
|
|
|
|
|
|
|
|
__init_uvar fish_color_cwd green
|
|
|
|
__init_uvar fish_color_cwd_root red
|
2016-05-09 07:27:15 +08:00
|
|
|
|
|
|
|
# Background color for matching quotes and parenthesis
|
2019-02-15 09:01:28 +08:00
|
|
|
__init_uvar fish_color_match --background=brblue
|
2016-05-09 07:27:15 +08:00
|
|
|
|
|
|
|
# Background color for search matches
|
2019-02-15 09:01:28 +08:00
|
|
|
__init_uvar fish_color_search_match bryellow --background=brblack
|
2016-05-09 07:27:15 +08:00
|
|
|
|
|
|
|
# Background color for selections
|
2019-02-15 09:01:28 +08:00
|
|
|
__init_uvar fish_color_selection white --bold --background=brblack
|
2016-05-09 07:27:15 +08:00
|
|
|
|
2019-02-15 09:01:28 +08:00
|
|
|
# XXX fish_color_cancel was added in 2.6, but this was added to post-2.3 initialization
|
|
|
|
# when 2.4 and 2.5 were already released
|
|
|
|
__init_uvar fish_color_cancel -r
|
2017-04-11 11:28:26 +08:00
|
|
|
|
2016-05-09 07:27:15 +08:00
|
|
|
# Pager colors
|
2019-02-15 09:01:28 +08:00
|
|
|
__init_uvar fish_pager_color_prefix white --bold --underline
|
|
|
|
__init_uvar fish_pager_color_completion
|
|
|
|
__init_uvar fish_pager_color_description B3A06D yellow
|
|
|
|
__init_uvar fish_pager_color_progress brwhite --background=cyan
|
2016-05-09 07:27:15 +08:00
|
|
|
|
|
|
|
#
|
|
|
|
# Directory history colors
|
|
|
|
#
|
2019-02-15 09:01:28 +08:00
|
|
|
__init_uvar fish_color_history_current --bold
|
2016-09-11 11:28:06 +08:00
|
|
|
|
|
|
|
set -U __fish_init_2_39_8
|
2016-05-09 07:27:15 +08:00
|
|
|
end
|
2007-08-20 00:42:30 +08:00
|
|
|
|
2013-11-11 23:44:24 +08:00
|
|
|
#
|
2016-05-09 06:57:56 +08:00
|
|
|
# Generate man page completions if not present.
|
2013-11-11 23:44:24 +08:00
|
|
|
#
|
2017-02-12 21:03:54 +08:00
|
|
|
# Don't do this if we're being invoked as part of running unit tests.
|
|
|
|
if not set -q FISH_UNIT_TESTS_RUNNING
|
2018-12-15 12:09:29 +08:00
|
|
|
if not test -d $__fish_user_data_dir/generated_completions
|
2017-02-12 21:03:54 +08: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 21:34:20 +08: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'
|
2018-10-21 21:31:49 +08:00
|
|
|
for py in python{3,2,}
|
|
|
|
if command -sq $py
|
2019-11-08 06:17:15 +08:00
|
|
|
set -l c $py $update_args
|
|
|
|
$c (: fish_update_completions: generating completions from man pages) >/dev/null 2>&1 &
|
2018-10-21 21:31:49 +08:00
|
|
|
break
|
|
|
|
end
|
2017-02-12 21:03:54 +08:00
|
|
|
end
|
2017-01-29 12:37:32 +08:00
|
|
|
end
|
2013-11-09 13:59:10 +08:00
|
|
|
end
|
|
|
|
|
2016-05-09 07:27:15 +08:00
|
|
|
#
|
2016-05-09 06:57:56 +08:00
|
|
|
# Print a greeting.
|
|
|
|
# fish_greeting can be a function (preferred) or a variable.
|
2016-05-09 07:27:15 +08:00
|
|
|
#
|
2016-07-24 16:32:09 +08:00
|
|
|
if status --is-interactive
|
2016-07-31 13:47:17 +08:00
|
|
|
if functions -q fish_greeting
|
|
|
|
fish_greeting
|
|
|
|
else
|
|
|
|
# The greeting used to be skipped when fish_greeting was empty (not just undefined)
|
|
|
|
# Keep it that way to not print superfluous newlines on old configuration
|
2019-02-15 09:01:28 +08:00
|
|
|
test -n "$fish_greeting"
|
|
|
|
and echo $fish_greeting
|
2016-07-24 14:33:20 +08:00
|
|
|
end
|
2016-05-09 07:27:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# This event handler makes sure the prompt is repainted when
|
2019-04-09 15:29:22 +08:00
|
|
|
# fish_color_cwd{,_root} changes value. Like all event handlers, it can't be
|
2016-05-09 07:27:15 +08:00
|
|
|
# autoloaded.
|
|
|
|
#
|
2019-04-09 15:29:22 +08:00
|
|
|
function __fish_repaint -v fish_color_cwd -v fish_color_cwd_root -d "Event handler, repaints the prompt when fish_color_cwd* changes"
|
2016-05-09 07:27:15 +08:00
|
|
|
if status --is-interactive
|
|
|
|
set -e __fish_prompt_cwd
|
2018-04-02 04:42:38 +08:00
|
|
|
commandline -f repaint 2>/dev/null
|
2016-05-09 07:27:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Completions for SysV startup scripts. These aren't bound to any
|
|
|
|
# specific command, so they can't be autoloaded.
|
|
|
|
#
|
2016-09-11 06:07:58 +08: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-09 07:27:15 +08:00
|
|
|
|
2018-11-25 17:57:05 +08: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 20:32:26 +08:00
|
|
|
complete -c ! --wraps not
|
2016-05-09 07:27:15 +08:00
|
|
|
|
2019-04-16 03:49:24 +08:00
|
|
|
#
|
|
|
|
# Only a few builtins take filenames; initialize the rest with no file completions
|
|
|
|
#
|
2019-10-29 20:32:26 +08:00
|
|
|
complete -c(builtin -n | string match -rv '(source|cd|exec|realpath|set|\\[|test|for)') --no-files
|
2019-04-16 03:49:24 +08:00
|
|
|
|
2016-05-09 07:27:15 +08: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-02 07:11:12 +08:00
|
|
|
# Make sure some key bindings are set
|
2019-02-15 09:01:28 +08:00
|
|
|
__init_uvar fish_key_bindings fish_default_key_bindings
|
2018-04-02 07:11:12 +08:00
|
|
|
|
2017-07-03 04:41:07 +08:00
|
|
|
# Do nothing if the key bindings didn't actually change.
|
2016-05-09 07:27:15 +08:00
|
|
|
# This could be because the variable was set to the existing value
|
2017-07-03 04:41:07 +08: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-23 01:54:11 +08:00
|
|
|
if test "$fish_key_bindings" = "$__fish_active_key_bindings" -a -n "$fish_key_bindings"
|
2016-05-09 07:27:15 +08:00
|
|
|
return
|
|
|
|
end
|
2017-07-03 04:41:07 +08: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-23 01:54:11 +08:00
|
|
|
if not functions -q "$fish_key_bindings"
|
|
|
|
echo "There is no fish_key_bindings function called: '$fish_key_bindings'" >&2
|
2016-11-27 21:12:10 +08: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-23 01:54:11 +08:00
|
|
|
echo "Keeping $__fish_active_key_bindings" >&2
|
2016-11-27 21:12:10 +08: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-23 01:54:11 +08:00
|
|
|
return 1
|
2016-08-16 04:36:21 +08:00
|
|
|
else if functions -q fish_default_key_bindings
|
2016-05-23 01:54:11 +08: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-16 04:36:21 +08: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-23 01:54:11 +08:00
|
|
|
end
|
|
|
|
end
|
2016-05-09 07:27:15 +08: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-23 01:54:11 +08:00
|
|
|
# Redirect stderr per #1155
|
2018-04-02 04:42:38 +08:00
|
|
|
fish_default_key_bindings 2>/dev/null
|
2016-05-09 07:27:15 +08:00
|
|
|
else
|
2018-10-21 21:31:49 +08:00
|
|
|
$fish_key_bindings 2>/dev/null
|
2016-05-09 07:27:15 +08:00
|
|
|
end
|
|
|
|
# Load user key bindings if they are defined
|
|
|
|
if functions --query fish_user_key_bindings >/dev/null
|
2018-04-02 04:42:38 +08:00
|
|
|
fish_user_key_bindings 2>/dev/null
|
2016-05-09 07:27:15 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-23 01:54:11 +08:00
|
|
|
# Load key bindings
|
|
|
|
__fish_reload_key_bindings
|
2016-05-09 07:27:15 +08:00
|
|
|
|
2017-02-25 21:42:52 +08:00
|
|
|
if not set -q FISH_UNIT_TESTS_RUNNING
|
|
|
|
# Enable bracketed paste before every prompt (see __fish_shared_bindings for the bindings).
|
|
|
|
# Disable it for unit tests so we don't have to add the sequences to bind.expect
|
|
|
|
function __fish_enable_bracketed_paste --on-event fish_prompt
|
|
|
|
printf "\e[?2004h"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Disable BP before every command because that might not support it.
|
2018-02-07 00:41:08 +08:00
|
|
|
function __fish_disable_bracketed_paste --on-event fish_preexec --on-event fish_exit
|
2017-02-25 21:42:52 +08:00
|
|
|
printf "\e[?2004l"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Tell the terminal we support BP. Since we are in __f_c_i, the first fish_prompt
|
|
|
|
# has already fired.
|
|
|
|
__fish_enable_bracketed_paste
|
|
|
|
end
|
|
|
|
|
2018-03-07 18:06:23 +08:00
|
|
|
# Similarly, enable TMUX's focus reporting when in tmux.
|
|
|
|
# This will be handled by
|
|
|
|
# - The keybindings (reading the sequence and triggering an event)
|
|
|
|
# - Any listeners (like the vi-cursor)
|
|
|
|
if set -q TMUX
|
2019-02-02 06:42:13 +08:00
|
|
|
and not set -q FISH_UNIT_TESTS_RUNNING
|
2018-03-07 18:06:23 +08:00
|
|
|
function __fish_enable_focus --on-event fish_postexec
|
2019-01-29 08:49:31 +08:00
|
|
|
echo -n \e\[\?1004h
|
2018-03-07 18:06:23 +08:00
|
|
|
end
|
|
|
|
function __fish_disable_focus --on-event fish_preexec
|
2019-01-29 08:49:31 +08:00
|
|
|
echo -n \e\[\?1004l
|
2018-03-07 18:06:23 +08:00
|
|
|
end
|
2019-04-22 02:26:57 +08:00
|
|
|
# Note: Don't call this initially because, even though we're in a fish_prompt event,
|
|
|
|
# tmux reacts sooo quickly that we'll still get a sequence before we're prepared for it.
|
|
|
|
# So this means that we won't get focus events until you've run at least one command, but that's preferable
|
|
|
|
# to always seeing `^[[I` when starting fish.
|
|
|
|
# __fish_enable_focus
|
2018-03-07 18:06:23 +08:00
|
|
|
end
|
|
|
|
|
2016-09-20 09:40:44 +08:00
|
|
|
function __fish_winch_handler --on-signal WINCH -d "Repaint screen when window changes size"
|
2018-05-30 00:32:54 +08:00
|
|
|
commandline -f repaint >/dev/null 2>/dev/null
|
2016-05-09 07:27:15 +08:00
|
|
|
end
|
|
|
|
|
2017-07-02 11:45:30 +08:00
|
|
|
# Notify terminals when $PWD changes (issue #906).
|
2018-12-14 21:49:08 +08:00
|
|
|
# VTE based terminals, Terminal.app, and iTerm.app (TODO) support this.
|
2019-03-07 05:52:20 +08:00
|
|
|
if test 0"$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal" -a (string match -r '\d+' 0"$TERM_PROGRAM_VERSION") -ge 309
|
2016-09-20 09:40:44 +08:00
|
|
|
function __update_cwd_osc --on-variable PWD --description 'Notify capable terminals when $PWD changes'
|
2018-12-14 21:49:08 +08:00
|
|
|
if status --is-command-substitution || set -q INSIDE_EMACS
|
2017-07-02 11:45:30 +08:00
|
|
|
return
|
|
|
|
end
|
2018-12-14 21:49:08 +08:00
|
|
|
printf \e\]7\;file://%s%s\a $hostname (string escape --style=url $PWD)
|
2016-05-09 07:27:15 +08:00
|
|
|
end
|
2016-09-11 11:28:06 +08:00
|
|
|
__update_cwd_osc # Run once because we might have already inherited a PWD from an old tab
|
2016-05-09 07:27:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
### Command-not-found handlers
|
|
|
|
# This can be overridden by defining a new __fish_command_not_found_handler function
|
|
|
|
if not type -q __fish_command_not_found_handler
|
2016-09-13 04:59:35 +08:00
|
|
|
# Read the OS/Distro from /etc/os-release.
|
|
|
|
# This has a "ID=" line that defines the exact distribution,
|
|
|
|
# and an "ID_LIKE=" line that defines what it is derived from or otherwise like.
|
|
|
|
# For our purposes, we use both.
|
|
|
|
set -l os
|
|
|
|
if test -r /etc/os-release
|
|
|
|
set os (string match -r '^ID(?:_LIKE)?\s*=.*' < /etc/os-release | \
|
2018-05-02 01:28:37 +08:00
|
|
|
string replace -r '^ID(?:_LIKE)?\s*=(.*)' '$1' | string trim -c '\'"' | string split " ")
|
2016-09-13 04:59:35 +08:00
|
|
|
end
|
|
|
|
|
2016-05-09 07:27:15 +08:00
|
|
|
# First check if we are on OpenSUSE since SUSE's handler has no options
|
2016-09-13 04:59:35 +08:00
|
|
|
# but the same name and path as Ubuntu's.
|
2018-12-14 21:49:08 +08:00
|
|
|
if contains -- suse $os || contains -- sles $os && type -q command-not-found
|
2016-05-09 07:27:15 +08:00
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
|
|
|
/usr/bin/command-not-found $argv[1]
|
|
|
|
end
|
|
|
|
# Check for Fedora's handler
|
|
|
|
else if test -f /usr/libexec/pk-command-not-found
|
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
|
|
|
/usr/libexec/pk-command-not-found $argv[1]
|
|
|
|
end
|
|
|
|
# Check in /usr/lib, this is where modern Ubuntus place this command
|
|
|
|
else if test -f /usr/lib/command-not-found
|
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
|
|
|
/usr/lib/command-not-found -- $argv[1]
|
|
|
|
end
|
|
|
|
# Check for NixOS handler
|
|
|
|
else if test -f /run/current-system/sw/bin/command-not-found
|
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
|
|
|
/run/current-system/sw/bin/command-not-found $argv
|
|
|
|
end
|
|
|
|
# Ubuntu Feisty places this command in the regular path instead
|
2017-07-14 06:19:02 +08:00
|
|
|
else if type -q command-not-found
|
2016-05-09 07:27:15 +08:00
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
|
|
|
command-not-found -- $argv[1]
|
|
|
|
end
|
|
|
|
# pkgfile is an optional, but official, package on Arch Linux
|
|
|
|
# it ships with example handlers for bash and zsh, so we'll follow that format
|
|
|
|
else if type -p -q pkgfile
|
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2018-04-02 04:42:38 +08:00
|
|
|
set -l __packages (pkgfile --binaries --verbose -- $argv[1] 2>/dev/null)
|
2016-05-09 07:27:15 +08:00
|
|
|
if test $status -eq 0
|
|
|
|
printf "%s may be found in the following packages:\n" "$argv[1]"
|
|
|
|
printf " %s\n" $__packages
|
|
|
|
else
|
|
|
|
__fish_default_command_not_found_handler $argv[1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
# Use standard fish command not found handler otherwise
|
|
|
|
else
|
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
|
|
|
__fish_default_command_not_found_handler $argv[1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2007-10-01 06:53:54 +08:00
|
|
|
end
|