fix the style of several functions

I'm going to modify these functions as part of dealing with issue #3000
and don't want those changes to be masked by running the files through
`make style`.
This commit is contained in:
Kurtis Rader 2016-05-08 16:27:15 -07:00
parent 0d1d324e9f
commit 3626c39398
3 changed files with 403 additions and 377 deletions

View file

@ -1,83 +1,106 @@
# Initializations that should only be performed when entering #
# interactive mode. # Initializations that should only be performed when entering interactive mode.
#
# This function is called by the __fish_on_interactive function, which # This function is called by the __fish_on_interactive function, which is defined in config.fish.
# is defined in config.fish. #
function __fish_config_interactive -d "Initializations that should be performed when entering interactive mode" function __fish_config_interactive -d "Initializations that should be performed when entering interactive mode"
# Make sure this function is only run once # Make sure this function is only run once
if set -q __fish_config_interactive_done if set -q __fish_config_interactive_done
return return
end end
set -g __fish_config_interactive_done set -g __fish_config_interactive_done
# Set the correct configuration directory # Set the correct configuration directory
set -l configdir ~/.config set -l configdir ~/.config
if set -q XDG_CONFIG_HOME if set -q XDG_CONFIG_HOME
set configdir $XDG_CONFIG_HOME set configdir $XDG_CONFIG_HOME
end end
# Set the correct user data directory # Set the correct user data directory
set -l userdatadir ~/.local/share set -l userdatadir ~/.local/share
if set -q XDG_DATA_HOME if set -q XDG_DATA_HOME
set userdatadir $XDG_DATA_HOME set userdatadir $XDG_DATA_HOME
end end
# #
# If we are starting up for the first time, set various defaults # If we are starting up for the first time, set various defaults
# #
if not set -q __fish_init_1_50_0 if not set -q __fish_init_1_50_0
if not set -q fish_greeting if not set -q fish_greeting
set -l line1 (printf (_ 'Welcome to fish, the friendly interactive shell') ) 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 -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 set -U fish_greeting $line1\n$line2
end end
set -U __fish_init_1_50_0 set -U __fish_init_1_50_0
# Regular syntax highlighting colors # Regular syntax highlighting colors
set -q fish_color_normal; or set -U fish_color_normal normal set -q fish_color_normal
set -q fish_color_command; or set -U fish_color_command 005fd7 purple or set -U fish_color_normal normal
set -q fish_color_param; or set -U fish_color_param 00afff cyan set -q fish_color_command
set -q fish_color_redirection; or set -U fish_color_redirection normal or set -U fish_color_command 005fd7 purple
set -q fish_color_comment; or set -U fish_color_comment red set -q fish_color_param
set -q fish_color_error; or set -U fish_color_error red --bold or set -U fish_color_param 00afff cyan
set -q fish_color_escape; or set -U fish_color_escape cyan set -q fish_color_redirection
set -q fish_color_operator; or set -U fish_color_operator cyan or set -U fish_color_redirection normal
set -q fish_color_end; or set -U fish_color_end green set -q fish_color_comment
set -q fish_color_quote; or set -U fish_color_quote brown or set -U fish_color_comment red
set -q fish_color_autosuggestion; or set -U fish_color_autosuggestion 555 yellow set -q fish_color_error
set -q fish_color_user; or set -U fish_color_user green 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_end
or set -U fish_color_end green
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_user
or set -U fish_color_user green
set -q fish_color_host; or set -U fish_color_host normal set -q fish_color_host
set -q fish_color_valid_path; or set -U fish_color_valid_path --underline 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
set -q fish_color_cwd_root; or set -U fish_color_cwd_root red 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 # Background color for matching quotes and parenthesis
set -q fish_color_match; or set -U fish_color_match cyan set -q fish_color_match
or set -U fish_color_match cyan
# Background color for search matches # Background color for search matches
set -q fish_color_search_match; or set -U fish_color_search_match --background=purple set -q fish_color_search_match
or set -U fish_color_search_match --background=purple
# Background color for selections # Background color for selections
set -q fish_color_selection; or set -U fish_color_selection --background=purple set -q fish_color_selection
or set -U fish_color_selection --background=purple
# Pager colors # Pager colors
set -q fish_pager_color_prefix; or set -U fish_pager_color_prefix cyan set -q fish_pager_color_prefix
set -q fish_pager_color_completion; or set -U fish_pager_color_completion normal or set -U fish_pager_color_prefix cyan
set -q fish_pager_color_description 555; or set -U fish_pager_color_description 555 yellow set -q fish_pager_color_completion
set -q fish_pager_color_progress; or set -U fish_pager_color_progress cyan 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
# #
# Directory history colors # Directory history colors
# #
set -q fish_color_history_current; or set -U fish_color_history_current cyan set -q fish_color_history_current
end or set -U fish_color_history_current cyan
end
# #
# Generate man page completions if not present # Generate man page completions if not present
@ -88,207 +111,210 @@ function __fish_config_interactive -d "Initializations that should be performed
eval "$__fish_bin_dir/fish -c 'fish_update_completions > /dev/null ^/dev/null' &" eval "$__fish_bin_dir/fish -c 'fish_update_completions > /dev/null ^/dev/null' &"
end end
# #
# Print a greeting # Print a greeting
# fish_greeting can be a function (preferred) or a variable # fish_greeting can be a function (preferred) or a variable
# #
if functions -q fish_greeting if functions -q fish_greeting
fish_greeting fish_greeting
else else
# The greeting used to be skipped when fish_greeting was empty (not just undefined) # 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 # Keep it that way to not print superfluous newlines on old configuration
test -n "$fish_greeting"; and echo $fish_greeting test -n "$fish_greeting"
end and echo $fish_greeting
end
# #
# This event handler makes sure the prompt is repainted when # This event handler makes sure the prompt is repainted when
# fish_color_cwd changes value. Like all event handlers, it can't be # fish_color_cwd changes value. Like all event handlers, it can't be
# autoloaded. # autoloaded.
# #
function __fish_repaint --on-variable fish_color_cwd --description "Event handler, repaints the prompt when fish_color_cwd changes" function __fish_repaint --on-variable fish_color_cwd --description "Event handler, repaints the prompt when fish_color_cwd changes"
if status --is-interactive if status --is-interactive
set -e __fish_prompt_cwd set -e __fish_prompt_cwd
commandline -f repaint ^/dev/null commandline -f repaint ^/dev/null
end end
end end
function __fish_repaint_root --on-variable fish_color_cwd_root --description "Event handler, repaints the prompt when fish_color_cwd_root changes" 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 if status --is-interactive
set -e __fish_prompt_cwd set -e __fish_prompt_cwd
commandline -f repaint ^/dev/null commandline -f repaint ^/dev/null
end end
end end
# #
# Completions for SysV startup scripts. These aren't bound to any # Completions for SysV startup scripts. These aren't bound to any
# specific command, so they can't be autoloaded. # specific command, so they can't be autoloaded.
# #
complete -x -p "/etc/init.d/*" -a start --description 'Start service' 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 stop --description 'Stop service'
complete -x -p "/etc/init.d/*" -a status --description 'Print service status' 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 restart --description 'Stop and then start service'
complete -x -p "/etc/init.d/*" -a reload --description 'Reload service configuration' complete -x -p "/etc/init.d/*" -a reload --description 'Reload service configuration'
# Make sure some key bindings are set # Make sure some key bindings are set
if not set -q fish_key_bindings if not set -q fish_key_bindings
set -U fish_key_bindings fish_default_key_bindings set -U fish_key_bindings fish_default_key_bindings
end end
# Reload key bindings when binding variable change # 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 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 # do nothing if the key bindings didn't actually change
# This could be because the variable was set to the existing value # This could be because the variable was set to the existing value
# or because it was a local variable # or because it was a local variable
if test "$fish_key_bindings" = "$__fish_active_key_bindings" if test "$fish_key_bindings" = "$__fish_active_key_bindings"
return return
end end
set -g __fish_active_key_bindings "$fish_key_bindings" set -g __fish_active_key_bindings "$fish_key_bindings"
set -g fish_bind_mode default set -g fish_bind_mode default
if test "$fish_key_bindings" = fish_default_key_bindings if test "$fish_key_bindings" = fish_default_key_bindings
fish_default_key_bindings fish_default_key_bindings
else else
eval $fish_key_bindings ^/dev/null eval $fish_key_bindings ^/dev/null
end end
# Load user key bindings if they are defined # Load user key bindings if they are defined
if functions --query fish_user_key_bindings > /dev/null if functions --query fish_user_key_bindings >/dev/null
fish_user_key_bindings fish_user_key_bindings
end end
end end
# Load key bindings. Redirect stderr per #1155 # Load key bindings. Redirect stderr per #1155
set -g __fish_active_key_bindings set -g __fish_active_key_bindings
__fish_reload_key_bindings ^ /dev/null __fish_reload_key_bindings ^/dev/null
# Repaint screen when window changes size # Repaint screen when window changes size
function __fish_winch_handler --on-signal WINCH function __fish_winch_handler --on-signal WINCH
commandline -f repaint commandline -f repaint
end end
# Notify vte-based terminals when $PWD changes (issue #906) # Notify vte-based terminals when $PWD changes (issue #906)
if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal" if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal"
function __update_vte_cwd --on-variable PWD --description 'Notify VTE of change to $PWD' function __update_vte_cwd --on-variable PWD --description 'Notify VTE of change to $PWD'
status --is-command-substitution; and return status --is-command-substitution
printf '\033]7;file://%s%s\a' (hostname) (pwd | __fish_urlencode) and return
end printf '\033]7;file://%s%s\a' (hostname) (pwd | __fish_urlencode)
__update_vte_cwd # Run once because we might have already inherited a PWD from an old tab end
end __update_vte_cwd # Run once because we might have already inherited a PWD from an old tab
end
### Command-not-found handlers ### Command-not-found handlers
# This can be overridden by defining a new __fish_command_not_found_handler function # This can be overridden by defining a new __fish_command_not_found_handler function
if not type -q __fish_command_not_found_handler if not type -q __fish_command_not_found_handler
# First check if we are on OpenSUSE since SUSE's handler has no options # 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 # and expects first argument to be a command and second database
# also check if there is command-not-found command. # also check if there is command-not-found command.
if test -f /etc/SuSE-release; and type -q -p command-not-found if test -f /etc/SuSE-release
function __fish_command_not_found_handler --on-event fish_command_not_found and type -q -p command-not-found
/usr/bin/command-not-found $argv[1] function __fish_command_not_found_handler --on-event fish_command_not_found
end /usr/bin/command-not-found $argv[1]
# Check for Fedora's handler end
else if test -f /usr/libexec/pk-command-not-found # Check for Fedora's handler
function __fish_command_not_found_handler --on-event fish_command_not_found else if test -f /usr/libexec/pk-command-not-found
/usr/libexec/pk-command-not-found $argv[1] function __fish_command_not_found_handler --on-event fish_command_not_found
end /usr/libexec/pk-command-not-found $argv[1]
# Check in /usr/lib, this is where modern Ubuntus place this command end
else if test -f /usr/lib/command-not-found # Check in /usr/lib, this is where modern Ubuntus place this command
function __fish_command_not_found_handler --on-event fish_command_not_found else if test -f /usr/lib/command-not-found
/usr/lib/command-not-found -- $argv[1] function __fish_command_not_found_handler --on-event fish_command_not_found
end /usr/lib/command-not-found -- $argv[1]
# Check for NixOS handler end
else if test -f /run/current-system/sw/bin/command-not-found # Check for NixOS handler
function __fish_command_not_found_handler --on-event fish_command_not_found else if test -f /run/current-system/sw/bin/command-not-found
/run/current-system/sw/bin/command-not-found $argv function __fish_command_not_found_handler --on-event fish_command_not_found
end /run/current-system/sw/bin/command-not-found $argv
# Ubuntu Feisty places this command in the regular path instead end
else if type -q -p command-not-found # Ubuntu Feisty places this command in the regular path instead
function __fish_command_not_found_handler --on-event fish_command_not_found else if type -q -p command-not-found
command-not-found -- $argv[1] function __fish_command_not_found_handler --on-event fish_command_not_found
end command-not-found -- $argv[1]
# pkgfile is an optional, but official, package on Arch Linux end
# it ships with example handlers for bash and zsh, so we'll follow that format # pkgfile is an optional, but official, package on Arch Linux
else if type -p -q pkgfile # it ships with example handlers for bash and zsh, so we'll follow that format
function __fish_command_not_found_handler --on-event fish_command_not_found else if type -p -q pkgfile
set -l __packages (pkgfile --binaries --verbose -- $argv[1] ^/dev/null) function __fish_command_not_found_handler --on-event fish_command_not_found
if test $status -eq 0 set -l __packages (pkgfile --binaries --verbose -- $argv[1] ^/dev/null)
printf "%s may be found in the following packages:\n" "$argv[1]" if test $status -eq 0
printf " %s\n" $__packages printf "%s may be found in the following packages:\n" "$argv[1]"
else printf " %s\n" $__packages
__fish_default_command_not_found_handler $argv[1] else
end __fish_default_command_not_found_handler $argv[1]
end end
# Use standard fish command not found handler otherwise end
else # Use standard fish command not found handler otherwise
function __fish_command_not_found_handler --on-event fish_command_not_found else
__fish_default_command_not_found_handler $argv[1] function __fish_command_not_found_handler --on-event fish_command_not_found
end __fish_default_command_not_found_handler $argv[1]
end end
end end
end
if test $TERM = "linux" # A linux in-kernel VT with 8 colors and 256/512 glyphs if test $TERM = "linux" # A linux in-kernel VT with 8 colors and 256/512 glyphs
# In a VT we have # In a VT we have
# black (invisible) # black (invisible)
# red # red
# green # green
# yellow # yellow
# blue # blue
# magenta # magenta
# cyan # cyan
# white # white
# Pretty much just set at random # Pretty much just set at random
set -g fish_color_normal normal set -g fish_color_normal normal
set -g fish_color_command yellow set -g fish_color_command yellow
set -g fish_color_param cyan set -g fish_color_param cyan
set -g fish_color_redirection normal set -g fish_color_redirection normal
set -g fish_color_comment red set -g fish_color_comment red
set -g fish_color_error red set -g fish_color_error red
set -g fish_color_escape cyan set -g fish_color_escape cyan
set -g fish_color_operator cyan set -g fish_color_operator cyan
set -g fish_color_quote blue set -g fish_color_quote blue
set -g fish_color_autosuggestion yellow set -g fish_color_autosuggestion yellow
set -g fish_color_valid_path set -g fish_color_valid_path
set -g fish_color_cwd green set -g fish_color_cwd green
set -g fish_color_cwd_root red set -g fish_color_cwd_root red
set -g fish_color_match cyan set -g fish_color_match cyan
set -g fish_color_history_current cyan set -g fish_color_history_current cyan
set -g fish_color_search_match cyan set -g fish_color_search_match cyan
set -g fish_color_selection blue set -g fish_color_selection blue
set -g fish_color_end yellow set -g fish_color_end yellow
set -g fish_color_host normal set -g fish_color_host normal
set -g fish_color_status red set -g fish_color_status red
set -g fish_color_user green set -g fish_color_user green
set -g fish_pager_color_prefix cyan set -g fish_pager_color_prefix cyan
set -g fish_pager_color_completion normal set -g fish_pager_color_completion normal
set -g fish_pager_color_description yellow set -g fish_pager_color_description yellow
set -g fish_pager_color_progress cyan set -g fish_pager_color_progress cyan
# Don't allow setting color other than what linux offers (see #2001) # Don't allow setting color other than what linux offers (see #2001)
functions -e set_color functions -e set_color
function set_color function set_color
set -l term_colors black red green yellow blue magenta cyan white normal set -l term_colors black red green yellow blue magenta cyan white normal
for a in $argv for a in $argv
if not contains -- $a $term_colors if not contains -- $a $term_colors
switch $a switch $a
# Also allow options # Also allow options
case "-*" case "-*"
continue continue
case "*" case "*"
echo "Color not valid in TERM = linux: $a" echo "Color not valid in TERM = linux: $a"
return 1 return 1
end end
end end
end end
builtin set_color $argv builtin set_color $argv
return $status return $status
end end
# Set fish_prompt to a VT-friendly version # Set fish_prompt to a VT-friendly version
# without color or unicode # without color or unicode
function fish_prompt function fish_prompt
fish_fallback_prompt fish_fallback_prompt
end end
end end
end end

