reformat all fish scripts

I hate doing this but I am tired of touching a fish script as part of
some change and having `make style` radically change it. Which makes
editing fish scripts more painful than it needs to be. It is time to do
a wholesale reformatting of these scripts to conform to the documented
style as implemented by the `fish_indent` program.
This commit is contained in:
Kurtis Rader 2016-11-27 21:27:22 -08:00
parent 54a76bb9e5
commit 11a60c8374
161 changed files with 2638 additions and 2587 deletions

View file

@ -8,7 +8,8 @@ function __fish_complete_ant_targets -d "Print list of targets from build.xml an
set files (sed -n "s/^.*<import[^>]* file=[\"']\([^\"']*\)[\"'].*\$/\1/p" < $buildfile)
# iterate through files and display their targets
for file in $files;
for file in $files
__fish_filter_ant_targets $file
end
end

View file

@ -4,11 +4,13 @@ function __fish_complete_cd -d "Completions for the cd command"
if string match -qr '^\.?\.?/.*' -- $token
for d in $token*/
# Check if it's accessible - the glob only matches directories
[ -x $d ]; and printf "%s\n" $d
[ -x $d ]
and printf "%s\n" $d
end
else # Relative path - check $CDPATH and use that as description
set -l cdpath $CDPATH
[ -z "$cdpath" ]; and set cdpath "."
[ -z "$cdpath" ]
and set cdpath "."
# Remove the real path to "." (i.e. $PWD) from cdpath if we're in it
# so it doesn't get printed in the descriptions
if set -l ind (contains -i -- $PWD $cdpath)
@ -21,11 +23,13 @@ function __fish_complete_cd -d "Completions for the cd command"
set -l desc
# Don't show description for current directory
# and replace $HOME with "~"
[ $i = "." ]; or set -l desc (string replace -r -- "^$HOME" "~" "$i")
[ $i = "." ]
or set -l desc (string replace -r -- "^$HOME" "~" "$i")
# This assumes the CDPATH component itself is cd-able
for d in $i/$token*/
# Remove the cdpath component again
[ -x $d ]; and printf "%s\t%s\n" (string replace -r "^$i/" "" -- $d) $desc
[ -x $d ]
and printf "%s\t%s\n" (string replace -r "^$i/" "" -- $d) $desc
end
end
end

View file

@ -234,7 +234,8 @@ function __fish_config_interactive -d "Initializations that should be performed
# Suppress duplicative title display on Terminal.app
if not functions -q fish_title
echo -n \e\]0\;\a # clear existing title
function fish_title -d 'no-op terminal title'; end
function fish_title -d 'no-op terminal title'
end
end
end
__update_cwd_osc # Run once because we might have already inherited a PWD from an old tab

View file

@ -484,7 +484,8 @@ function __fish_git_prompt_informative_status
# If `math` fails for some reason, assume the state is clean - it's the simpler path
set -l state (math $dirtystate + $invalidstate + $stagedstate + $untrackedfiles ^/dev/null)
if test -z "$state"; or test "$state" = 0
if test -z "$state"
or test "$state" = 0
set info $___fish_git_prompt_color_cleanstate$___fish_git_prompt_char_cleanstate$___fish_git_prompt_color_cleanstate_done
else
for i in $___fish_git_prompt_status_order

View file

@ -69,12 +69,18 @@ function __fish_hg_prompt --description 'Write out the hg prompt'
# Add a character for each file status if we have one
switch $line
case 'A ' ; set hg_statuses $hg_statuses added
case 'M ' ' M' ; set hg_statuses $hg_statuses modified
case 'C ' ; set hg_statuses $hg_statuses copied
case 'D ' ' D' ; set hg_statuses $hg_statuses deleted
case '\? ' ; set hg_statuses $hg_statuses untracked
case 'U*' '*U' 'DD' 'AA'; set hg_statuses $hg_statuses unmerged
case 'A '
set hg_statuses $hg_statuses added
case 'M ' ' M'
set hg_statuses $hg_statuses modified
case 'C '
set hg_statuses $hg_statuses copied
case 'D ' ' D'
set hg_statuses $hg_statuses deleted
case '\? '
set hg_statuses $hg_statuses untracked
case 'U*' '*U' 'DD' 'AA'
set hg_statuses $hg_statuses unmerged
end
end

View file

