2007-09-21 20:52:12 +00:00
|
|
|
# Initializations that should only be performed when entering
|
|
|
|
# interactive mode.
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2007-09-21 20:52:12 +00:00
|
|
|
# This function is called by the __fish_on_interactive function, which
|
|
|
|
# is defined in config.fish.
|
2007-08-19 16:42:30 +00: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 11:39:36 +00: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-19 16:42:30 +00:00
|
|
|
|
|
|
|
#
|
2008-01-08 16:18:56 +00:00
|
|
|
# If we are starting up for the first time, set various defaults
|
2010-09-18 02:18:26 +00:00
|
|
|
#
|
2008-01-08 16:18:56 +00:00
|
|
|
|
2012-06-05 08:01:30 +00:00
|
|
|
if not set -q __fish_init_1_50_0
|
2008-01-08 15:27:08 +00: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 03:20:23 +00:00
|
|
|
set -U __fish_init_1_50_0
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
#
|
|
|
|
# Set various defaults using these throwaway functions
|
|
|
|
#
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
function set_default -d "Set a universal variable, unless it has already been set"
|
|
|
|
if not set -q $argv[1]
|
2010-09-18 02:18:26 +00:00
|
|
|
set -U -- $argv
|
2008-01-08 16:18:56 +00:00
|
|
|
end
|
|
|
|
end
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
# Regular syntax highlighting colors
|
|
|
|
set_default fish_color_normal normal
|
2012-06-05 08:01:30 +00:00
|
|
|
set_default fish_color_command 005fd7 purple
|
|
|
|
set_default fish_color_param 00afff cyan
|
2008-01-08 16:18:56 +00:00
|
|
|
set_default fish_color_redirection normal
|
|
|
|
set_default fish_color_comment red
|
|
|
|
set_default fish_color_error red --bold
|
|
|
|
set_default fish_color_escape cyan
|
|
|
|
set_default fish_color_operator cyan
|
|
|
|
set_default fish_color_quote brown
|
2012-06-05 08:01:30 +00:00
|
|
|
set_default fish_color_autosuggestion 555 yellow
|
2008-01-08 16:18:56 +00:00
|
|
|
set_default fish_color_valid_path --underline
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
set_default fish_color_cwd green
|
|
|
|
set_default fish_color_cwd_root red
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
# Background color for matching quotes and parenthesis
|
|
|
|
set_default fish_color_match cyan
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
# Background color for search matches
|
2012-02-07 04:14:19 +00:00
|
|
|
set_default fish_color_search_match --background=purple
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2014-01-15 21:41:10 +00:00
|
|
|
# Background color for selections
|
|
|
|
set_default fish_color_selection --background=purple
|
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
# Pager colors
|
|
|
|
set_default fish_pager_color_prefix cyan
|
|
|
|
set_default fish_pager_color_completion normal
|
2012-11-18 11:17:51 +00:00
|
|
|
set_default fish_pager_color_description 555 yellow
|
2008-01-08 16:18:56 +00:00
|
|
|
set_default fish_pager_color_progress cyan
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
#
|
|
|
|
# Directory history colors
|
|
|
|
#
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
set_default fish_color_history_current cyan
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
#
|
|
|
|
# Remove temporary functions for setting default variable values
|
|
|
|
#
|
|
|
|
|
|
|
|
functions -e set_default
|
2010-09-18 02:18:26 +00:00
|
|
|
|
2008-01-08 16:18:56 +00:00
|
|
|
end
|
2007-08-19 16:42:30 +00:00
|
|
|
|
2013-11-11 15:44:24 +00:00
|
|
|
#
|
|
|
|
# Generate man page completions if not present
|
|
|
|
#
|
|
|
|
|
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.
|
2013-11-17 10:54:00 +00:00
|
|
|
eval "$__fish_bin_dir/fish -c 'fish_update_completions > /dev/null ^/dev/null' &"
|
2013-11-09 05:59:10 +00:00
|
|
|
end
|
|
|
|
|
2014-09-22 03:33:58 +00:00
|
|
|
if status -i
|
|
|
|
#
|
|
|
|
# Print a greeting
|
|
|
|
#
|
2010-09-18 02:18:26 +00:00
|
|
|
|
2014-09-22 03:33:58 +00:00
|
|
|
if functions -q fish_greeting
|
|
|
|
fish_greeting
|
|
|
|
else
|
|
|
|
if set -q fish_greeting
|
|
|
|
switch "$fish_greeting"
|
|
|
|
case ''
|
|
|
|
# If variable is empty, don't print anything, saves us a fork
|
|
|
|
|
|
|
|
case '*'
|
|
|
|
echo $fish_greeting
|
|
|
|
end
|
2009-02-16 21:04:50 +00:00
|
|
|
end
|
2008-01-12 18:53:19 +00:00
|
|
|
end
|
2008-01-08 16:18:56 +00:00
|
|
|
end
|
2007-08-19 16:42:30 +00: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 02:18:26 +00:00
|
|
|
# Completions for SysV startup scripts. These aren't bound to any
|
2007-09-21 20:52:12 +00:00
|
|
|
# specific command, so they can't be autoloaded.
|
2007-08-19 16:42:30 +00: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-25 16:14:47 +00:00
|
|
|
|
2008-01-14 22:58:28 +00:00
|
|
|
# Make sure some key bindings are set
|
2007-09-25 16:14:47 +00:00
|
|
|
if not set -q fish_key_bindings
|
|
|
|
set -U fish_key_bindings fish_default_key_bindings
|
|
|
|
end
|
2010-09-18 02:18:26 +00:00
|
|
|
|
2012-10-18 20:56:08 +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
|
2014-09-18 22:45:07 +00: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 05:41:34 +00:00
|
|
|
if test "$fish_key_bindings" = fish_default_key_bindings
|
2012-04-24 17:10:43 +00:00
|
|
|
fish_default_key_bindings
|
2014-10-02 19:14:22 +00:00
|
|
|
# Load user key bindings if they are defined
|
2012-10-19 05:37:22 +00:00
|
|
|
if functions --query fish_user_key_bindings > /dev/null
|
2012-10-19 05:41:34 +00:00
|
|
|
fish_user_key_bindings
|
2012-06-05 17:49:48 +00:00
|
|
|
end
|
2012-04-24 17:10:43 +00:00
|
|
|
else
|
|
|
|
eval $fish_key_bindings ^/dev/null
|
|
|
|
end
|
2010-09-18 02:18:26 +00:00
|
|
|
end
|
2007-09-28 21:37:41 +00:00
|
|
|
|
2014-02-04 00:46:01 +00:00
|
|
|
# Load key bindings. Redirect stderr per #1155
|
2014-10-02 19:14:22 +00:00
|
|
|
set -g __fish_active_key_bindings
|
2014-02-04 00:46:01 +00:00
|
|
|
__fish_reload_key_bindings ^ /dev/null
|
2008-01-14 22:58:28 +00:00
|
|
|
|
|
|
|
# Repaint screen when window changes size
|
2007-09-30 22:53:54 +00:00
|
|
|
function __fish_winch_handler --on-signal winch
|
|
|
|
commandline -f repaint
|
|
|
|
end
|
2007-09-25 16:14:47 +00:00
|
|
|
|
2013-08-24 08:52:00 +00:00
|
|
|
|
|
|
|
# Notify vte-based terminals when $PWD changes (issue #906)
|
2014-11-20 06:45:07 +00:00
|
|
|
if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal"
|
2013-08-24 08:52:00 +00:00
|
|
|
function __update_vte_cwd --on-variable PWD --description 'Notify VTE of change to $PWD'
|
|
|
|
status --is-command-substitution; and return
|
2014-11-20 06:45:07 +00:00
|
|
|
printf '\033]7;file://%s%s\a' (hostname) (pwd | __fish_urlencode)
|
2013-08-24 08:52:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-12-12 00:00:49 +00:00
|
|
|
# The first time a command is not found, look for command-not-found
|
|
|
|
# This is not cheap so we try to avoid doing it during startup
|
2014-02-20 18:26:57 +00:00
|
|
|
# config.fish already installed a handler for noninteractive command-not-found,
|
|
|
|
# so delete it here since we are now interactive
|
|
|
|
functions -e __fish_command_not_found_handler
|
|
|
|
|
|
|
|
# Now install our fancy variant
|
2013-09-12 09:02:05 +00:00
|
|
|
function __fish_command_not_found_setup --on-event fish_command_not_found
|
2012-12-12 00:00:49 +00:00
|
|
|
# Remove fish_command_not_found_setup so we only execute this once
|
2013-09-12 09:02:05 +00:00
|
|
|
functions --erase __fish_command_not_found_setup
|
2013-07-19 07:56:47 +00:00
|
|
|
|
2014-02-02 13:39:17 +00: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.
|
2014-07-10 07:26:58 +00:00
|
|
|
if begin; test -f /etc/SuSE-release; and type -q -p command-not-found; end
|
2014-02-02 13:39:17 +00:00
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
|
|
|
/usr/bin/command-not-found $argv
|
|
|
|
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
|
2015-01-18 10:52:15 +00:00
|
|
|
/usr/libexec/pk-command-not-found $argv
|
2014-02-02 13:39:17 +00:00
|
|
|
end
|
|
|
|
# Check in /usr/lib, this is where modern Ubuntus place this command
|
|
|
|
else if test -f /usr/lib/command-not-found
|
2013-09-12 09:02:05 +00:00
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2013-08-24 19:20:21 +00:00
|
|
|
/usr/lib/command-not-found -- $argv
|
2012-12-12 00:00:49 +00:00
|
|
|
end
|
2014-12-07 12:33:40 +00:00
|
|
|
# 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
|
2013-07-19 07:56:47 +00:00
|
|
|
# Ubuntu Feisty places this command in the regular path instead
|
2014-07-10 07:26:58 +00:00
|
|
|
else if type -q -p command-not-found
|
2013-09-12 09:02:05 +00:00
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2013-08-24 19:20:21 +00:00
|
|
|
command-not-found -- $argv
|
2013-07-19 07:56:47 +00:00
|
|
|
end
|
2015-01-31 05:01:40 +00: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
|
|
|
|
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 ^/dev/null)
|
|
|
|
if test $status -eq 0
|
|
|
|
printf "%s may be found in the following packages:\n" "$argv"
|
|
|
|
printf " %s\n" $__packages
|
|
|
|
else
|
|
|
|
__fish_default_command_not_found_handler $argv
|
|
|
|
end
|
|
|
|
end
|
2013-07-19 07:56:47 +00:00
|
|
|
# Use standard fish command not found handler otherwise
|
2012-12-12 00:00:49 +00:00
|
|
|
else
|
2013-09-12 09:02:05 +00:00
|
|
|
function __fish_command_not_found_handler --on-event fish_command_not_found
|
2014-02-20 18:26:57 +00:00
|
|
|
__fish_default_command_not_found_handler $argv
|
2008-01-15 12:29:53 +00:00
|
|
|
end
|
|
|
|
end
|
2013-09-12 09:02:05 +00:00
|
|
|
__fish_command_not_found_handler $argv
|
2008-01-14 22:31:24 +00:00
|
|
|
end
|
2007-09-30 22:53:54 +00:00
|
|
|
end
|