View file

@ -15,7 +15,7 @@ function cd --description "Change directory"
return $status return $status
end end
# Avoid set completions # Avoid set completions.
set -l previous $PWD set -l previous $PWD
if test "$argv" = "-" if test "$argv" = "-"
@ -31,7 +31,8 @@ function cd --description "Change directory"
set -l cd_status $status set -l cd_status $status
if test $cd_status -eq 0 -a "$PWD" != "$previous" if test $cd_status -eq 0 -a "$PWD" != "$previous"
set -q dirprev[$MAX_DIR_HIST]; and set -e dirprev[1] set -q dirprev[$MAX_DIR_HIST]
and set -e dirprev[1]
set -g dirprev $dirprev $previous set -g dirprev $dirprev $previous
set -e dirnext set -e dirnext
set -g __fish_cd_direction prev set -g __fish_cd_direction prev

View file

@ -1,147 +1,146 @@
# #
#Deletes an item from history #Deletes an item from history
# #
function history --description "Deletes an item from history" function history --description "Deletes an item from history"
set -l argc (count $argv) set -l argc (count $argv)
set -l prefix_args "" set -l prefix_args ""
set -l contains_args "" set -l contains_args ""
set -l cmd print set -l cmd print
set -l search_mode none set -l search_mode none
set -l pager less set -l pager less
if set -q PAGER if set -q PAGER
set pager $PAGER set pager $PAGER
end end
if test $argc -gt 0 if test $argc -gt 0
for i in (seq $argc) for i in (seq $argc)
switch $argv[$i] switch $argv[$i]
case --delete case --delete
set cmd delete set cmd delete
case --prefix case --prefix
set search_mode prefix set search_mode prefix
set prefix_args $argv[(math $i + 1)] set prefix_args $argv[(math $i + 1)]
case --contains case --contains
set search_mode contains set search_mode contains
set contains_args $argv[(math $i + 1)] set contains_args $argv[(math $i + 1)]
case --save case --save
set cmd save set cmd save
case --clear case --clear
set cmd clear set cmd clear
case --search case --search
set cmd print set cmd print
case --merge case --merge
set cmd merge set cmd merge
case --help case --help
set cmd help set cmd help
case -- case --
set -e argv[$i] set -e argv[$i]
break break
case "-*" "--*" case "-*" "--*"
printf ( _ "%s: invalid option -- %s\n" ) history $argv[1] >& 2 printf ( _ "%s: invalid option -- %s\n" ) history $argv[1] >&2
return 1 return 1
end end
end end
else else
#Execute history builtin without any argument #Execute history builtin without any argument
if status --is-interactive if status --is-interactive
builtin history | eval $pager builtin history | eval $pager
else else
builtin history builtin history
end end
return return
end end
switch $cmd switch $cmd
case print case print
# Print matching items # Print matching items
# Note this may end up passing --search twice to the builtin, # Note this may end up passing --search twice to the builtin,
# but that's harmless # but that's harmless
builtin history --search $argv builtin history --search $argv
case delete case delete
# Interactively delete history # Interactively delete history
set -l found_items "" set -l found_items ""
switch $search_mode switch $search_mode
case prefix case prefix
set found_items (builtin history --search --prefix $prefix_args) set found_items (builtin history --search --prefix $prefix_args)
case contains case contains
set found_items (builtin history --search --contains $contains_args) set found_items (builtin history --search --contains $contains_args)
case none case none
builtin history $argv builtin history $argv
#Save changes after deleting item #Save changes after deleting item
builtin history --save builtin history --save
return 0 return 0
end end
set found_items_count (count $found_items) set found_items_count (count $found_items)
if test $found_items_count -gt 0 if test $found_items_count -gt 0
echo "[0] cancel" echo "[0] cancel"
echo "[1] all" echo "[1] all"
echo echo
for i in (seq $found_items_count) for i in (seq $found_items_count)
printf "[%s] %s \n" (math $i + 1) $found_items[$i] printf "[%s] %s \n" (math $i + 1) $found_items[$i]
end end
read --local --prompt "echo 'Delete which entries? > '" choice read --local --prompt "echo 'Delete which entries? > '" choice
set choice (string split " " -- $choice) set choice (string split " " -- $choice)
for i in $choice for i in $choice
# Skip empty input, for example, if the user just hits return # Skip empty input, for example, if the user just hits return
if test -z $i if test -z $i
continue continue
end end
#Following two validations could be embedded with "and" but I find the syntax kind of weird. #Following two validations could be embedded with "and" but I find the syntax kind of weird.
if not string match -qr '^[0-9]+$' $i if not string match -qr '^[0-9]+$' $i
printf "Invalid input: %s\n" $i printf "Invalid input: %s\n" $i
continue continue
end end
if test $i -gt (math $found_items_count + 1) if test $i -gt (math $found_items_count + 1)
printf "Invalid input : %s\n" $i printf "Invalid input : %s\n" $i
continue continue
end end
if test $i = "0" if test $i = "0"
printf "Cancel\n" printf "Cancel\n"
return return
else else
if test $i = "1" if test $i = "1"
for item in $found_items for item in $found_items
builtin history --delete $item builtin history --delete $item
end end
printf "Deleted all!\n" printf "Deleted all!\n"
else else
builtin history --delete $found_items[(math $i - 1)] builtin history --delete $found_items[(math $i - 1)]
end end
end end
end end
#Save changes after deleting item(s) #Save changes after deleting item(s)
builtin history --save builtin history --save
end end
case save case save
#Save changes to history file #Save changes to history file
builtin history $argv builtin history $argv
case merge case merge
builtin history --merge builtin history --merge
case help case help
builtin history --help builtin history --help
case clear case clear
# Erase the entire history # Erase the entire history
echo "Are you sure you want to clear history ? (y/n)" echo "Are you sure you want to clear history ? (y/n)"
read ch read ch
if test $ch = "y" if test $ch = "y"
builtin history $argv builtin history $argv
echo "History cleared!" echo "History cleared!"
end end
end end
end end