@ -7,7 +7,8 @@ function __fish_is_first_token -d 'Test if no non-switch argument has been speci
case '-*'
case '*'
return 1;
return 1
end
end
return 0

View file

@ -11,7 +11,8 @@ function __fish_make_completion_signals --description 'Make list of kill signals
# The procps `kill -L` produces a more compact table. We can distinguish the two cases by
# testing whether it supports `kill -t`; in which case it is the coreutils `kill` command.
# Darwin doesn't have kill -t or kill -L
if kill -t ^/dev/null >/dev/null; or not kill -L ^/dev/null >/dev/null
if kill -t ^/dev/null >/dev/null
or not kill -L ^/dev/null >/dev/null
# Posix systems print out the name of a signal using 'kill -l SIGNUM'.
complete -c kill -s l --description "List names of available signals"
for i in (seq 31)

View file

@ -4,16 +4,14 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
# Print all hosts from /etc/hosts
# use 'getent hosts' on OSes that support it (OpenBSD and Cygwin do not)
if type -q getent; and getent hosts > /dev/null 2>&1 # test if 'getent hosts' works and redirect output so errors don't print
if type -q getent
and getent hosts >/dev/null 2>&1 # test if 'getent hosts' works and redirect output so errors don't print
# Ignore zero ips
getent hosts | string match -r -v '^0.0.0.0' \
| string replace -r '[0-9.]*\s*' '' | string split " "
getent hosts | string match -r -v '^0.0.0.0' | string replace -r '[0-9.]*\s*' '' | string split " "
else if test -r /etc/hosts
# Ignore commented lines and functionally empty lines
string match -r -v '^\s*0.0.0.0|^\s*#|^\s*$' < /etc/hosts \
# Strip comments
| string replace -ra '#.*$' '' \
| string replace -r '[0-9.]*\s*' '' | string trim | string replace -ra '\s+' '\n'
string match -r -v '^\s*0.0.0.0|^\s*#|^\s*$' </etc/hosts # Strip comments
| string replace -ra '#.*$' '' | string replace -r '[0-9.]*\s*' '' | string trim | string replace -ra '\s+' '\n'
end
# Print nfs servers from /etc/fstab
@ -27,15 +25,15 @@ function __fish_print_hostnames -d "Print a list of known hostnames"
if test -r $file
# Print hosts from system wide ssh configuration file
# Note the non-capturing group to avoid printing "name"
string match -ri '\s*Host(?:name)?(?:\s+|\s*=\s*)\w.*' < $file | string replace -ri '^\s*Host(?:name)?\s*(\S+)' '$1' \
| string replace -r '\s+' ' ' | string split ' '
string match -ri '\s*Host(?:name)?(?:\s+|\s*=\s*)\w.*' <$file | string replace -ri '^\s*Host(?:name)?\s*(\S+)' '$1' | string replace -r '\s+' ' ' | string split ' '
set known_hosts $known_hosts (string match -ri '^\s*UserKnownHostsFile|^\s*GlobalKnownHostsFile' < $file \
| string replace -ri '.*KnownHostsFile\s*' '')
end
end
for file in $known_hosts
# Ignore hosts that are hashed, commented or have custom ports (like [localhost]:2200)
test -r $file; and string replace -ra '(\S+) .*' '$1' < $file | string match -r '^[^#|[=]+$' | string split ","
test -r $file
and string replace -ra '(\S+) .*' '$1' <$file | string match -r '^[^#|[=]+$' | string split ","
end
return 0
end

View file

@ -5,8 +5,7 @@ function __fish_print_mounted --description 'Print mounted devices'
# \011 encodes a tab, \012 encodes a newline and \\ encodes a backslash
# This will probably break on newlines because of our splitting, though
# and tabs because of descriptions
string replace -r '\S+ (\S+) .*' '$1' </etc/mtab | string replace -a "\040" " " \
| string replace -a "\011" \t | string replace -a "\012" \n | string replace -a "\\\\" "\\"
string replace -r '\S+ (\S+) .*' '$1' </etc/mtab | string replace -a "\040" " " | string replace -a "\011" \t | string replace -a "\012" \n | string replace -a "\\\\" "\\"
else
mount | cut -d " " -f 1-3 | tr " " \n | sed -e "s/[0-9\.]*:\//\//" | __fish_sgrep "^/"
end

View file

