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"
|
2016-05-08 22:57:56 +00:00
|
|
|
# Make sure this function is only run once.
|
2016-05-08 23:27:15 +00:00
|
|
|
if set -q __fish_config_interactive_done
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
set -g __fish_config_interactive_done
|
|
|
|
|
|
|
|
# Set the correct configuration directory
|
|
|
|
set -l configdir ~/.config
|
|
|
|
if set -q XDG_CONFIG_HOME
|
|
|
|
set configdir $XDG_CONFIG_HOME
|
|
|
|
end
|
|
|
|
# Set the correct user data directory
|
|
|
|
set -l userdatadir ~/.local/share
|
|
|
|
if set -q XDG_DATA_HOME
|
|
|
|
set userdatadir $XDG_DATA_HOME
|
|
|
|
end
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2016-09-11 03:28:06 +00:00
|
|
|
if not set -q fish_greeting
|
|
|
|
set -l line1 (printf (_ 'Welcome to fish, the friendly interactive shell' ))
|
|
|
|
if not set -q __fish_init_2_3_0
|
|
|
|
set -l line2 \n(printf (_ 'Type %shelp%s for instructions on how to use fish %s') (set_color green) (set_color normal))
|
|
|
|
else
|
|
|
|
set -l line2 ''
|
|
|
|
end
|
|
|
|
set -U fish_greeting $line1$line2
|
|
|
|
end
|
|
|
|
|
2016-05-08 23:27:15 +00:00
|
|
|
#
|
2016-09-13 01:47:59 +00: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
|
|
|
|
set -l date (command date '+%Y-%m-%dT%H:%M:%S')
|
|
|
|
set -g colors_backup "$HOME/fish_previous_colors-$date.txt"
|
2016-09-11 03:28:06 +00:00
|
|
|
echo Backing up uvars to:\n (set_color --underline)$colors_backup(set_color normal)
|
|
|
|
set -U >>$colors_backup
|
|
|
|
for option in (set -Un | string match "fish*color_*")
|
|
|
|
set -eU $option
|
2016-05-08 23:27:15 +00:00
|
|
|
end
|
2016-09-11 03:28:06 +00:00
|
|
|
echo \"Normalized\" colors on upgrade.
|
2016-05-08 23:27:15 +00:00
|
|
|
|
|
|
|
# Regular syntax highlighting colors
|
|
|
|
set -q fish_color_normal
|
|
|
|
or set -U fish_color_normal normal
|
|
|
|
set -q fish_color_command
|
2016-09-10 22:07:58 +00:00
|
|
|
or set -U fish_color_command --bold
|
2016-05-08 23:27:15 +00:00
|
|
|
set -q fish_color_param
|
2016-05-30 16:05:19 +00:00
|
|
|
or set -U fish_color_param cyan
|
2016-05-08 23:27:15 +00:00
|
|
|
set -q fish_color_redirection
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_color_redirection brblue
|
2016-05-08 23:27:15 +00:00
|
|
|
set -q fish_color_comment
|
|
|
|
or set -U fish_color_comment red
|
|
|
|
set -q fish_color_error
|
2016-09-10 22:07:58 +00:00
|
|
|
or set -U fish_color_error brred
|
2016-05-08 23:27:15 +00:00
|
|
|
set -q fish_color_escape
|
2016-09-10 22:07:58 +00:00
|
|
|
or set -U fish_color_escape bryellow
|
2016-05-08 23:27:15 +00:00
|
|
|
set -q fish_color_operator
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_color_operator bryellow
|
2016-05-08 23:27:15 +00:00
|
|
|
set -q fish_color_end
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_color_end brmagenta
|
2016-05-08 23:27:15 +00:00
|
|
|
set -q fish_color_quote
|
2016-09-10 22:07:58 +00:00
|
|
|
or set -U fish_color_quote yellow
|
2016-05-08 23:27:15 +00:00
|
|
|
set -q fish_color_autosuggestion
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_color_autosuggestion 555 brblack
|
2016-05-08 23:27:15 +00:00
|
|
|
set -q fish_color_user
|
2016-09-10 22:07:58 +00:00
|
|
|
or set -U fish_color_user brgreen
|
2016-05-08 23:27:15 +00:00
|
|
|
|
|
|
|
set -q fish_color_host
|
|
|
|
or set -U fish_color_host normal
|
|
|
|
set -q fish_color_valid_path
|
|
|
|
or set -U fish_color_valid_path --underline
|
|
|
|
|
|
|
|
set -q fish_color_cwd
|
|
|
|
or set -U fish_color_cwd green
|
|
|
|
set -q fish_color_cwd_root
|
|
|
|
or set -U fish_color_cwd_root red
|
|
|
|
|
|
|
|
# Background color for matching quotes and parenthesis
|
|
|
|
set -q fish_color_match
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_color_match --background=blue
|
2016-05-08 23:27:15 +00:00
|
|
|
|
|
|
|
# Background color for search matches
|
|
|
|
set -q fish_color_search_match
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_color_search_match bryellow --background=brgrey
|
2016-05-08 23:27:15 +00:00
|
|
|
|
|
|
|
# Background color for selections
|
|
|
|
set -q fish_color_selection
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_color_selection white --bold --background=brgrey
|
2016-05-08 23:27:15 +00:00
|
|
|
|
|
|
|
# Pager colors
|
|
|
|
set -q fish_pager_color_prefix
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_pager_color_prefix white --bold --underline
|
|
|
|
#set -q fish_pager_color_completion
|
|
|
|
#or set -U fish_pager_color_completion
|
2016-05-30 16:05:19 +00:00
|
|
|
set -q fish_pager_color_description
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_pager_color_description B3A06D yellow
|
2016-05-08 23:27:15 +00:00
|
|
|
set -q fish_pager_color_progress
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_pager_color_progress brwhite --background=cyan
|
2016-05-08 23:27:15 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Directory history colors
|
|
|
|
#
|
|
|
|
set -q fish_color_history_current
|
2016-09-11 03:28:06 +00:00
|
|
|
or set -U fish_color_history_current --bold
|
|
|
|
|
|
|
|
|
|
|
|
set -U __fish_init_2_39_8
|
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
|
|
|
#
|
2014-09-29 11:39:36 +00:00
|
|
|
if not test -d $userdatadir/fish/generated_completions
|
2013-11-09 05:59:10 +00:00
|
|
|
#fish_update_completions is a function, so it can not be directly run in background.
|
2016-06-16 04:39:55 +00:00
|
|
|
eval (string escape "$__fish_bin_dir/fish") "-c 'fish_update_completions > /dev/null ^/dev/null' &"
|
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.
|
|
|
|
# fish_greeting can be a function (preferred) or a variable.
|
2016-05-08 23:27:15 +00:00
|
|
|
#
|
2016-07-24 08:32:09 +00:00
|
|
|
if status --is-interactive
|
2016-07-31 05:47:17 +00: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
|
|
|
|
test -n "$fish_greeting"
|
|
|
|
and echo $fish_greeting
|
2016-07-24 06:33:20 +00:00
|
|
|
end
|
2016-05-08 23:27:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
#
|
|
|
|
# This event handler makes sure the prompt is repainted when
|
|
|
|
# fish_color_cwd changes value. Like all event handlers, it can't be
|
|
|
|
# autoloaded.
|
|
|
|
#
|
|
|
|
function __fish_repaint --on-variable fish_color_cwd --description "Event handler, repaints the prompt when fish_color_cwd changes"
|
|
|
|
if status --is-interactive
|
|
|
|
set -e __fish_prompt_cwd
|
|
|
|
commandline -f repaint ^/dev/null
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function __fish_repaint_root --on-variable fish_color_cwd_root --description "Event handler, repaints the prompt when fish_color_cwd_root changes"
|
|
|
|
if status --is-interactive
|
|
|
|
set -e __fish_prompt_cwd
|
|
|
|
commandline -f repaint ^/dev/null
|
|
|
|
end
|
|
|
|
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
|
|
|
|
|
|
|
# Make sure some key bindings are set
|
|
|
|
if not set -q fish_key_bindings
|
|
|
|
set -U fish_key_bindings fish_default_key_bindings
|
|
|
|
end
|
|
|
|
|
|
|
|
# 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
|
|
|
|
# do nothing if the key bindings didn't actually change
|
|
|
|
# This could be because the variable was set to the existing value
|
|
|
|
# or because it was a local variable
|
2016-05-22 17:54:11 +00:00
|
|
|
# If fish_key_bindings is empty on the first run, we still need to set the defaults
|
|
|
|
if test "$fish_key_bindings" = "$__fish_active_key_bindings" -a -n "$fish_key_bindings"
|
2016-05-08 23:27:15 +00:00
|
|
|
return
|
|
|
|
end
|
2016-05-22 17:54:11 +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
|
|
|
|
if not functions -q "$fish_key_bindings"
|
|
|
|
echo "There is no fish_key_bindings function called: '$fish_key_bindings'" >&2
|
|
|
|
if set -q __fish_active_key_bindings
|
|
|
|
echo "Keeping $__fish_active_key_bindings" >&2
|
|
|
|
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
|
|
|
|
fish_default_key_bindings ^/dev/null
|
2016-05-08 23:27:15 +00:00
|
|
|
else
|
|
|
|
eval $fish_key_bindings ^/dev/null
|
|
|
|
end
|
|
|
|
# Load user key bindings if they are defined
|
|
|
|
if functions --query fish_user_key_bindings >/dev/null
|
2016-05-22 17:54:11 +00:00
|
|
|
fish_user_key_bindings ^/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
|
|
|
|
|
|
|
# Repaint screen when window changes size
|
|
|
|
function __fish_winch_handler --on-signal WINCH
|
|
|
|
commandline -f repaint
|
|
|
|
end
|
|
|
|
|
2016-09-11 03:28:06 +00:00
|
|
|
# Notify terminals when $PWD changes (issue #906)
|
2016-05-08 23:27:15 +00:00
|
|
|
if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal"
|
2016-09-11 03:28:06 +00:00
|
|
|
function __update_cwd_osc --on-variable PWD --description 'Notify VTE of change to $PWD'
|
2016-05-08 23:27:15 +00:00
|
|
|
status --is-command-substitution
|
|
|
|
and return
|
2016-09-11 03:28:06 +00:00
|
|
|
printf \e\]7\;file://\%s\%s\a (hostname) (pwd | __fish_urlencode)
|
2016-05-08 23:27:15 +00:00
|
|
|
end
|
2016-09-11 03:28:06 +00:00
|
|
|
__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
|
|
|
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-12 20:59:35 +00: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 | \
|
|
|
|
string replace -r '^ID(?:_LIKE)?\s*=(.*)' '$1' | string trim -c '\'"')
|
|
|
|
end
|
|
|
|
|
2016-05-08 23:27:15 +00:00
|
|
|
# First check if we are on OpenSUSE since SUSE's handler has no options
|
2016-09-12 20:59:35 +00:00
|
|
|
# but the same name and path as Ubuntu's.
|
|
|
|
if contains -- suse $os
|
2016-05-08 23:27:15 +00:00
|
|
|
and type -q -p command-not-found
|
|
|
|
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
|
|
|
|
else if type -q -p command-not-found
|
|
|
|
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
|
|
|
|
set -l __packages (pkgfile --binaries --verbose -- $argv[1] ^/dev/null)
|
|
|
|
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-09-30 22:53:54 +00:00
|
|
|
end
|