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
# Migrate old (pre 1.22.0) init scripts if they exist
if not set -q __fish_init_1_22_0
if test -f ~/.fish_history -o -f ~/.fish -o -d ~/.fish.d -a ! -d $configdir /fish
# Perform upgrade of configuration file hierarchy
if not test -d $configdir
command mkdir $configdir > /dev/null
end
if test -d $configdir
2010-09-18 10:18:26 +08:00
if command mkdir $configdir /fish
2007-08-20 00:42:30 +08:00
# These files are sometimes overwritten to by fish, so
# we want backups of them in case something goes wrong
cp ~/.fishd.( hostname ) $configdir /fish /fishd.( hostname ) .backup
cp ~/.fish_history $configdir /fish /fish_history.backup
# Move the files
mv ~/.fish_history $configdir /fish /fish_history
mv ~/.fish $configdir /fish /config.fish
mv ~/.fish_inputrc $configdir /fish /fish_inputrc
mv ~/.fish.d/functions $configdir /fish /functions
mv ~/.fish.d/completions $configdir /fish /completions
#
# Move the fishd stuff from another shell to avoid concurrency problems
#
2010-09-18 10:18:26 +08:00
2007-08-20 00:42:30 +08:00
/bin/sh -c mv\ \~ /.fishd.( hostname ) \ $configdir /fish /fishd.( hostname ) \; kill \ -9 \ ( echo %fishd )
# Update paths to point to new configuration locations
set fish_function_path ( printf "%s\n" $fish_function_path | sed -e "s|/usr/local/etc/fish.d/|/usr/local/etc/fish/|" )
set fish_complete_path ( printf "%s\n" $fish_complete_path | sed -e "s|/usr/local/etc/fish.d/|/usr/local/etc/fish/|" )
set fish_function_path ( printf "%s\n" $fish_function_path | sed -e " s| $HOME /.fish.d/| $configdir /fish/| " )
set fish_complete_path ( printf "%s\n" $fish_complete_path | sed -e " s| $HOME /.fish.d/| $configdir /fish/| " )
printf ( _ "\nWARNING\n\nThe location for fish configuration files has changed to %s.\nYour old files have been moved to this location.\nYou can change to a different location by changing the value of the variable \$XDG_CONFIG_HOME.\n\n" ) $configdir
end ^ /dev/null
end
end
# Make sure this is only done once
set -U __fish_init_1_22_0
2010-09-18 10:18:26 +08:00
2007-08-20 00:42:30 +08:00
end
#
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
2008-01-08 23:27:08 +08:00
if not set -q __fish_init_1_23_0
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
set -U __fish_init_1_23_0
2007-08-20 00:42:30 +08:00
2008-01-09 00:18:56 +08:00
#
# Set various defaults using these throwaway functions
#
2007-08-20 00:42:30 +08:00
2008-01-09 00:18:56 +08:00
function set_default -d "Set a universal variable, unless it has already been set"
if not set -q $argv [ 1 ]
2010-09-18 10:18:26 +08:00
set -U -- $argv
2008-01-09 00:18:56 +08:00
end
end
2007-08-20 00:42:30 +08:00
2008-01-09 00:18:56 +08:00
# Regular syntax highlighting colors
set_default fish_color_normal normal
set_default fish_color_command green
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-02-13 10:05:59 +08:00
set_default fish_color_autosuggestion 555
2008-01-09 00:18:56 +08:00
set_default fish_color_valid_path --underline
2007-08-20 00:42:30 +08:00
2008-01-09 00:18:56 +08:00
set_default fish_color_cwd green
set_default 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
set_default 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
2012-02-07 12:14:19 +08:00
set_default fish_color_search_match --background = purple
2007-08-20 00:42:30 +08:00
2008-01-09 00:18:56 +08:00
# Pager colors
set_default fish_pager_color_prefix cyan
set_default fish_pager_color_completion normal
set_default fish_pager_color_description normal
set_default 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
2008-01-09 00:18:56 +08:00
set_default fish_color_history_current cyan
2007-08-20 00:42:30 +08:00
2008-01-09 00:18:56 +08:00
#
# Setup the CDPATH variable
#
2007-08-20 00:42:30 +08:00
2008-01-09 00:18:56 +08:00
set_default CDPATH . ~
2007-08-20 00:42:30 +08:00
2008-01-09 00:18:56 +08:00
#
# Remove temporary functions for setting default variable values
#
functions -e set_default
2010-09-18 10:18:26 +08:00
2008-01-09 00:18:56 +08:00
end
2007-08-20 00:42:30 +08:00
#
2010-09-18 10:18:26 +08:00
# Print a greeting
2007-08-20 00:42:30 +08:00
#
2009-02-17 05:04:50 +08:00
if functions -q fish_greeting
fish_greeting
else
if set -q fish_greeting
2010-11-24 00:49:15 +08:00
switch " $fish_greeting "
2009-02-17 05:04:50 +08:00
case ''
# If variable is empty, don't print anything, saves us a fork
2010-09-18 10:18:26 +08:00
2009-02-17 05:04:50 +08:00
case '*'
echo $fish_greeting
end
2008-01-13 02:53:19 +08:00
end
2008-01-09 00:18:56 +08:00
end
2007-08-20 00:42:30 +08:00
#
2008-01-09 00:18:56 +08:00
# Set exit message
2007-08-20 00:42:30 +08:00
#
2008-01-09 00:18:56 +08:00
function fish_on_exit --description "Commands to execute when fish exits" --on-process %self
2008-01-13 02:40:42 +08:00
printf ( _ "Goodbye\n" )
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
2008-01-15 06:58:28 +08:00
# Reload keybindings when binding variable change
2007-10-01 06:55:57 +08:00
function __fish_reload_key_bindings -d "Reload keybindings when binding variable change" --on-variable fish_key_bindings
2007-10-31 17:15:03 +08:00
eval $fish_key_bindings ^ /dev/null
2010-09-18 10:18:26 +08:00
end
2007-09-29 05:37:41 +08:00
2008-01-15 06:58:28 +08:00
# Load keybindings
2008-01-15 08:40:50 +08:00
__fish_reload_key_bindings
2008-01-15 06:58:28 +08:00
# Repaint screen when window changes size
2007-10-01 06:53:54 +08:00
function __fish_winch_handler --on-signal winch
commandline -f repaint
end
2007-09-26 00:14:47 +08:00
2008-01-15 06:58:28 +08:00
# If the ubuntu command-not-found package can be found, add a handler for it
2008-01-15 20:29:53 +08:00
# First check in /usr/lib, this is where modern Ubuntus place this command
2010-09-18 10:18:26 +08:00
if test -f /usr/lib/command -not-found
2008-01-15 06:31:24 +08:00
function fish_command_not_found_handler --on-event fish_command_not_found
/usr/lib/command -not-found $argv
2008-01-15 06:58:28 +08:00
end
2010-09-18 10:18:26 +08:00
else
2008-01-15 20:29:53 +08:00
# Ubuntu Feisty places this command in the regular path instead
if type -p command -not-found > /dev/null
function fish_command_not_found_handler --on-event fish_command_not_found
command -not-found $argv
end
end
2008-01-15 06:31:24 +08:00
end
2007-10-01 06:53:54 +08:00
end
2007-09-26 00:14:47 +08:00