2007-09-22 04:52:12 +08:00
|
|
|
# Initializations that should only be performed when entering
|
|
|
|
# interactive mode.
|
2007-08-20 00:42:30 +08:00
|
|
|
|
2007-09-22 04:52:12 +08:00
|
|
|
# This function is called by the __fish_on_interactive function, which
|
|
|
|
# is defined in config.fish.
|
2007-08-20 00:42:30 +08:00
|
|
|
|
|
|
|
function __fish_config_interactive -d "Initializations that should be performed when entering interactive mode"
|
|
|
|
|
|
|
|
|
|
|
|
# Make sure this function is only run once
|
|
|
|
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
|
2014-09-29 19:39:36 +08:00
|
|
|
# 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-20 00:42:30 +08:00
|
|
|
|
|
|
|
#
|
2008-01-09 00:18:56 +08:00
|
|
|
# If we are starting up for the first time, set various defaults
|
2010-09-18 10:18:26 +08:00
|
|
|
#
|
2008-01-09 00:18:56 +08:00
|
|
|
|
2012-06-05 16:01:30 +08:00
|
|
|
if not set -q __fish_init_1_50_0
|
2008-01-08 23:27:08 +08:00
|
|
|
if not set -q fish_greeting
|
|
|
|
set -l line1 (printf (_ 'Welcome to fish, the friendly interactive shell') )
|
|
|
|
set -l line2 (printf (_ 'Type %shelp%s for instructions on how to use fish') (set_color green) (set_color normal))
|
|
|
|
set -U fish_greeting $line1\n$line2
|
|
|
|
end
|
2012-06-22 11:20:23 +08:00
|
|
|
set -U __fish_init_1_50_0
|
2007-08-20 00:42:30 +08:00
|
|
|
|
2008-01-09 00:18:56 +08:00
|
|
|
# Regular syntax highlighting colors
|
2015-12-30 19:47:41 +08:00
|
|
|
set -q fish_color_normal; or set -U fish_color_normal normal
|
|
|
|
set -q fish_color_command; or set -U fish_color_command 005fd7 purple
|
|
|
|
set -q fish_color_param; or set -U fish_color_param 00afff cyan
|
|
|
|
set -q fish_color_redirection; or set -U fish_color_redirection normal
|
|
|
|
set -q fish_color_comment; or set -U fish_color_comment red
|
|
|
|
set -q fish_color_error; or set -U fish_color_error red --bold
|
|
|
|
set -q fish_color_escape; or set -U fish_color_escape cyan
|
|
|
|
set -q fish_color_operator; or set -U fish_color_operator cyan
|
|
|
|
set -q fish_color_quote; or set -U fish_color_quote brown
|
|
|
|
set -q fish_color_autosuggestion; or set -U fish_color_autosuggestion 555 yellow
|
|
|
|
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
|
2007-08-20 00:42:30 +08:00
|
|
|
|
2008-01-09 00:18:56 +08:00
|
|
|
# Background color for matching quotes and parenthesis
|
2015-12-30 19:47:41 +08:00
|
|
|
set -q fish_color_match; or set -U fish_color_match cyan
|
2007-08-20 00:42:30 +08:00
|
|
|
|
2008-01-09 00:18:56 +08:00
|
|
|
# Background color for search matches
|
2015-12-30 19:47:41 +08:00
|
|
|
set -q fish_color_search_match; or set -U fish_color_search_match --background=purple
|
2007-08-20 00:42:30 +08:00
|
|
|
|
2014-01-16 05:41:10 +08:00
|
|
|
# Background color for selections
|
2015-12-30 19:47:41 +08:00
|
|
|
set -q fish_color_selection; or set -U fish_color_selection --background=purple
|
2014-01-16 05:41:10 +08:00
|
|
|
|
2008-01-09 00:18:56 +08:00
|
|
|
# Pager colors
|
2015-12-30 19:47:41 +08:00
|
|
|
set -q fish_pager_color_prefix; or set -U fish_pager_color_prefix cyan
|
|
|
|
set -q fish_pager_color_completion; or set -U fish_pager_color_completion normal
|
|
|
|
set -q fish_pager_color_description 555; or set -U fish_pager_color_description 555 yellow
|
|
|
|
set -q fish_pager_color_progress; or set -U fish_pager_color_progress cyan
|
2007-08-20 00:42:30 +08:00
|
|
|
|
2008-01-09 00:18:56 +08:00
|
|
|
#
|
|
|
|
# Directory history colors
|
|
|
|
#
|
2007-08-20 00:42:30 +08:00
|
|
|
|
2015-12-30 19:47:41 +08:00
|
|
|
set -q fish_color_history_current; or set -U fish_color_history_current cyan
|
2008-01-09 00:18:56 +08:00
|
|
|
end
|
2007-08-20 00:42:30 +08:00
|
|
|
|
2013-11-11 23:44:24 +08:00
|
|
|
#
|
|
|
|
# Generate man page completions if not present
|
|
|
|
#
|
|
|
|
|
2014-09-29 19:39:36 +08:00
|
|
|
if not test -d $userdatadir/fish/generated_completions
|
2013-11-09 13:59:10 +08:00
|
|
|
#fish_update_completions is a function, so it can not be directly run in background.
|
2013-11-17 18:54:00 +08:00
|
|
|
eval "$__fish_bin_dir/fish -c 'fish_update_completions > /dev/null ^/dev/null' &"
|
2013-11-09 13:59:10 +08:00
|
|
|
end
|
|
|
|
|
2015-12-29 22:58:48 +08:00
|
|
|
#
|
|
|
|
# Print a greeting
|
|
|
|
# fish_greeting can be a function (preferred) or a variable
|
|
|
|
#
|
2010-09-18 10:18:26 +08:00
|
|
|
|
2015-12-29 22:58:48 +08:00
|
|
|
if functions -q fish_greeting
|
|
|
|
fish_greeting
|
|
|
|
else
|
|
|
|
set -q fish_greeting; and echo $fish_greeting
|
2008-01-09 00:18:56 +08:00
|
|
|
end
|
2007-08-20 00:42:30 +08:00
|
|
|
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#
|
2010-09-18 10:18:26 +08:00
|
|
|
# Completions for SysV startup scripts. These aren't bound to any
|
2007-09-22 04:52:12 +08:00
|
|
|
# specific command, so they can't be autoloaded.
|
2007-08-20 00:42:30 +08:00
|
|
|
#
|
|
|
|
|
|
|
|
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'
|
2007-09-26 00:14:47 +08:00
|
|
|
|
2008-01-15 06:58:28 +08:00
|
|
|
# Make sure some key bindings are set
|
2007-09-26 00:14:47 +08:00
|
|
|
if not set -q fish_key_bindings
|
|
|
|
set -U fish_key_bindings fish_default_key_bindings
|
|
|
|
end
|
2010-09-18 10:18:26 +08:00
|
|
|
|
2012-10-19 04:56:08 +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
|
2014-09-19 06:45:07 +08:00
|
|
|
# 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
|
|
|
|
if test "$fish_key_bindings" = "$__fish_active_key_bindings"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
set -g __fish_active_key_bindings "$fish_key_bindings"
|
|
|
|
set -g fish_bind_mode default
|
2012-10-19 13:41:34 +08:00
|
|
|
if test "$fish_key_bindings" = fish_default_key_bindings
|
2012-04-25 01:10:43 +08:00
|
|
|
fish_default_key_bindings
|
|
|
|
else
|
|
|
|
eval $fish_key_bindings ^/dev/null
|
|
|
|
end
|
2015-09-01 17:50:50 +08:00
|
|
|
# Load user key bindings if they are defined
|
|
|
|
if functions --query fish_user_key_bindings > /dev/null
|
|
|
|
fish_user_key_bindings
|
|
|
|
end
|
2010-09-18 10:18:26 +08:00
|
|
|
end
|
2007-09-29 05:37:41 +08:00
|
|
|
|
2014-02-04 08:46:01 +08:00
|
|
|
# Load key bindings. Redirect stderr per #1155
|
2014-10-03 03:14:22 +08:00
|
|
|
set -g __fish_active_key_bindings
|
2014-02-04 08:46:01 +08:00
|
|
|
__fish_reload_key_bindings ^ /dev/null
|
2008-01-15 06:58:28 +08:00
|
|
|
|
|
|
|
# Repaint screen when window changes size
|
2015-07-24 03:21:41 +08:00
|
|
|
function __fish_winch_handler --on-signal WINCH
|
2007-10-01 06:53:54 +08:00
|
|
|
commandline -f repaint
|
|
|
|
end
|
2007-09-26 00:14:47 +08:00
|
|
|
|
2013-08-24 16:52:00 +08:00
|
|
|
|
|
|
|
# Notify vte-based terminals when $PWD changes (issue #906)
|
2014-11-20 14:45:07 +08:00
|
|
|
if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal"
|
2013-08-24 16:52:00 +08:00
|
|
|
function __update_vte_cwd --on-variable PWD --description 'Notify VTE of change to $PWD'
|
|
|
|
status --is-command-substitution; and return
|
2014-11-20 14:45:07 +08:00
|
|
|
printf '\033]7;file://%s%s\a' (hostname) (pwd | __fish_urlencode)
|
2013-08-24 16:52:00 +08:00
|
|
|
end
|
2015-12-12 19:22:08 +08:00
|
|
|
__update_vte_cwd # Run once because we might have already inherited a PWD from an old tab
|
2013-08-24 16:52:00 +08:00
|
|
|
end
|
|
|
|
|
2015-12-29 22:41:00 +08:00
|
|
|
### 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
|
2014-02-02 21:39:17 +08:00
|
|
|
# First check if we are on OpenSUSE since SUSE's handler has no options
|
|
|
|
# and expects first argument to be a command and second database
|
|
|
|
# also check if there is command-not-found command.
|
2015-12-29 22:41:00 +08:00
|
|
|
if test -f /etc/SuSE-release; and type -q -p command-not-found
|
2014-02-02 21:39:17 +08:00
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2015-04-20 17:22:54 +08:00
|
|
|
/usr/bin/command-not-found $argv[1]
|
2014-02-02 21:39:17 +08:00
|
|
|
end
|
2015-12-29 22:41:00 +08:00
|
|
|
# Check for Fedora's handler
|
2014-02-02 21:39:17 +08:00
|
|
|
else if test -f /usr/libexec/pk-command-not-found
|
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2015-04-20 17:22:54 +08:00
|
|
|
/usr/libexec/pk-command-not-found $argv[1]
|
2014-02-02 21:39:17 +08:00
|
|
|
end
|
2015-12-29 22:41:00 +08:00
|
|
|
# Check in /usr/lib, this is where modern Ubuntus place this command
|
2014-02-02 21:39:17 +08:00
|
|
|
else if test -f /usr/lib/command-not-found
|
2013-09-12 17:02:05 +08:00
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2015-04-20 17:22:54 +08:00
|
|
|
/usr/lib/command-not-found -- $argv[1]
|
2012-12-12 08:00:49 +08:00
|
|
|
end
|
2015-12-29 22:41:00 +08:00
|
|
|
# Check for NixOS handler
|
2014-12-07 20:33:40 +08:00
|
|
|
else if test -f /run/current-system/sw/bin/command-not-found
|
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2016-01-03 21:05:39 +08:00
|
|
|
/run/current-system/sw/bin/command-not-found $argv
|
2014-12-07 20:33:40 +08:00
|
|
|
end
|
2015-12-29 22:41:00 +08:00
|
|
|
# Ubuntu Feisty places this command in the regular path instead
|
2014-07-10 15:26:58 +08:00
|
|
|
else if type -q -p command-not-found
|
2013-09-12 17:02:05 +08:00
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2015-04-20 17:22:54 +08:00
|
|
|
command-not-found -- $argv[1]
|
2013-07-19 15:56:47 +08:00
|
|
|
end
|
2015-12-29 22:41:00 +08:00
|
|
|
# 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
|
2015-01-31 13:01:40 +08:00
|
|
|
else if type -p -q pkgfile
|
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2015-04-20 17:22:54 +08:00
|
|
|
set -l __packages (pkgfile --binaries --verbose -- $argv[1] ^/dev/null)
|
2015-01-31 13:01:40 +08:00
|
|
|
if test $status -eq 0
|
2015-04-20 17:22:54 +08:00
|
|
|
printf "%s may be found in the following packages:\n" "$argv[1]"
|
2015-01-31 13:01:40 +08:00
|
|
|
printf " %s\n" $__packages
|
|
|
|
else
|
2015-04-20 17:22:54 +08:00
|
|
|
__fish_default_command_not_found_handler $argv[1]
|
2015-01-31 13:01:40 +08:00
|
|
|
end
|
|
|
|
end
|
2015-12-29 22:41:00 +08:00
|
|
|
# Use standard fish command not found handler otherwise
|
2012-12-12 08:00:49 +08:00
|
|
|
else
|
2013-09-12 17:02:05 +08:00
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2015-04-20 17:22:54 +08:00
|
|
|
__fish_default_command_not_found_handler $argv[1]
|
2008-01-15 20:29:53 +08:00
|
|
|
end
|
|
|
|
end
|
2008-01-15 06:31:24 +08:00
|
|
|
end
|
2015-12-29 22:41:00 +08:00
|
|
|
|
2015-08-17 23:32:45 +08:00
|
|
|
if test $TERM = "linux" # A linux in-kernel VT with 8 colors and 256/512 glyphs
|
|
|
|
# In a VT we have
|
|
|
|
# black (invisible)
|
|
|
|
# red
|
|
|
|
# green
|
|
|
|
# yellow
|
|
|
|
# blue
|
|
|
|
# magenta
|
|
|
|
# cyan
|
|
|
|
# white
|
|
|
|
|
|
|
|
# Pretty much just set at random
|
|
|
|
set -g fish_color_normal normal
|
|
|
|
set -g fish_color_command yellow
|
|
|
|
set -g fish_color_param cyan
|
|
|
|
set -g fish_color_redirection normal
|
|
|
|
set -g fish_color_comment red
|
|
|
|
set -g fish_color_error red
|
|
|
|
set -g fish_color_escape cyan
|
|
|
|
set -g fish_color_operator cyan
|
|
|
|
set -g fish_color_quote blue
|
|
|
|
set -g fish_color_autosuggestion yellow
|
|
|
|
set -g fish_color_valid_path
|
|
|
|
set -g fish_color_cwd green
|
|
|
|
set -g fish_color_cwd_root red
|
|
|
|
set -g fish_color_match cyan
|
|
|
|
set -g fish_color_history_current cyan
|
|
|
|
set -g fish_color_search_match cyan
|
|
|
|
set -g fish_color_selection blue
|
|
|
|
set -g fish_color_end yellow
|
|
|
|
set -g fish_color_host normal
|
|
|
|
set -g fish_color_status red
|
|
|
|
set -g fish_color_user green
|
|
|
|
set -g fish_pager_color_prefix cyan
|
|
|
|
set -g fish_pager_color_completion normal
|
|
|
|
set -g fish_pager_color_description yellow
|
|
|
|
set -g fish_pager_color_progress cyan
|
|
|
|
|
|
|
|
# Don't allow setting color other than what linux offers (see #2001)
|
|
|
|
functions -e set_color
|
|
|
|
function set_color
|
2015-09-10 21:12:02 +08:00
|
|
|
set -l term_colors black red green yellow blue magenta cyan white normal
|
2015-08-17 23:32:45 +08:00
|
|
|
for a in $argv
|
|
|
|
if not contains -- $a $term_colors
|
2015-09-10 21:12:02 +08:00
|
|
|
switch $a
|
|
|
|
# Also allow options
|
|
|
|
case "-*"
|
|
|
|
continue
|
|
|
|
case "*"
|
|
|
|
echo "Color not valid in TERM = linux: $a"
|
|
|
|
return 1
|
|
|
|
end
|
2015-08-17 23:32:45 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
builtin set_color $argv
|
|
|
|
return $status
|
|
|
|
end
|
|
|
|
|
|
|
|
# Set fish_prompt to a VT-friendly version
|
|
|
|
# without color or unicode
|
|
|
|
function fish_prompt
|
|
|
|
fish_fallback_prompt
|
|
|
|
end
|
|
|
|
end
|
2015-10-20 23:02:32 +08:00
|
|
|
|
|
|
|
if begin set -q KONSOLE_PROFILE_NAME # KDE's konsole
|
|
|
|
or string match -q -- "*:*" $ITERM_SESSION_ID # Supporting versions of iTerm2 will include a colon here
|
|
|
|
or string match -q -- "st-*" $TERM # suckless' st
|
|
|
|
or test "$VTE_VERSION" -ge 3600 # Should be all gtk3-vte-based terms after version 3.6.0.0
|
|
|
|
or test "$COLORTERM" = truecolor -o "$COLORTERM" = 24bit # slang expects this
|
|
|
|
end
|
|
|
|
set -g fish_term24bit 1
|
|
|
|
end
|
2007-10-01 06:53:54 +08:00
|
|
|
end
|