@ -97,7 +97,8 @@ function __fish_svn_prompt --description "Prompt function for svn"
# make sure that this is a svn repo
set -l checkout_info (command svn info ^/dev/null)
if [ $status -ne 0 ];
if [ $status -ne 0 ]
return
end
@ -122,7 +123,8 @@ function __fish_svn_prompt --description "Prompt function for svn"
set -l column_status (printf '%s\n' $svn_status_lines | cut -c $col | tr -d ' \n')
# check that the character count is not zero (this would indicate that there are status flags in this column)
if [ (count $column_status) -ne 0 ];
if [ (count $column_status) -ne 0 ]
# we only want to display unique status flags (eg: if there are 5 modified files, the prompt should only show the modified status once)
set -l column_unique_status (echo $column_status | sort | uniq)
# parse the status flags for this column and create the formatting by calling out to the helper function

View file

@ -1,5 +1,7 @@
# Like for running machines, I'm assuming machinectl doesn't allow spaces in image names
# This does not include the special image ".host" since it isn't valid for most operations
function __fish_systemd_machine_images
machinectl --no-legend --no-pager list-images | while read -l a b; echo $a; end
machinectl --no-legend --no-pager list-images | while read -l a b
echo $a
end
end

View file

@ -1,4 +1,6 @@
# It seems machinectl will eliminate spaces from machine names so we don't need to handle that
function __fish_systemd_machines
machinectl --no-legend --no-pager list --all | while read -l a b; echo $a; end
machinectl --no-legend --no-pager list --all | while read -l a b
echo $a
end
end

View file

@ -13,5 +13,6 @@ function __fish_toggle_comment_commandline --description 'Comment/uncomment the
end
set -l cmdlines (printf '%s\n' '#'$cmdlines | string replace -r '^##' '')
commandline -r $cmdlines
string match -q '#*' $cmdlines[1]; and commandline -f execute
string match -q '#*' $cmdlines[1]
and commandline -f execute
end

View file

@ -2,7 +2,11 @@ function __fish_urlencode --description "URL-encode stdin"
set -l join ''
set -l chars
# Set locale to C and IFS to "" in order to split a line into bytes.
while begin; set -lx LC_ALL C; set -lx IFS ''; read -az chars; end
while begin
set -lx LC_ALL C
set -lx IFS ''
read -az chars
end
printf '%s' $join
# chomp off a trailing newline
if test "$chars[-1]" = \n

View file

@ -51,13 +51,20 @@ function __terlar_git_prompt --description 'Write out the git prompt'
end
switch $i
case 'A ' ; set gs $gs added
case 'M ' ' M' ; set gs $gs modified
case 'R ' ; set gs $gs renamed
case 'C ' ; set gs $gs copied
case 'D ' ' D' ; set gs $gs deleted
case '\?\?' ; set gs $gs untracked
case 'U*' '*U' 'DD' 'AA'; set gs $gs unmerged
case 'A '
set gs $gs added
case 'M ' ' M'
set gs $gs modified
case 'R '
set gs $gs renamed
case 'C '
set gs $gs copied
case 'D ' ' D'
set gs $gs deleted
case '\?\?'
set gs $gs untracked
case 'U*' '*U' 'DD' 'AA'
set gs $gs unmerged
end
end

View file

@ -74,12 +74,14 @@ function abbr --description "Manage abbreviations"
case 'add'
# Convert from old "key=value" syntax
# TODO: This should be removed later
if not set -q mode_arg[2]; and string match -qr '^[^ ]+=' -- $mode_arg
if not set -q mode_arg[2]
and string match -qr '^[^ ]+=' -- $mode_arg
set mode_arg (string split "=" -- $mode_arg)
end
# Bail out early if the exact abbr is already in
contains -- "$mode_arg" $fish_user_abbreviations; and return 0
contains -- "$mode_arg" $fish_user_abbreviations
and return 0
set -l key $mode_arg[1]
set -e mode_arg[1]
set -l value "$mode_arg"
@ -122,7 +124,8 @@ function abbr --description "Manage abbreviations"
# Check to see if either key or value has a leading dash
# If so, we need to write --
string match -q -- '-*' $key $value; and set opt_double_dash '--'
string match -q -- '-*' $key $value
and set opt_double_dash '--'
echo abbr $opt_double_dash (string escape -- $key $value)
end
return 0

View file

