2006-10-19 11:50:23 +00:00
#
# Initializations that should only be performed when in interactive mode.
#
#
# @configure_input@
#
set -l configdir ~/.config
if set -q XDG_CONFIG_HOME
set configdir $XDG_CONFIG_HOME
end
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
2006-12-14 12:06:30 +00:00
command mkdir $configdir > /dev/null
2006-10-19 11:50:23 +00:00
end
if test -d $configdir
2006-12-14 12:06:30 +00:00
if command mkdir $configdir /fish
2006-10-19 11:50:23 +00:00
# These files are sometimes overwritten to by fish, so
# we want backups of them in case something goes wrong
2006-10-25 20:33:37 +00:00
cp ~/.fishd.( hostname ) $configdir /fish /fishd.( hostname ) .backup
2006-10-19 11:50:23 +00:00
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
#
/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|@sysconfdir@/fish.d/|@sysconfdir@/fish/|" )
set fish_complete_path ( printf "%s\n" $fish_complete_path | sed -e "s|@sysconfdir@/fish.d/|@sysconfdir@/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/| " )
2006-10-22 15:57:59 +00:00
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
2006-10-19 11:50:23 +00:00
end ^ /dev/null
end
end
# Make sure this is only done once
set -U __fish_init_1_22_0
end
#
# Print a greeting
#
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
2006-11-07 13:06:29 +00:00
if test " $fish_greeting "
echo $fish_greeting
end
2006-10-19 11:50:23 +00:00
#
# Set exit message
#
2007-01-27 02:02:40 +00:00
function fish_on_exit --description "Commands to execute when fish exits" --on-process %self
2006-10-19 11:50:23 +00:00
printf ( _ "Good bye\n" )
end
#
# Set INPUTRC to something nice
#
# We override INPUTRC if already set, since it may be set by a shell
# other than fish, which may use a different file. The new value should
# be exported, since the fish inputrc file plays nice with other files
# by including them when found.
#
2006-11-03 15:53:35 +00:00
for i in $configdir /fish /fish_inputrc @sysconfdir@/fish /fish_inputrc ~/.inputrc /etc/inputrc
2006-10-19 11:50:23 +00:00
if test -f $i
set -xg INPUTRC $i
break
end
end
#
# Set various defaults using these throwaway functions
#
function set_default -d "Set an universal variable, unless it has already been set"
if not set -q $argv [ 1 ]
set -U -- $argv
end
end
# 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
set_default fish_color_valid_path --underline
set_default fish_color_cwd green
# Background color for matching quotes and parenthesis
set_default fish_color_match cyan
# Background color for search matches
set_default fish_color_search_match purple
# 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
#
# Directory history colors
#
set_default fish_color_history_current cyan
#
# Setup the CDPATH variable
#
set_default CDPATH . ~
#
# Remove temporary functions for setting default variable values
#
functions -e set_default
2006-11-18 21:21:47 +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.
#
2007-01-27 02:02:40 +00:00
function __fish_repaint --on-variable fish_color_cwd --description "Event handler, repaints the prompt when fish_color_cwd changes"
2007-08-01 18:09:01 +00:00
if status --is-interactive
set -e __fish_prompt_cwd
commandline -f repaint ^ /dev/null
end
2006-11-18 21:21:47 +00:00
end
2006-10-19 11:50:23 +00:00
#
# A few minor convenience functions
#
# The naming heuristic is that __fish_complete_* prints completions
# and descriptions, while __fish_print_* only prints the completions
# and no descriptions
#
2007-01-27 02:02:40 +00:00
function __fish_complete_users --description "Print a list of local users, with the real user name as a description"
2006-10-19 11:50:23 +00:00
cat /etc/passwd | sed -e "s/^\([^:]*\):[^:]*:[^:]*:[^:]*:\([^:]*\):.*/\1\t\2/"
end
2007-01-27 02:02:40 +00:00
function __fish_complete_groups --description "Print a list of local groups, with group members as the description"
2006-10-19 11:50:23 +00:00
cat /etc/group | sed -e "s/^\([^:]*\):[^:]*:[^:]*:\(.*\)/\1\tMembers: \2/"
end
2007-01-27 02:02:40 +00:00
function __fish_complete_command --description "Complete using all available commands"
2006-10-19 11:50:23 +00:00
printf "%s\n" ( commandline -ct ) ( complete -C ( commandline -ct ) )
end
2007-01-27 02:02:40 +00:00
function __fish_print_interfaces --description "Print a list of known network interfaces"
2006-10-19 11:50:23 +00:00
netstat -i -n -a | awk 'NR>2' | awk '{print $1}'
end
2007-01-27 02:02:40 +00:00
function __fish_print_addresses --description "Print a list of known network addresses"
2006-11-29 14:00:04 +00:00
/sbin/ifconfig | sgrep 'inet addr' | cut -d : -f 2 | cut -d ' ' -f 1
2006-10-19 11:50:23 +00:00
end
2007-01-27 02:02:40 +00:00
function __fish_print_users --description "Print a list of local users"
2006-10-19 11:50:23 +00:00
cat /etc/passwd | cut -d : -f 1
end
#
# Completions for SysV startup scripts
#
2007-01-27 02:02:40 +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'
2006-10-19 11:50:23 +00:00