@ -69,7 +69,10 @@ function funced --description 'Edit function definition'
set editor fish
end
if begin; set -q interactive[1]; or test "$editor" = fish; end
if begin
set -q interactive[1]
or test "$editor" = fish
end
set -l IFS
if functions -q -- $funcname
# Shadow IFS here to avoid array splitting in command substitution
@ -89,7 +92,8 @@ function funced --description 'Edit function definition'
# OSX mktemp is rather restricted - no suffix, no way to automatically use TMPDIR
# Create a directory so we can use a ".fish" suffix for the file - makes editors pick up that it's a fish file
set -q TMPDIR; or set -l TMPDIR /tmp
set -q TMPDIR
or set -l TMPDIR /tmp
set -l tmpdir (mktemp -d $TMPDIR/fish.XXXXXX)
set -l tmpname $tmpdir/$funcname.fish

View file

@ -7,7 +7,8 @@ function man --description "Format and display the on-line manual pages"
# Notice local but exported variable
set -lx MANPATH (string join : $MANPATH)
if test -z "$MANPATH"
type -q manpath; and set MANPATH (command manpath)
type -q manpath
and set MANPATH (command manpath)
end
set -l fish_manpath (dirname $__fish_datadir)/fish/man
if test -d "$fish_manpath" -a -n "$MANPATH"

View file

@ -38,7 +38,8 @@ function nextd --description "Move forward in the directory history"
if count $times >/dev/null
for i in (seq $times)
# Try one step backward
if __fish_move_last dirnext dirprev;
if __fish_move_last dirnext dirprev
# We consider it a success if we were able to do at least 1 step
# (low expectations are the key to happiness ;)
set code 0

View file

@ -38,7 +38,8 @@ function prevd --description "Move back in the directory history"
if count $times >/dev/null
for i in (seq $times)
# Try one step backward
if __fish_move_last dirprev dirnext;
if __fish_move_last dirprev dirnext
# We consider it a success if we were able to do at least 1 step
# (low expectations are the key to happiness ;)
set code 0

View file

@ -1,12 +1,14 @@
function prompt_pwd --description "Print the current working directory, shortened to fit the prompt"
set -q argv[1]; and switch $argv[1]
set -q argv[1]
and switch $argv[1]
case -h --help
__fish_print_help prompt_pwd
return 0
end
# This allows overriding fish_prompt_pwd_dir_length from the outside (global or universal) without leaking it
set -q fish_prompt_pwd_dir_length; or set -l fish_prompt_pwd_dir_length 1
set -q fish_prompt_pwd_dir_length
or set -l fish_prompt_pwd_dir_length 1
# Replace $HOME with "~"
set realhome ~

View file

@ -60,7 +60,8 @@ function psub --description "Read from stdin into a file and output the filename
# Write output to pipe. This needs to be done in the background so
# that the command substitution exits without needing to wait for
# all the commands to exit
set dirname (mktemp -d "$TMPDIR[1]"/.psub.XXXXXXXXXX); or return
set dirname (mktemp -d "$TMPDIR[1]"/.psub.XXXXXXXXXX)
or return
set filename $dirname/psub.fifo"$suffix"
mkfifo $filename
cat >$filename &
@ -78,9 +79,11 @@ function psub --description "Read from stdin into a file and output the filename
# Find unique function name
while true
set funcname __fish_psub_(random);
set funcname __fish_psub_(random)
if not functions $funcname >/dev/null ^/dev/null
break;
break
end
end

View file

@ -1,5 +1,6 @@
function suspend -d "Suspend the current shell."
if contains -- $argv --help; or contains -- $argv -h
if contains -- $argv --help
or contains -- $argv -h
__fish_print_help suspend
and return 0
end

View file

@ -143,7 +143,10 @@ function type --description "Print the type of a command"
end
end
if begin; test $found = 0; and test $mode != quiet; end
if begin
test $found = 0
and test $mode != quiet
end
printf (_ "%s: Could not find '%s'\n") type $i >&2
end

View file

@ -3,7 +3,9 @@ function __fish_umask_parse -d "Internal umask function"
# Test if already a valid octal mask, and pad it with zeros
if echo $argv | __fish_sgrep -E '^0?[0-7]{1,3}$' >/dev/null
set -l char_count (echo $argv| wc -c)
for i in (seq (math 5 - $char_count)); set argv 0$argv; end
for i in (seq (math 5 - $char_count))
set argv 0$argv
end
echo $argv
else
# Test if argument really is a valid symbolic mask