From 11a60c8374c21c299bab35ae12a30b54a44bc9e3 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Sun, 27 Nov 2016 21:27:22 -0800 Subject: [PATCH] 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. --- share/functions/N_.fish | 2 +- share/functions/__fish_append.fish | 6 +- share/functions/__fish_bind_test1.fish | 12 +- share/functions/__fish_bind_test2.fish | 26 +- share/functions/__fish_commandline_test.fish | 6 +- .../__fish_complete_abook_formats.fish | 6 +- .../__fish_complete_ant_targets.fish | 23 +- ..._fish_complete_atool_archive_contents.fish | 34 +- .../functions/__fish_complete_bittorrent.fish | 58 +-- share/functions/__fish_complete_cd.fish | 64 ++-- share/functions/__fish_complete_command.fish | 16 +- .../__fish_complete_convert_options.fish | 24 +- .../__fish_complete_directories.fish | 16 +- share/functions/__fish_complete_file_url.fish | 26 +- share/functions/__fish_complete_ftp.fish | 24 +- share/functions/__fish_complete_groups.fish | 10 +- share/functions/__fish_complete_list.fish | 42 +-- share/functions/__fish_complete_lpr.fish | 34 +- .../functions/__fish_complete_lpr_option.fish | 42 +-- share/functions/__fish_complete_lsusb.fish | 2 +- share/functions/__fish_complete_man.fish | 34 +- share/functions/__fish_complete_path.fish | 24 +- share/functions/__fish_complete_pgrep.fish | 4 +- share/functions/__fish_complete_pids.fish | 16 +- share/functions/__fish_complete_ppp_peer.fish | 2 +- share/functions/__fish_complete_proc.fish | 90 ++--- .../functions/__fish_complete_setxkbmap.fish | 2 +- share/functions/__fish_complete_ssh.fish | 20 +- .../functions/__fish_complete_subcommand.fish | 52 +-- .../__fish_complete_subcommand_root.fish | 4 +- share/functions/__fish_complete_suffix.fish | 62 ++-- share/functions/__fish_complete_svn_diff.fish | 42 +-- share/functions/__fish_complete_tar.fish | 52 +-- share/functions/__fish_complete_unrar.fish | 28 +- share/functions/__fish_complete_users.fish | 14 +- .../__fish_complete_wvdial_peers.fish | 46 +-- .../functions/__fish_config_interactive.fish | 3 +- share/functions/__fish_contains_opt.fish | 78 ++-- share/functions/__fish_crux_packages.fish | 2 +- share/functions/__fish_cursor_konsole.fish | 18 +- share/functions/__fish_cursor_xterm.fish | 26 +- share/functions/__fish_describe_command.fish | 2 +- .../functions/__fish_filter_ant_targets.fish | 2 +- share/functions/__fish_git_prompt.fish | 3 +- share/functions/__fish_gnu_complete.fish | 66 ++-- share/functions/__fish_hg_prompt.fish | 20 +- share/functions/__fish_is_first_token.fish | 21 +- share/functions/__fish_is_token_n.fish | 6 +- .../__fish_make_completion_signals.fish | 5 +- share/functions/__fish_man_page.fish | 4 +- share/functions/__fish_move_last.fish | 34 +- share/functions/__fish_no_arguments.fish | 20 +- share/functions/__fish_not_contain_opt.fish | 78 ++-- share/functions/__fish_paginate.fish | 14 +- share/functions/__fish_ports_dirs.fish | 2 +- .../functions/__fish_print_abook_emails.fish | 2 +- share/functions/__fish_print_addresses.fish | 16 +- .../functions/__fish_print_arch_daemons.fish | 2 +- .../__fish_print_debian_apache_confs.fish | 8 +- .../__fish_print_debian_apache_mods.fish | 8 +- .../__fish_print_debian_apache_sites.fish | 8 +- .../__fish_print_debian_services.fish | 8 +- share/functions/__fish_print_encodings.fish | 2 +- share/functions/__fish_print_filesystems.fish | 12 +- .../__fish_print_function_prototypes.fish | 2 +- share/functions/__fish_print_hostnames.fish | 72 ++-- share/functions/__fish_print_interfaces.fish | 16 +- share/functions/__fish_print_lpr_options.fish | 2 +- .../functions/__fish_print_lpr_printers.fish | 2 +- .../functions/__fish_print_lsblk_columns.fish | 2 +- .../functions/__fish_print_make_targets.fish | 22 +- share/functions/__fish_print_modules.fish | 2 +- share/functions/__fish_print_mounted.fish | 21 +- .../functions/__fish_print_ninja_targets.fish | 2 +- share/functions/__fish_print_packages.fish | 220 ++++++------ .../functions/__fish_print_pacman_repos.fish | 2 +- .../functions/__fish_print_service_names.fish | 12 +- share/functions/__fish_print_svn_rev.fish | 2 +- share/functions/__fish_print_users.fish | 14 +- .../functions/__fish_print_xdg_mimeapps.fish | 2 +- .../functions/__fish_print_xdg_mimetypes.fish | 2 +- .../functions/__fish_print_xrandr_modes.fish | 18 +- .../__fish_print_xrandr_outputs.fish | 2 +- share/functions/__fish_print_xwindows.fish | 2 +- share/functions/__fish_prt_no_subcommand.fish | 12 +- share/functions/__fish_prt_packages.fish | 2 +- share/functions/__fish_prt_ports.fish | 2 +- share/functions/__fish_prt_use_package.fish | 12 +- share/functions/__fish_prt_use_port.fish | 12 +- share/functions/__fish_pwd.fish | 16 +- share/functions/__fish_sgrep.fish | 4 +- .../functions/__fish_shared_key_bindings.fish | 2 +- share/functions/__fish_svn_prompt.fish | 128 +++---- .../__fish_systemctl_automounts.fish | 14 +- share/functions/__fish_systemctl_devices.fish | 18 +- share/functions/__fish_systemctl_mounts.fish | 14 +- share/functions/__fish_systemctl_scopes.fish | 18 +- .../__fish_systemctl_service_paths.fish | 14 +- .../functions/__fish_systemctl_services.fish | 22 +- share/functions/__fish_systemctl_slices.fish | 18 +- .../functions/__fish_systemctl_snapshots.fish | 20 +- share/functions/__fish_systemctl_sockets.fish | 14 +- share/functions/__fish_systemctl_swaps.fish | 14 +- share/functions/__fish_systemctl_targets.fish | 14 +- share/functions/__fish_systemctl_timers.fish | 14 +- .../__fish_systemd_machine_images.fish | 4 +- share/functions/__fish_systemd_machines.fish | 4 +- share/functions/__fish_test_arg.fish | 2 +- .../__fish_toggle_comment_commandline.fish | 3 +- share/functions/__fish_urlencode.fish | 44 +-- share/functions/__fish_use_subcommand.fish | 20 +- share/functions/__fish_vcs_prompt.fish | 6 +- share/functions/__terlar_git_prompt.fish | 117 +++--- share/functions/abbr.fish | 289 +++++++-------- share/functions/alias.fish | 2 +- share/functions/contains_seq.fish | 86 ++--- share/functions/delete-or-exit.fish | 14 +- share/functions/dirs.fish | 28 +- share/functions/down-or-search.fish | 42 +-- share/functions/eval.fish | 116 +++--- share/functions/fish_clipboard_copy.fish | 2 +- share/functions/fish_clipboard_paste.fish | 2 +- share/functions/fish_config.fish | 14 +- .../functions/fish_default_key_bindings.fish | 6 +- share/functions/fish_fallback_prompt.fish | 30 +- share/functions/fish_hybrid_key_bindings.fish | 2 +- share/functions/fish_indent.fish | 2 +- share/functions/fish_key_reader.fish | 2 +- share/functions/fish_mode_prompt.fish | 38 +- share/functions/fish_prompt.fish | 30 +- share/functions/fish_update_completions.fish | 4 +- share/functions/fish_vi_cursor.fish | 8 +- share/functions/fish_vi_key_bindings.fish | 4 +- share/functions/fish_vi_mode.fish | 8 +- share/functions/funced.fish | 64 ++-- share/functions/funcsave.fish | 66 ++-- share/functions/grep.fish | 6 +- share/functions/help.fish | 274 +++++++------- share/functions/hostname.fish | 12 +- share/functions/isatty.fish | 38 +- share/functions/la.fish | 2 +- share/functions/ll.fish | 2 +- share/functions/ls.fish | 52 +-- share/functions/man.fish | 37 +- share/functions/nextd-or-forward-word.fish | 14 +- share/functions/nextd.fish | 51 +-- share/functions/open.fish | 40 +-- share/functions/popd.fish | 28 +- share/functions/prevd-or-backward-word.fish | 2 +- share/functions/prevd.fish | 53 +-- share/functions/prompt_pwd.fish | 34 +- share/functions/psub.fish | 157 ++++---- share/functions/pushd.fish | 128 +++---- share/functions/seq.fish | 84 ++--- share/functions/setenv.fish | 2 +- share/functions/suspend.fish | 7 +- share/functions/trap.fish | 206 +++++------ share/functions/type.fish | 257 +++++++------- share/functions/umask.fish | 334 +++++++++--------- share/functions/up-or-search.fish | 40 +-- share/functions/vared.fish | 68 ++-- 161 files changed, 2638 insertions(+), 2587 deletions(-) diff --git a/share/functions/N_.fish b/share/functions/N_.fish index 74c39b4af..9b05f12ff 100644 --- a/share/functions/N_.fish +++ b/share/functions/N_.fish @@ -1,6 +1,6 @@ function N_ --description "No-op" - printf "%s" $argv + printf "%s" $argv end diff --git a/share/functions/__fish_append.fish b/share/functions/__fish_append.fish index 43caa26c0..d1b6ece1e 100644 --- a/share/functions/__fish_append.fish +++ b/share/functions/__fish_append.fish @@ -1,7 +1,7 @@ function __fish_append -d "Internal completion function for appending string to the commandline" --argument separator - set -e argv[1] - set str (commandline -tc| sed -ne "s/\(.*$separator\)[^$separator]*/\1/p"|sed -e "s/--.*=//") - printf "%s\n" "$str"$argv "$str"(printf "%s\n" $argv|sed -e "s/\(\t\|\$\)/,\1/") + set -e argv[1] + set str (commandline -tc| sed -ne "s/\(.*$separator\)[^$separator]*/\1/p"|sed -e "s/--.*=//") + printf "%s\n" "$str"$argv "$str"(printf "%s\n" $argv|sed -e "s/\(\t\|\$\)/,\1/") end diff --git a/share/functions/__fish_bind_test1.fish b/share/functions/__fish_bind_test1.fish index 7659f5f45..fa5fe4de1 100644 --- a/share/functions/__fish_bind_test1.fish +++ b/share/functions/__fish_bind_test1.fish @@ -5,21 +5,21 @@ function __fish_bind_test1 for i in (commandline -poc) switch $i case -k --k --ke --key - set use_keys yes + set use_keys yes case "-*" case "*" - set args $args $i + set args $args $i end end switch $use_keys case yes - switch (count $args) - case 1 - return 0 - end + switch (count $args) + case 1 + return 0 + end end return 1 end diff --git a/share/functions/__fish_bind_test2.fish b/share/functions/__fish_bind_test2.fish index 4c7f684ac..fded8b262 100644 --- a/share/functions/__fish_bind_test2.fish +++ b/share/functions/__fish_bind_test2.fish @@ -1,20 +1,20 @@ function __fish_bind_test2 -set -l args -for i in (commandline -poc) - switch $i - case "-*" + set -l args + for i in (commandline -poc) + switch $i + case "-*" - case "*" - set args $args $i - end -end + case "*" + set args $args $i + end + end - switch (count $args) - case 2 - return 0 - end + switch (count $args) + case 2 + return 0 + end - return 1 + return 1 end diff --git a/share/functions/__fish_commandline_test.fish b/share/functions/__fish_commandline_test.fish index a7e5e00b7..e89b13f11 100644 --- a/share/functions/__fish_commandline_test.fish +++ b/share/functions/__fish_commandline_test.fish @@ -5,10 +5,10 @@ function __fish_commandline_test for i in (commandline -poc) switch $i case -f --f --fu --fun --func --funct --functi --functio --function - set is_function yes + set is_function yes case -- - break + break end @@ -16,7 +16,7 @@ function __fish_commandline_test switch $is_function case yes - return 0 + return 0 end return 1 diff --git a/share/functions/__fish_complete_abook_formats.fish b/share/functions/__fish_complete_abook_formats.fish index b1c03fd6a..bc58a2267 100644 --- a/share/functions/__fish_complete_abook_formats.fish +++ b/share/functions/__fish_complete_abook_formats.fish @@ -2,11 +2,11 @@ function __fish_complete_abook_formats --description 'Complete abook formats' set -l pat switch $argv[1] case in - set pat '/output:/,$d; /input:\|^$/d' + set pat '/output:/,$d; /input:\|^$/d' case out - set pat '/input:/,/output:/d; /^$/d' + set pat '/input:/,/output:/d; /^$/d' case '*' - return 1 + return 1 end abook --formats | sed -e $pat -e 's/^\s\+//' diff --git a/share/functions/__fish_complete_ant_targets.fish b/share/functions/__fish_complete_ant_targets.fish index 61dde00a6..e93b855c6 100644 --- a/share/functions/__fish_complete_ant_targets.fish +++ b/share/functions/__fish_complete_ant_targets.fish @@ -1,15 +1,16 @@ function __fish_complete_ant_targets -d "Print list of targets from build.xml and imported files" - set -l buildfile "build.xml" - if test -f $buildfile - # show ant targets - __fish_filter_ant_targets $buildfile + set -l buildfile "build.xml" + if test -f $buildfile + # show ant targets + __fish_filter_ant_targets $buildfile - # find files with buildfile - set files (sed -n "s/^.*]* file=[\"']\([^\"']*\)[\"'].*\$/\1/p" < $buildfile) + # find files with buildfile + set files (sed -n "s/^.*]* file=[\"']\([^\"']*\)[\"'].*\$/\1/p" < $buildfile) - # iterate through files and display their targets - for file in $files; - __fish_filter_ant_targets $file - end - end + # iterate through files and display their targets + for file in $files + + __fish_filter_ant_targets $file + end + end end diff --git a/share/functions/__fish_complete_atool_archive_contents.fish b/share/functions/__fish_complete_atool_archive_contents.fish index dcc062f69..0a19c8217 100644 --- a/share/functions/__fish_complete_atool_archive_contents.fish +++ b/share/functions/__fish_complete_atool_archive_contents.fish @@ -1,20 +1,20 @@ function __fish_complete_atool_archive_contents --description 'List archive contents' - set -l cmd (commandline -cop) - set -e cmd[1] - set -l file - for arg in $cmd - switch $arg - case '-*' - case '*' - if test -f $arg - set file $arg - break - end - end - end - if not set -q file[1] - return - end - als $file -qq | sed -r 's/^\s*[0-9]+\s+[0-9-]+\s+[0-9:]+\s+(.*)$/\1/' + set -l cmd (commandline -cop) + set -e cmd[1] + set -l file + for arg in $cmd + switch $arg + case '-*' + case '*' + if test -f $arg + set file $arg + break + end + end + end + if not set -q file[1] + return + end + als $file -qq | sed -r 's/^\s*[0-9]+\s+[0-9-]+\s+[0-9:]+\s+(.*)$/\1/' end diff --git a/share/functions/__fish_complete_bittorrent.fish b/share/functions/__fish_complete_bittorrent.fish index d78d0c100..7e74fdf31 100644 --- a/share/functions/__fish_complete_bittorrent.fish +++ b/share/functions/__fish_complete_bittorrent.fish @@ -1,33 +1,33 @@ # Bittorrent commands function __fish_complete_bittorrent - complete -c $argv -l max_uploads -x --description "Maximum uploads at once" - complete -c $argv -l keepalive_interval -x --description "Number of seconds between keepalives" - complete -c $argv -l download_slice_size -x --description "Bytes per request" - complete -c $argv -l request_backlog -x --description "Requests per pipe" - complete -c $argv -l max_message_length -x --description "Maximum length prefix encoding" - complete -c $argv -l ip --description "IP to report to the tracker" -x -a "(__fish_print_addresses)" - complete -c $argv -l minport --description "Minimum port to listen to" - complete -c $argv -l maxport --description "Maximum port to listen to" - complete -c $argv -l responsefile -r --description "File for server response" - complete -c $argv -l url -x --description "URL to get file from" - complete -c $argv -l saveas -r --description "Local file target" - complete -c $argv -l timeout -x --description "Time to close inactive socket" - complete -c $argv -l timeout_check_interval -x --description "Time between checking timeouts" - complete -c $argv -l max_slice_length -x --description "Maximum outgoing slice length" - complete -c $argv -l max_rate_period -x --description "Maximum time to guess rate" - complete -c $argv -l bind -x --description "IP to bind to locally" -a "(__fish_print_addresses)" - complete -c $argv -l display_interval -x --description "Time between screen updates" - complete -c $argv -l rerequest_interval -x --description "Time to wait between requesting more peers" - complete -c $argv -l min_peers -x --description "Minimum number of peers to not do requesting" - complete -c $argv -l http_timeout -x --description "Number of seconds before assuming http timeout" - complete -c $argv -l max_initiate -x --description "Number of peers at which to stop initiating new connections" - complete -c $argv -l max_allow_in -x --description "Maximum number of connections to allow" - complete -c $argv -l check_hashes -x --description "Whether to check hashes on disk" - complete -c $argv -l max_upload_rate -x --description "Maximum kB/s to upload at" - complete -c $argv -l snub_time -x --description "Seconds to wait for data to come in before assuming choking" - complete -c $argv -l spew -x --description "Whether to display diagnostic info" - complete -c $argv -l rarest_first_cutoff -x --description "Number of downloads at which to switch from random to rarest first" - complete -c $argv -l min_uploads -x --description "Number of uploads to fill out to with optimistic unchokes" - complete -c $argv -l report_hash_failiures -x --description "Whether to inform the user that hash failures occur" + complete -c $argv -l max_uploads -x --description "Maximum uploads at once" + complete -c $argv -l keepalive_interval -x --description "Number of seconds between keepalives" + complete -c $argv -l download_slice_size -x --description "Bytes per request" + complete -c $argv -l request_backlog -x --description "Requests per pipe" + complete -c $argv -l max_message_length -x --description "Maximum length prefix encoding" + complete -c $argv -l ip --description "IP to report to the tracker" -x -a "(__fish_print_addresses)" + complete -c $argv -l minport --description "Minimum port to listen to" + complete -c $argv -l maxport --description "Maximum port to listen to" + complete -c $argv -l responsefile -r --description "File for server response" + complete -c $argv -l url -x --description "URL to get file from" + complete -c $argv -l saveas -r --description "Local file target" + complete -c $argv -l timeout -x --description "Time to close inactive socket" + complete -c $argv -l timeout_check_interval -x --description "Time between checking timeouts" + complete -c $argv -l max_slice_length -x --description "Maximum outgoing slice length" + complete -c $argv -l max_rate_period -x --description "Maximum time to guess rate" + complete -c $argv -l bind -x --description "IP to bind to locally" -a "(__fish_print_addresses)" + complete -c $argv -l display_interval -x --description "Time between screen updates" + complete -c $argv -l rerequest_interval -x --description "Time to wait between requesting more peers" + complete -c $argv -l min_peers -x --description "Minimum number of peers to not do requesting" + complete -c $argv -l http_timeout -x --description "Number of seconds before assuming http timeout" + complete -c $argv -l max_initiate -x --description "Number of peers at which to stop initiating new connections" + complete -c $argv -l max_allow_in -x --description "Maximum number of connections to allow" + complete -c $argv -l check_hashes -x --description "Whether to check hashes on disk" + complete -c $argv -l max_upload_rate -x --description "Maximum kB/s to upload at" + complete -c $argv -l snub_time -x --description "Seconds to wait for data to come in before assuming choking" + complete -c $argv -l spew -x --description "Whether to display diagnostic info" + complete -c $argv -l rarest_first_cutoff -x --description "Number of downloads at which to switch from random to rarest first" + complete -c $argv -l min_uploads -x --description "Number of uploads to fill out to with optimistic unchokes" + complete -c $argv -l report_hash_failiures -x --description "Whether to inform the user that hash failures occur" end diff --git a/share/functions/__fish_complete_cd.fish b/share/functions/__fish_complete_cd.fish index 3ba2ad9d5..381e0b0b7 100644 --- a/share/functions/__fish_complete_cd.fish +++ b/share/functions/__fish_complete_cd.fish @@ -1,32 +1,36 @@ function __fish_complete_cd -d "Completions for the cd command" - set -l token (commandline -ct) - # Absolute path or explicitly from the current directory - no descriptions and no CDPATH - 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 - end - else # Relative path - check $CDPATH and use that as description - set -l cdpath $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) - and contains -- "." $cdpath - set -e cdpath[$ind] - end - # TODO: There's a subtlety regarding descriptions - if $cdpath[1]/foo and $cdpath[2]/foo exist, we print both - # but want the first description to win - this currently works, but is not guaranteed - for i in $cdpath - set -l desc - # Don't show description for current directory - # and replace $HOME with "~" - [ $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 - end - end - end + set -l token (commandline -ct) + # Absolute path or explicitly from the current directory - no descriptions and no CDPATH + 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 + end + else # Relative path - check $CDPATH and use that as description + set -l cdpath $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) + and contains -- "." $cdpath + set -e cdpath[$ind] + end + # TODO: There's a subtlety regarding descriptions - if $cdpath[1]/foo and $cdpath[2]/foo exist, we print both + # but want the first description to win - this currently works, but is not guaranteed + for i in $cdpath + set -l desc + # Don't show description for current directory + # and replace $HOME with "~" + [ $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 + end + end + end end diff --git a/share/functions/__fish_complete_command.fish b/share/functions/__fish_complete_command.fish index 35f5e29b5..f6cc7e20a 100644 --- a/share/functions/__fish_complete_command.fish +++ b/share/functions/__fish_complete_command.fish @@ -1,10 +1,10 @@ function __fish_complete_command --description 'Complete using all available commands' - set -l ctoken (commandline -ct) - switch $ctoken - case '*=*' - set ctoken (string split "=" -- $ctoken) - printf '%s\n' $ctoken[1]=(complete -C$ctoken[2]) - case '*' - complete -C$ctoken - end + set -l ctoken (commandline -ct) + switch $ctoken + case '*=*' + set ctoken (string split "=" -- $ctoken) + printf '%s\n' $ctoken[1]=(complete -C$ctoken[2]) + case '*' + complete -C$ctoken + end end diff --git a/share/functions/__fish_complete_convert_options.fish b/share/functions/__fish_complete_convert_options.fish index 3437cc70b..863c83c7f 100644 --- a/share/functions/__fish_complete_convert_options.fish +++ b/share/functions/__fish_complete_convert_options.fish @@ -1,16 +1,16 @@ function __fish_complete_convert_options --description 'Complete Convert options' --argument what - switch $what - case format Format - convert -list Format | sed '1,/----/d; /^$/,$d; /^$/d; s/^\s*\([a-zA-Z0-9-]\+\)\**\s*\S\+\s\+\\(\S\+\)\s\+\(.\+\S\)\s*$/\1\t\2 \3/' - case color Color - convert -list color | awk '{ print $1"\t"$2" "$3} ' | sed '1,/----/d' - case family - convert -list Font | grep family | sed 's/^\s*.\+: //' | sort -u - case font Font - convert -list Font | grep Font | sed 's/^\s*.\+: //' | sort -u - case '*' - convert -list $what - end + switch $what + case format Format + convert -list Format | sed '1,/----/d; /^$/,$d; /^$/d; s/^\s*\([a-zA-Z0-9-]\+\)\**\s*\S\+\s\+\\(\S\+\)\s\+\(.\+\S\)\s*$/\1\t\2 \3/' + case color Color + convert -list color | awk '{ print $1"\t"$2" "$3} ' | sed '1,/----/d' + case family + convert -list Font | grep family | sed 's/^\s*.\+: //' | sort -u + case font Font + convert -list Font | grep Font | sed 's/^\s*.\+: //' | sort -u + case '*' + convert -list $what + end end diff --git a/share/functions/__fish_complete_directories.fish b/share/functions/__fish_complete_directories.fish index ba222f0b2..35a82e92a 100644 --- a/share/functions/__fish_complete_directories.fish +++ b/share/functions/__fish_complete_directories.fish @@ -5,17 +5,17 @@ function __fish_complete_directories -d "Complete using directories" --argument comp - set desc (_ Directory) + set desc (_ Directory) - if test (count $argv) -gt 1 - set desc $argv[2] - end + if test (count $argv) -gt 1 + set desc $argv[2] + end - eval "set dirs "$comp"*/" + eval "set dirs "$comp"*/" - if test $dirs[1] - printf "%s\t$desc\n" $dirs - end + if test $dirs[1] + printf "%s\t$desc\n" $dirs + end end diff --git a/share/functions/__fish_complete_file_url.fish b/share/functions/__fish_complete_file_url.fish index 28af18080..c19df569e 100644 --- a/share/functions/__fish_complete_file_url.fish +++ b/share/functions/__fish_complete_file_url.fish @@ -1,20 +1,20 @@ function __fish_complete_file_url - set -l comp + set -l comp - if set -q argv[1] - set comp $argv[1] - else - set comp (commandline -ct) - end + if set -q argv[1] + set comp $argv[1] + else + set comp (commandline -ct) + end - set -l prefix (echo $comp|cut -c 1-7) + set -l prefix (echo $comp|cut -c 1-7) - if test file:// = $prefix - set -l stripped (echo $comp|cut -c 8-) - printf "%s\n" file://(complete -C"echo $stripped") - else - echo file:// - end + if test file:// = $prefix + set -l stripped (echo $comp|cut -c 8-) + printf "%s\n" file://(complete -C"echo $stripped") + else + echo file:// + end end diff --git a/share/functions/__fish_complete_ftp.fish b/share/functions/__fish_complete_ftp.fish index 92ff0b088..f651b756a 100644 --- a/share/functions/__fish_complete_ftp.fish +++ b/share/functions/__fish_complete_ftp.fish @@ -1,14 +1,14 @@ function __fish_complete_ftp -d 'Complete ftp, pftp' --argument-names ftp - complete -c $ftp -xa "(__fish_print_hostnames)" -d 'Hostname' - complete -c $ftp -s 4 -d 'Use only IPv4 to contact any host' - complete -c $ftp -s 6 -d 'Use IPv6 only' - complete -c $ftp -s p -d 'Use passive mode for data transfers' - complete -c $ftp -s A -d 'Use active mode for data transfers' - complete -c $ftp -s i -d 'Turn off interactive prompting during multiple file transfers.' - complete -c $ftp -s n -d 'Restrain ftp from attempting "auto-login" upon initial connection' - complete -c $ftp -s e -d 'Disable command editing and history support' - complete -c $ftp -s g -d 'Disable file name globbing' - complete -c $ftp -s m -d 'Do not explicitly bind data and control channels to same interface' - complete -c $ftp -s v -d 'Verbose. Show all server responses and data transfer stats' - complete -c $ftp -s d -d 'Enable debugging' + complete -c $ftp -xa "(__fish_print_hostnames)" -d 'Hostname' + complete -c $ftp -s 4 -d 'Use only IPv4 to contact any host' + complete -c $ftp -s 6 -d 'Use IPv6 only' + complete -c $ftp -s p -d 'Use passive mode for data transfers' + complete -c $ftp -s A -d 'Use active mode for data transfers' + complete -c $ftp -s i -d 'Turn off interactive prompting during multiple file transfers.' + complete -c $ftp -s n -d 'Restrain ftp from attempting "auto-login" upon initial connection' + complete -c $ftp -s e -d 'Disable command editing and history support' + complete -c $ftp -s g -d 'Disable file name globbing' + complete -c $ftp -s m -d 'Do not explicitly bind data and control channels to same interface' + complete -c $ftp -s v -d 'Verbose. Show all server responses and data transfer stats' + complete -c $ftp -s d -d 'Enable debugging' end diff --git a/share/functions/__fish_complete_groups.fish b/share/functions/__fish_complete_groups.fish index ca2f4ccb5..a7a41f0aa 100644 --- a/share/functions/__fish_complete_groups.fish +++ b/share/functions/__fish_complete_groups.fish @@ -1,8 +1,8 @@ function __fish_complete_groups --description "Print a list of local groups, with group members as the description" - if command -s getent >/dev/null - getent group | cut -d ':' -f 1,4 | sed 's/:/\t/' - else - cut -d ':' -f 1,4 /etc/group | sed 's/:/\t/' - end + if command -s getent >/dev/null + getent group | cut -d ':' -f 1,4 | sed 's/:/\t/' + else + cut -d ':' -f 1,4 /etc/group | sed 's/:/\t/' + end end diff --git a/share/functions/__fish_complete_list.fish b/share/functions/__fish_complete_list.fish index 99d65ef19..bfe3ecf91 100644 --- a/share/functions/__fish_complete_list.fish +++ b/share/functions/__fish_complete_list.fish @@ -1,30 +1,30 @@ function __fish_complete_list --argument div cmd prefix iprefix - if not set -q cmd[1] - echo "Usage: + if not set -q cmd[1] + echo "Usage: __fish_complete_list where: separator - a symbol, separating individual entries function - a function which prints a completion list to complete each entry prefix - a prefix, which is printed before the list - itemprefix - a prefix, which is printed before each item" > /dev/stderr - return 1 - end - set -q iprefix[1] - or set -l iprefix "" - set -q prefix[1] - or set -l prefix "" - set -l pat (commandline -t) - #set -l pat $argv[5] - switch $pat - case "*$div*" - for i in (echo $pat | sed "s/^\(.\+$div\)$iprefix.*\$/\1/")$iprefix(eval $cmd) - echo $i - end - case '*' - for i in $prefix$iprefix(eval $cmd) - echo $i - end - end + itemprefix - a prefix, which is printed before each item" >/dev/stderr + return 1 + end + set -q iprefix[1] + or set -l iprefix "" + set -q prefix[1] + or set -l prefix "" + set -l pat (commandline -t) + #set -l pat $argv[5] + switch $pat + case "*$div*" + for i in (echo $pat | sed "s/^\(.\+$div\)$iprefix.*\$/\1/")$iprefix(eval $cmd) + echo $i + end + case '*' + for i in $prefix$iprefix(eval $cmd) + echo $i + end + end end diff --git a/share/functions/__fish_complete_lpr.fish b/share/functions/__fish_complete_lpr.fish index c6b2cbf45..f594147f6 100644 --- a/share/functions/__fish_complete_lpr.fish +++ b/share/functions/__fish_complete_lpr.fish @@ -4,35 +4,35 @@ function __fish_complete_lpr -d 'Complete lpr common options' --argument-names c switch $cmd case lpr lpq lprm - complete -c $cmd -s P -d 'Specifies an alternate printer or class name' -xa '(__fish_print_lpr_printers)' + complete -c $cmd -s P -d 'Specifies an alternate printer or class name' -xa '(__fish_print_lpr_printers)' end switch $cmd case lpq cancel - complete -c $cmd -s a -d 'Apply command to all printers' + complete -c $cmd -s a -d 'Apply command to all printers' end switch $cmd - case lpq cancel lpmove lpstat lprm lpoptions lp reject accept cupsaccept cupsreject cupsenable cupsdisable - complete -c $cmd -s h -d 'Specifies an alternate server' -xa '(__fish_print_hostnames)' + case lpq cancel lpmove lpstat lprm lpoptions lp reject accept cupsaccept cupsreject cupsenable cupsdisable + complete -c $cmd -s h -d 'Specifies an alternate server' -xa '(__fish_print_hostnames)' end switch $cmd case lp lpr - complete -c $cmd -s o -d 'Sets a job option' -xa '(__fish_complete_lpr_option)' - complete -c $cmd -s m -d 'Send an email on job completion' + complete -c $cmd -s o -d 'Sets a job option' -xa '(__fish_complete_lpr_option)' + complete -c $cmd -s m -d 'Send an email on job completion' - complete -c $cmd -s o -xa landscape -d 'Landscape mode' - complete -c $cmd -s o -xa "media=a4 media=letter media=legal" -d 'Media size' - complete -c $cmd -s o -xa page-ranges= -d 'Page ranges' - complete -c $cmd -s o -xa orientation-requested= -d 'Choose orientation (4-landscape)' - complete -c $cmd -s o -xa 'sides-one-sided two-sided-long-edge two-sided-short-edge' -d 'Choose between one/two sided modes' - complete -c $cmd -s o -xa fitplot -d 'Scale the print file to fit on the page' - complete -c $cmd -s o -xa 'number-up=2 number-up=4 number-up=6 number-up=9' -d 'Print multiple document pages on each output page' - complete -c $cmd -s o -xa 'scaling=' -d 'Scale image files to use up to number percent of the page' - complete -c $cmd -s o -xa 'cpi=' -d 'Set the number of characters per inch to use' - complete -c $cmd -s o -xa 'lpi=' -d 'Set the number of lines per inch to use' - complete -c $cmd -s o -xa 'page-bottom= page-left= page-right= page-top=' -d 'Set the page margins when printing text files' + complete -c $cmd -s o -xa landscape -d 'Landscape mode' + complete -c $cmd -s o -xa "media=a4 media=letter media=legal" -d 'Media size' + complete -c $cmd -s o -xa page-ranges= -d 'Page ranges' + complete -c $cmd -s o -xa orientation-requested= -d 'Choose orientation (4-landscape)' + complete -c $cmd -s o -xa 'sides-one-sided two-sided-long-edge two-sided-short-edge' -d 'Choose between one/two sided modes' + complete -c $cmd -s o -xa fitplot -d 'Scale the print file to fit on the page' + complete -c $cmd -s o -xa 'number-up=2 number-up=4 number-up=6 number-up=9' -d 'Print multiple document pages on each output page' + complete -c $cmd -s o -xa 'scaling=' -d 'Scale image files to use up to number percent of the page' + complete -c $cmd -s o -xa 'cpi=' -d 'Set the number of characters per inch to use' + complete -c $cmd -s o -xa 'lpi=' -d 'Set the number of lines per inch to use' + complete -c $cmd -s o -xa 'page-bottom= page-left= page-right= page-top=' -d 'Set the page margins when printing text files' end end diff --git a/share/functions/__fish_complete_lpr_option.fish b/share/functions/__fish_complete_lpr_option.fish index e593aab44..6db627f84 100644 --- a/share/functions/__fish_complete_lpr_option.fish +++ b/share/functions/__fish_complete_lpr_option.fish @@ -1,25 +1,25 @@ function __fish_complete_lpr_option --description 'Complete lpr option' - set -l optstr (commandline -t) - switch $optstr - case '*=*' - set -l IFS = - echo $optstr | read -l opt val - set -l descr - for l in (lpoptions -l ^/dev/null | string match -- "*$opt*" | string replace -r '.*/(.*):\s*(.*)$' '$1 $2' | string split " ") - if not set -q descr[1] - set descr $l - continue - end - set -l default '' - if string match -q '\**' -- $l - set default 'Default ' - set l (string sub -s 2 -- $l) - end - echo $opt=$l\t$default$descr - end - case '*' - lpoptions -l ^/dev/null | string replace -r '(.*)/(.*):.*$' '$1=\t$2' - end + set -l optstr (commandline -t) + switch $optstr + case '*=*' + set -l IFS = + echo $optstr | read -l opt val + set -l descr + for l in (lpoptions -l ^/dev/null | string match -- "*$opt*" | string replace -r '.*/(.*):\s*(.*)$' '$1 $2' | string split " ") + if not set -q descr[1] + set descr $l + continue + end + set -l default '' + if string match -q '\**' -- $l + set default 'Default ' + set l (string sub -s 2 -- $l) + end + echo $opt=$l\t$default$descr + end + case '*' + lpoptions -l ^/dev/null | string replace -r '(.*)/(.*):.*$' '$1=\t$2' + end end diff --git a/share/functions/__fish_complete_lsusb.fish b/share/functions/__fish_complete_lsusb.fish index faf7ae5b2..eba9cd29e 100644 --- a/share/functions/__fish_complete_lsusb.fish +++ b/share/functions/__fish_complete_lsusb.fish @@ -1,3 +1,3 @@ function __fish_complete_lsusb - lsusb | awk '{print $2 ":" $4}'| cut -c1-7 + lsusb | awk '{print $2 ":" $4}' | cut -c1-7 end diff --git a/share/functions/__fish_complete_man.fish b/share/functions/__fish_complete_man.fish index bd9818bb9..43415e714 100644 --- a/share/functions/__fish_complete_man.fish +++ b/share/functions/__fish_complete_man.fish @@ -1,20 +1,20 @@ function __fish_complete_man - # Try to guess what section to search in. If we don't know, we - # use [^)]*, which should match any section + # Try to guess what section to search in. If we don't know, we + # use [^)]*, which should match any section - set section "" - set prev (commandline -poc) - set -e prev[1] - while set -q prev[1] - switch $prev[1] - case '-**' + set section "" + set prev (commandline -poc) + set -e prev[1] + while set -q prev[1] + switch $prev[1] + case '-**' - case '*' - set section $prev[1] - end - set -e prev[1] - end + case '*' + set section $prev[1] + end + set -e prev[1] + end set section $section"[^)]*" @@ -25,9 +25,9 @@ function __fish_complete_man set token "." end - if test -n "$token" - # Do the actual search - apropos $token ^/dev/null | awk ' + if test -n "$token" + # Do the actual search + apropos $token ^/dev/null | awk ' BEGIN { FS="[\t ]- "; OFS="\t"; } # BSD/Darwin /^[^( \t]+\('$section'\)/ { @@ -66,7 +66,7 @@ function __fish_complete_man ' else return 1 - end + end return 0 end diff --git a/share/functions/__fish_complete_path.fish b/share/functions/__fish_complete_path.fish index e10ef7069..614d914a8 100644 --- a/share/functions/__fish_complete_path.fish +++ b/share/functions/__fish_complete_path.fish @@ -1,14 +1,14 @@ function __fish_complete_path --description "Complete using path" - set -l target - set -l description - switch (count $argv) - case 0 - # pass - case 1 - set target "$argv[1]" - case 2 "*" - set target "$argv[1]" - set description "$argv[2]" - end - printf "%s\t$description\n" (command ls -dp "$target"*) + set -l target + set -l description + switch (count $argv) + case 0 + # pass + case 1 + set target "$argv[1]" + case 2 "*" + set target "$argv[1]" + set description "$argv[2]" + end + printf "%s\t$description\n" (command ls -dp "$target"*) end diff --git a/share/functions/__fish_complete_pgrep.fish b/share/functions/__fish_complete_pgrep.fish index 816ea238d..c69b4de79 100644 --- a/share/functions/__fish_complete_pgrep.fish +++ b/share/functions/__fish_complete_pgrep.fish @@ -3,14 +3,14 @@ function __fish_complete_pgrep -d 'Complete pgrep/pkill' --argument-names cmd complete -c $cmd -xa '(__fish_complete_proc)' complete -c $cmd -s f -d 'Match pattern against full command line' complete -c $cmd -s g -d 'Only match processes in the process group' -xa '(__fish_complete_list , __fish_complete_groups)' - complete -c $cmd -s G -d "Only match processes whose real group ID is listed. Group 0 is translated into $cmd\'s own process group" -xa '(__fish_complete_list , __fish_complete_groups)' + complete -c $cmd -s G -d "Only match processes whose real group ID is listed. Group 0 is translated into $cmd\'s own process group" -xa '(__fish_complete_list , __fish_complete_groups)' complete -c $cmd -s n -d 'Select only the newest process' complete -c $cmd -s o -d 'Select only the oldest process' complete -c $cmd -s P -d 'Only match processes whose parent process ID is listed' -xa '(__fish_complete_list , __fish_complete_pids)' complete -c $cmd -s s -d "Only match processes whose process session ID is listed. Session ID 0 is translated into $cmd\'s own session ID." complete -c $cmd -s t -d 'Only match processes whose controlling terminal is listed. The terminal name should be specified without the "/dev/" prefix' -r complete -c $cmd -s u -d 'Only match processes whose effective user ID is listed' -xa '(__fish_complete_list , __fish_complete_users)' - complete -c $cmd -s U -d 'Only match processes whose real user ID is listed' -xa '(__fish_complete_list , __fish_complete_users)' + complete -c $cmd -s U -d 'Only match processes whose real user ID is listed' -xa '(__fish_complete_list , __fish_complete_users)' complete -c $cmd -s v -d 'Negates the matching' complete -c $cmd -s x -d ' Only match processes whose name (or command line if -f is specified) exactly match the pattern' end diff --git a/share/functions/__fish_complete_pids.fish b/share/functions/__fish_complete_pids.fish index e974ed61f..d00fbf92d 100644 --- a/share/functions/__fish_complete_pids.fish +++ b/share/functions/__fish_complete_pids.fish @@ -1,11 +1,11 @@ function __fish_complete_pids -d "Print a list of process identifiers along with brief descriptions" - # This may be a bit slower, but it's nice - having the tty displayed is really handy - # 'tail -n +2' deletes the first line, which contains the headers - # %self is removed from output by string match -r -v - set -l SELF %self - - # Display the tty if available - # But not if it's just question marks, meaning no tty - ps axc -o pid,ucomm,tty | string match -r -v '^\s*'$SELF'\s' | tail -n +2 | string replace -r ' *([0-9]+) +([^ ].*[^ ]|[^ ]) +([^ ]+) *$' '$1\t$2 [$3]' | string replace -r ' *\[\?*\] *$' '' + # This may be a bit slower, but it's nice - having the tty displayed is really handy + # 'tail -n +2' deletes the first line, which contains the headers + # %self is removed from output by string match -r -v + set -l SELF %self + + # Display the tty if available + # But not if it's just question marks, meaning no tty + ps axc -o pid,ucomm,tty | string match -r -v '^\s*'$SELF'\s' | tail -n +2 | string replace -r ' *([0-9]+) +([^ ].*[^ ]|[^ ]) +([^ ]+) *$' '$1\t$2 [$3]' | string replace -r ' *\[\?*\] *$' '' end diff --git a/share/functions/__fish_complete_ppp_peer.fish b/share/functions/__fish_complete_ppp_peer.fish index bc4f75448..faabba378 100644 --- a/share/functions/__fish_complete_ppp_peer.fish +++ b/share/functions/__fish_complete_ppp_peer.fish @@ -1,4 +1,4 @@ function __fish_complete_ppp_peer --description 'Complete isp name for pon/poff' - find /etc/ppp/peers/ -type f -printf '%f\n' + find /etc/ppp/peers/ -type f -printf '%f\n' end diff --git a/share/functions/__fish_complete_proc.fish b/share/functions/__fish_complete_proc.fish index d520a0302..3499c43bc 100644 --- a/share/functions/__fish_complete_proc.fish +++ b/share/functions/__fish_complete_proc.fish @@ -1,47 +1,47 @@ function __fish_complete_proc --description 'Complete by list of running processes' - # Our function runs ps, followed by a massive list of commands passed to sed - set -l ps_cmd - set -l sed_cmds - if test (uname) = Linux - # comm and ucomm return a truncated name, so parse it from the command line field, - # which means we have to trim off the arguments. - # Unfortunately, it doesn't seem to escape spaces - so we can't distinguish - # between the command name, and the first argument. Still, processes with spaces - # in the name seem more common on OS X than on Linux, so prefer to parse out the - # command line rather than using the stat data. - # If the command line is unavailable, you get the stat data in brackets - so - # parse out brackets too. - set ps_cmd 'ps -A -o command' - - # Erase everything after the first space - set sed_cmds $sed_cmds 's/ .*//' - - # Erases weird stuff Linux gives like kworker/0:0 - set sed_cmds $sed_cmds 's|/[0-9]:[0-9]]$||g' - - # Retain the last path component only - set sed_cmds $sed_cmds 's|.*/||g' - - # Strip off square brackets. Cute, huh? - set sed_cmds $sed_cmds 's/[][]//g' - - # Erase things that are just numbers - set sed_cmds $sed_cmds 's/^[0-9]*$//' - else - # OS X, BSD. Preserve leading spaces. - set ps_cmd 'ps axc -o comm' - - # Delete parenthesized (zombie) processes - set sed_cmds $sed_cmds '/(.*)/d' - end - - # Append sed command to delete first line (the header) - set sed_cmds $sed_cmds '1d' - - # Append sed commands to delete leading dashes and trailing spaces - # In principle, commands may have trailing spaces, but ps emits space padding on OS X - set sed_cmds $sed_cmds 's/^-//' 's/ *$//' - - # Run ps, pipe it through our massive set of sed commands, then sort and unique - eval $ps_cmd | sed '-e '$sed_cmds | sort -u + # Our function runs ps, followed by a massive list of commands passed to sed + set -l ps_cmd + set -l sed_cmds + if test (uname) = Linux + # comm and ucomm return a truncated name, so parse it from the command line field, + # which means we have to trim off the arguments. + # Unfortunately, it doesn't seem to escape spaces - so we can't distinguish + # between the command name, and the first argument. Still, processes with spaces + # in the name seem more common on OS X than on Linux, so prefer to parse out the + # command line rather than using the stat data. + # If the command line is unavailable, you get the stat data in brackets - so + # parse out brackets too. + set ps_cmd 'ps -A -o command' + + # Erase everything after the first space + set sed_cmds $sed_cmds 's/ .*//' + + # Erases weird stuff Linux gives like kworker/0:0 + set sed_cmds $sed_cmds 's|/[0-9]:[0-9]]$||g' + + # Retain the last path component only + set sed_cmds $sed_cmds 's|.*/||g' + + # Strip off square brackets. Cute, huh? + set sed_cmds $sed_cmds 's/[][]//g' + + # Erase things that are just numbers + set sed_cmds $sed_cmds 's/^[0-9]*$//' + else + # OS X, BSD. Preserve leading spaces. + set ps_cmd 'ps axc -o comm' + + # Delete parenthesized (zombie) processes + set sed_cmds $sed_cmds '/(.*)/d' + end + + # Append sed command to delete first line (the header) + set sed_cmds $sed_cmds '1d' + + # Append sed commands to delete leading dashes and trailing spaces + # In principle, commands may have trailing spaces, but ps emits space padding on OS X + set sed_cmds $sed_cmds 's/^-//' 's/ *$//' + + # Run ps, pipe it through our massive set of sed commands, then sort and unique + eval $ps_cmd | sed '-e '$sed_cmds | sort -u end diff --git a/share/functions/__fish_complete_setxkbmap.fish b/share/functions/__fish_complete_setxkbmap.fish index 9f8578a58..7260f7e20 100644 --- a/share/functions/__fish_complete_setxkbmap.fish +++ b/share/functions/__fish_complete_setxkbmap.fish @@ -1,3 +1,3 @@ function __fish_complete_setxkbmap --description 'Complete setxkb options' --argument-names what - sed -e "1,/! $what/d" -e '/^\s*$/,$d' /usr/share/X11/xkb/rules/xorg.lst | sed -r 's/\s+(\S+)\s+(.+)/\1\t\2/' + sed -e "1,/! $what/d" -e '/^\s*$/,$d' /usr/share/X11/xkb/rules/xorg.lst | sed -r 's/\s+(\S+)\s+(.+)/\1\t\2/' end diff --git a/share/functions/__fish_complete_ssh.fish b/share/functions/__fish_complete_ssh.fish index b1154a53a..00545dcc7 100644 --- a/share/functions/__fish_complete_ssh.fish +++ b/share/functions/__fish_complete_ssh.fish @@ -1,15 +1,15 @@ function __fish_complete_ssh -d "common completions for ssh commands" --argument command - complete -c $command -s 1 --description "Protocol version 1 only" - complete -c $command -s 2 --description "Protocol version 2 only" - complete -c $command -s 4 --description "IPv4 addresses only" - complete -c $command -s 6 --description "IPv6 addresses only" - complete -c $command -s C --description "Compress all data" - complete -xc $command -s c --description "Encryption algorithm" -a "blowfish 3des des" - complete -r -c $command -s F --description "Configuration file" - complete -r -c $command -s i --description "Identity file" - complete -x -c $command -s o --description "Options" -a " + complete -c $command -s 1 --description "Protocol version 1 only" + complete -c $command -s 2 --description "Protocol version 2 only" + complete -c $command -s 4 --description "IPv4 addresses only" + complete -c $command -s 6 --description "IPv6 addresses only" + complete -c $command -s C --description "Compress all data" + complete -xc $command -s c --description "Encryption algorithm" -a "blowfish 3des des" + complete -r -c $command -s F --description "Configuration file" + complete -r -c $command -s i --description "Identity file" + complete -x -c $command -s o --description "Options" -a " AddressFamily BatchMode BindAddress @@ -56,6 +56,6 @@ function __fish_complete_ssh -d "common completions for ssh commands" --argument UserKnownHostsFile VerifyHostKeyDNS " - complete -c $command -s v --description "Verbose mode" + complete -c $command -s v --description "Verbose mode" end diff --git a/share/functions/__fish_complete_subcommand.fish b/share/functions/__fish_complete_subcommand.fish index 4707450fc..9f5ac1d59 100644 --- a/share/functions/__fish_complete_subcommand.fish +++ b/share/functions/__fish_complete_subcommand.fish @@ -1,5 +1,5 @@ -function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowing - set -l skip_next 1 +function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowing + set -l skip_next 1 set -l test switch "$argv[1]" case '--fcs-skip=*' @@ -8,38 +8,38 @@ function __fish_complete_subcommand -d "Complete subcommand" --no-scope-shadowi set -e argv[1] end - set -l res "" - set -l had_cmd 0 - set -l cmd (commandline -cop) (commandline -ct) + set -l res "" + set -l had_cmd 0 + set -l cmd (commandline -cop) (commandline -ct) - for i in $cmd + for i in $cmd - if test $skip_next -gt 0 + if test $skip_next -gt 0 set skip_next (math $skip_next - 1) - continue - end + continue + end - if test "$had_cmd" = 1 - set res "$res $i" - else + if test "$had_cmd" = 1 + set res "$res $i" + else - if contains -- $i $argv - set skip_next (math $skip_next + 1) - continue - end + if contains -- $i $argv + set skip_next (math $skip_next + 1) + continue + end - switch $i - case '-*' - case '*=*' - case '*' + switch $i + case '-*' + case '*=*' + case '*' - set had_cmd 1 - set res $i - end - end - end + set had_cmd 1 + set res $i + end + end + end - printf "%s\n" (complete -C$res) + printf "%s\n" (complete -C$res) end diff --git a/share/functions/__fish_complete_subcommand_root.fish b/share/functions/__fish_complete_subcommand_root.fish index 822820fdb..f27984543 100644 --- a/share/functions/__fish_complete_subcommand_root.fish +++ b/share/functions/__fish_complete_subcommand_root.fish @@ -1,6 +1,6 @@ function __fish_complete_subcommand_root -d "Run the __fish_complete_subcommand function using a PATH containing /sbin and /usr/sbin" - set -lx PATH /sbin /usr/sbin $PATH ^/dev/null - __fish_complete_subcommand $argv + set -lx PATH /sbin /usr/sbin $PATH ^/dev/null + __fish_complete_subcommand $argv end diff --git a/share/functions/__fish_complete_suffix.fish b/share/functions/__fish_complete_suffix.fish index d0c264db2..a12d95e6b 100644 --- a/share/functions/__fish_complete_suffix.fish +++ b/share/functions/__fish_complete_suffix.fish @@ -7,47 +7,47 @@ function __fish_complete_suffix -d "Complete using files" - # Variable declarations + # Variable declarations - set -l comp - set -l suff - set -l desc - set -l files + set -l comp + set -l suff + set -l desc + set -l files - switch (count $argv) + switch (count $argv) - case 1 - set comp (commandline -ct) - set suff $argv - set desc "" + case 1 + set comp (commandline -ct) + set suff $argv + set desc "" - case 2 - set comp $argv[1] - set suff $argv[2] - set desc "" + case 2 + set comp $argv[1] + set suff $argv[2] + set desc "" - case 3 - set comp $argv[1] - set suff $argv[2] - set desc $argv[3] + case 3 + set comp $argv[1] + set suff $argv[2] + set desc $argv[3] - end + end - # Perform the completion + # Perform the completion - set base (echo $comp |sed -e 's/\.[a-zA-Z0-9]*$//') - eval "set files $base*$suff" + set base (echo $comp |sed -e 's/\.[a-zA-Z0-9]*$//') + eval "set files $base*$suff" - if test $files[1] - printf "%s\t$desc\n" $files - end + if test $files[1] + printf "%s\t$desc\n" $files + end - # - # Also do directory completion, since there might be files - # with the correct suffix in a subdirectory - # No need to describe directories (#279) - # + # + # Also do directory completion, since there might be files + # with the correct suffix in a subdirectory + # No need to describe directories (#279) + # - __fish_complete_directories $comp "" + __fish_complete_directories $comp "" end diff --git a/share/functions/__fish_complete_svn_diff.fish b/share/functions/__fish_complete_svn_diff.fish index ada2dd0ed..eb67fcc21 100644 --- a/share/functions/__fish_complete_svn_diff.fish +++ b/share/functions/__fish_complete_svn_diff.fish @@ -1,25 +1,25 @@ function __fish_complete_svn_diff --description 'Complete "svn diff" arguments' - set -l cmdl (commandline -cop) -#set -l cmdl svn diff --diff-cmd diff --extensions '-a -b' -set -l diff diff -set -l args -while set -q cmdl[1] -switch $cmdl[1] -case --diff-cmd -if set -q cmdl[2] -set diff $cmdl[2] -set -e cmd[2] -end + set -l cmdl (commandline -cop) + #set -l cmdl svn diff --diff-cmd diff --extensions '-a -b' + set -l diff diff + set -l args + while set -q cmdl[1] + switch $cmdl[1] + case --diff-cmd + if set -q cmdl[2] + set diff $cmdl[2] + set -e cmd[2] + end -case --extensions -if set -q cmdl[2] -set args $cmdl[2] -set -e cmdl[2] -end -end -set -e cmdl[1] -end -set -l token (commandline -cpt) -complete -C"$diff $args $token" + case --extensions + if set -q cmdl[2] + set args $cmdl[2] + set -e cmdl[2] + end + end + set -e cmdl[1] + end + set -l token (commandline -cpt) + complete -C"$diff $args $token" end diff --git a/share/functions/__fish_complete_tar.fish b/share/functions/__fish_complete_tar.fish index 91a795015..94a3c0389 100644 --- a/share/functions/__fish_complete_tar.fish +++ b/share/functions/__fish_complete_tar.fish @@ -1,35 +1,35 @@ function __fish_complete_tar -d "Peek inside of archives and list all files" - set -l cmd (commandline -poc) - set -e cmd[1] - for i in $cmd - switch $i - case '-*' - continue + set -l cmd (commandline -poc) + set -e cmd[1] + for i in $cmd + switch $i + case '-*' + continue - case '*.tar.bz' '*.tar.bz2' '*.tbz' '*.tbz2' - if test -f $i - set -l file_list (tar -jt <$i) - printf (_ "%s\tArchived file\n") $file_list - end - return + case '*.tar.bz' '*.tar.bz2' '*.tbz' '*.tbz2' + if test -f $i + set -l file_list (tar -jt <$i) + printf (_ "%s\tArchived file\n") $file_list + end + return - case '*.tar.gz' '*.tgz' - if test -f $i - set -l file_list (tar -it <$i) - printf (_ "%s\tArchived file\n") $file_list - end - return + case '*.tar.gz' '*.tgz' + if test -f $i + set -l file_list (tar -it <$i) + printf (_ "%s\tArchived file\n") $file_list + end + return - case '*.tar' - if test -f $i - set -l file_list (tar -t <$i) - printf (_ "%s\tArchived file\n") $file_list - end - return - end - end + case '*.tar' + if test -f $i + set -l file_list (tar -t <$i) + printf (_ "%s\tArchived file\n") $file_list + end + return + end + end end diff --git a/share/functions/__fish_complete_unrar.fish b/share/functions/__fish_complete_unrar.fish index 1c86794e5..c5cbc7ad9 100644 --- a/share/functions/__fish_complete_unrar.fish +++ b/share/functions/__fish_complete_unrar.fish @@ -1,21 +1,21 @@ function __fish_complete_unrar -d "Peek inside of archives and list all files" - set -l cmd (commandline -poc) - set -e cmd[1] - for i in $cmd - switch $i - case '-*' - continue + set -l cmd (commandline -poc) + set -e cmd[1] + for i in $cmd + switch $i + case '-*' + continue - case '*.rar' - if test -f $i - set -l file_list (unrar vb $i) - printf (_ "%s\tArchived file\n") $file_list - end - return - end - end + case '*.rar' + if test -f $i + set -l file_list (unrar vb $i) + printf (_ "%s\tArchived file\n") $file_list + end + return + end + end end diff --git a/share/functions/__fish_complete_users.fish b/share/functions/__fish_complete_users.fish index 199231be1..f7002fe21 100644 --- a/share/functions/__fish_complete_users.fish +++ b/share/functions/__fish_complete_users.fish @@ -1,10 +1,10 @@ function __fish_complete_users --description "Print a list of local users, with the real user name as a description" - if test -x /usr/bin/getent - getent passwd | cut -d : -f 1,5 | string replace -r ':' \t - else if test -x /usr/bin/dscl - dscl . -list /Users RealName | string match -r -v '^_' | string replace -r ' {2,}' \t - else - string match -v -r '^\s*#' < /etc/passwd | cut -d : -f 1,5 | string replace ':' \t - end + if test -x /usr/bin/getent + getent passwd | cut -d : -f 1,5 | string replace -r ':' \t + else if test -x /usr/bin/dscl + dscl . -list /Users RealName | string match -r -v '^_' | string replace -r ' {2,}' \t + else + string match -v -r '^\s*#' /dev/null - return 0 - end + if commandline -cpo | __fish_sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null + return 0 + end - if commandline -ct | __fish_sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null - return 0 - end - end + if commandline -ct | __fish_sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null + return 0 + end + end - for i in $long_opt - if test -z $i - continue - end + for i in $long_opt + if test -z $i + continue + end - if contains -- --$i (commandline -cpo) - return 0 - end - end + if contains -- --$i (commandline -cpo) + return 0 + end + end - return 1 + return 1 end diff --git a/share/functions/__fish_crux_packages.fish b/share/functions/__fish_crux_packages.fish index fa96e4803..904d1b863 100644 --- a/share/functions/__fish_crux_packages.fish +++ b/share/functions/__fish_crux_packages.fish @@ -1,4 +1,4 @@ # a function to obtain a list of installed packages with CRUX pkgutils function __fish_crux_packages -d 'Obtain a list of installed packages' - pkginfo -i|cut -d' ' -f1 + pkginfo -i | cut -d' ' -f1 end diff --git a/share/functions/__fish_cursor_konsole.fish b/share/functions/__fish_cursor_konsole.fish index ef7c777b8..e6941a451 100644 --- a/share/functions/__fish_cursor_konsole.fish +++ b/share/functions/__fish_cursor_konsole.fish @@ -1,11 +1,11 @@ function __fish_cursor_konsole -d 'Set cursor (konsole)' - set -l shape $argv[1] - switch "$shape" - case block - echo -en '\e]50;CursorShape=0\x7' - case underscore - echo -en '\e]50;CursorShape=2\x7' - case line - echo -en '\e]50;CursorShape=1\x7' - end + set -l shape $argv[1] + switch "$shape" + case block + echo -en '\e]50;CursorShape=0\x7' + case underscore + echo -en '\e]50;CursorShape=2\x7' + case line + echo -en '\e]50;CursorShape=1\x7' + end end diff --git a/share/functions/__fish_cursor_xterm.fish b/share/functions/__fish_cursor_xterm.fish index c7dd1690f..7a964ba99 100644 --- a/share/functions/__fish_cursor_xterm.fish +++ b/share/functions/__fish_cursor_xterm.fish @@ -1,16 +1,16 @@ function __fish_cursor_xterm -d 'Set cursor (xterm)' - set -l shape $argv[1] + set -l shape $argv[1] - switch "$shape" - case block - set shape 2 - case underscore - set shape 4 - case line - set shape 6 - end - if contains blink $argv - set shape (math $shape - 1) - end - echo -en "\e[$shape q" + switch "$shape" + case block + set shape 2 + case underscore + set shape 4 + case line + set shape 6 + end + if contains blink $argv + set shape (math $shape - 1) + end + echo -en "\e[$shape q" end diff --git a/share/functions/__fish_describe_command.fish b/share/functions/__fish_describe_command.fish index 76971e739..df2efc8d5 100644 --- a/share/functions/__fish_describe_command.fish +++ b/share/functions/__fish_describe_command.fish @@ -3,7 +3,7 @@ # function __fish_describe_command -d "Command used to find descriptions for commands" - apropos $argv ^/dev/null | awk -v FS=" +- +" '{ + apropos $argv ^/dev/null | awk -v FS=" +- +" '{ split($1, names, ", "); for (name in names) if (names[name] ~ /^'"$argv"'.* *\([18]\)/ ) { diff --git a/share/functions/__fish_filter_ant_targets.fish b/share/functions/__fish_filter_ant_targets.fish index 28ce2eb11..242cdb0bc 100644 --- a/share/functions/__fish_filter_ant_targets.fish +++ b/share/functions/__fish_filter_ant_targets.fish @@ -1,3 +1,3 @@ function __fish_filter_ant_targets -d "Display targets within an ant build.xml file" - sed -n "s/^.*]* name=[\"']\([^\"']*\)[\"'].*\$/\1/p" < $argv[1] + sed -n "s/^.*]* name=[\"']\([^\"']*\)[\"'].*\$/\1/p" <$argv[1] end diff --git a/share/functions/__fish_git_prompt.fish b/share/functions/__fish_git_prompt.fish index e1ea3476d..46ce5b62f 100644 --- a/share/functions/__fish_git_prompt.fish +++ b/share/functions/__fish_git_prompt.fish @@ -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 diff --git a/share/functions/__fish_gnu_complete.fish b/share/functions/__fish_gnu_complete.fish index 62e6dde3e..2fa60edaf 100644 --- a/share/functions/__fish_gnu_complete.fish +++ b/share/functions/__fish_gnu_complete.fish @@ -1,52 +1,52 @@ function __fish_gnu_complete -d "Wrapper for the complete built-in. Skips the long completions on non-GNU systems" - set is_gnu 0 + set is_gnu 0 - set -l argv_out + set -l argv_out - # Check if we are using a gnu system - for i in $argv - switch $i + # Check if we are using a gnu system + for i in $argv + switch $i - case -g --is-gnu - set is_gnu 1 + case -g --is-gnu + set is_gnu 1 - case '*' - set argv_out $argv_out $i - end - end + case '*' + set argv_out $argv_out $i + end + end - set argv $argv_out - set argv_out - set -l skip_next 0 + set argv $argv_out + set argv_out + set -l skip_next 0 - # Remove long option if not on a gnu system - switch $is_gnu - case 0 - for i in $argv + # Remove long option if not on a gnu system + switch $is_gnu + case 0 + for i in $argv - switch $skip_next + switch $skip_next - case 1 - set skip_next 0 - continue + case 1 + set skip_next 0 + continue - end + end - switch $i + switch $i - case -l --long - set skip_next 1 - continue + case -l --long + set skip_next 1 + continue - end + end - set argv_out $argv_out $i - end - set argv $argv_out + set argv_out $argv_out $i + end + set argv $argv_out - end + end - complete $argv + complete $argv end diff --git a/share/functions/__fish_hg_prompt.fish b/share/functions/__fish_hg_prompt.fish index b40e70a24..831f37e47 100644 --- a/share/functions/__fish_hg_prompt.fish +++ b/share/functions/__fish_hg_prompt.fish @@ -23,7 +23,7 @@ set -g fish_prompt_hg_status_order added modified copied deleted untracked unmer function __fish_hg_prompt --description 'Write out the hg prompt' # If hg isn't installed, there's nothing we can do # Return 1 so the calling prompt can deal with it - if not command -s hg > /dev/null + if not command -s hg >/dev/null return 1 end @@ -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 diff --git a/share/functions/__fish_is_first_token.fish b/share/functions/__fish_is_first_token.fish index 6f943ea78..70aeb7951 100644 --- a/share/functions/__fish_is_first_token.fish +++ b/share/functions/__fish_is_first_token.fish @@ -1,15 +1,16 @@ function __fish_is_first_token -d 'Test if no non-switch argument has been specified yet' - set cmd (commandline -poc) - set -e cmd[1] - for i in $cmd - switch $i - case '-*' + set cmd (commandline -poc) + set -e cmd[1] + for i in $cmd + switch $i + case '-*' - case '*' - return 1; - end - end - return 0 + case '*' + return 1 + + end + end + return 0 end diff --git a/share/functions/__fish_is_token_n.fish b/share/functions/__fish_is_token_n.fish index c6069bde1..eccd9ace2 100644 --- a/share/functions/__fish_is_token_n.fish +++ b/share/functions/__fish_is_token_n.fish @@ -1,5 +1,5 @@ function __fish_is_token_n --description 'Test if current token is on Nth place' --argument n - # Add a fake element to increment without calling math - set -l num (count (commandline -poc) additionalelement) - test $n -eq $num + # Add a fake element to increment without calling math + set -l num (count (commandline -poc) additionalelement) + test $n -eq $num end diff --git a/share/functions/__fish_make_completion_signals.fish b/share/functions/__fish_make_completion_signals.fish index e9dabf77c..2dd88ac47 100644 --- a/share/functions/__fish_make_completion_signals.fish +++ b/share/functions/__fish_make_completion_signals.fish @@ -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) @@ -24,7 +25,7 @@ function __fish_make_completion_signals --description 'Make list of kill signals set -g __kill_signals kill -L | sed -e 's/^ //; s/ */ /g; y/ /\n/' | while read -l signo test -z "$signo" - and break # the sed above produces one blank line at the end + and break # the sed above produces one blank line at the end read -l signame set -g __kill_signals $__kill_signals "$signo $signame" end diff --git a/share/functions/__fish_man_page.fish b/share/functions/__fish_man_page.fish index 17a903153..718a93c06 100644 --- a/share/functions/__fish_man_page.fish +++ b/share/functions/__fish_man_page.fish @@ -1,4 +1,4 @@ function __fish_man_page - man (basename (commandline -po; echo)[1]) ^/dev/null - or printf \a + man (basename (commandline -po; echo)[1]) ^/dev/null + or printf \a end diff --git a/share/functions/__fish_move_last.fish b/share/functions/__fish_move_last.fish index 4646561f8..b9c57d805 100644 --- a/share/functions/__fish_move_last.fish +++ b/share/functions/__fish_move_last.fish @@ -1,27 +1,27 @@ function __fish_move_last -d "Move the last element of a directory history from src to dest" - set -l src $argv[1] - set -l dest $argv[2] + set -l src $argv[1] + set -l dest $argv[2] - set -l size_src (count $$src) + set -l size_src (count $$src) - if test $size_src = 0 - # Cannot make this step - printf (_ "Hit end of history…\n") - return 1 - end + if test $size_src = 0 + # Cannot make this step + printf (_ "Hit end of history…\n") + return 1 + end - # Append current dir to the end of the destination - set -g (echo $dest) $$dest (command pwd) + # Append current dir to the end of the destination + set -g (echo $dest) $$dest (command pwd) - set ssrc $$src + set ssrc $$src - # Change dir to the last entry in the source dir-hist - builtin cd $ssrc[$size_src] + # Change dir to the last entry in the source dir-hist + builtin cd $ssrc[$size_src] - # Keep all but the last from the source dir-hist - set -e (echo $src)\[$size_src] + # Keep all but the last from the source dir-hist + set -e (echo $src)\[$size_src] - # All ok, return success - return 0 + # All ok, return success + return 0 end diff --git a/share/functions/__fish_no_arguments.fish b/share/functions/__fish_no_arguments.fish index b2ce27814..cb21fcf96 100644 --- a/share/functions/__fish_no_arguments.fish +++ b/share/functions/__fish_no_arguments.fish @@ -1,15 +1,15 @@ function __fish_no_arguments -d "Internal fish function" - set -l cmd (commandline -poc) (commandline -tc) - set -e cmd[1] - for i in $cmd - switch $i - case '-*' + set -l cmd (commandline -poc) (commandline -tc) + set -e cmd[1] + for i in $cmd + switch $i + case '-*' - case '*' - return 1 - end - end - return 0 + case '*' + return 1 + end + end + return 0 end diff --git a/share/functions/__fish_not_contain_opt.fish b/share/functions/__fish_not_contain_opt.fish index da8d029c7..933e5eec7 100644 --- a/share/functions/__fish_not_contain_opt.fish +++ b/share/functions/__fish_not_contain_opt.fish @@ -1,51 +1,51 @@ function __fish_not_contain_opt -d "Checks that a specific option is not in the current command line" - set -l next_short + set -l next_short - set -l short_opt - set -l long_opt + set -l short_opt + set -l long_opt - for i in $argv - if test $next_short - set next_short - set short_opt $short_opt $i - else - switch $i - case -s - set next_short 1 - case '-*' - echo __fish_contains_opt: Unknown option $i - return 1 + for i in $argv + if test $next_short + set next_short + set short_opt $short_opt $i + else + switch $i + case -s + set next_short 1 + case '-*' + echo __fish_contains_opt: Unknown option $i + return 1 - case '**' - set long_opt $long_opt $i - end - end - end + case '**' + set long_opt $long_opt $i + end + end + end - for i in $short_opt + for i in $short_opt - if test -z $i - continue - end + if test -z $i + continue + end - if commandline -cpo | __fish_sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null - return 1 - end + if commandline -cpo | __fish_sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null + return 1 + end - if commandline -ct | __fish_sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null - return 1 - end - end + if commandline -ct | __fish_sgrep -- "^-"$i"\|^-[^-]*"$i >/dev/null + return 1 + end + end - for i in $long_opt - if test -z $i - continue - end + for i in $long_opt + if test -z $i + continue + end - if contains -- --$i (commandline -cpo) - return 1 - end - end + if contains -- --$i (commandline -cpo) + return 1 + end + end - return 0 + return 0 end diff --git a/share/functions/__fish_paginate.fish b/share/functions/__fish_paginate.fish index 31cdd61fa..95390ac53 100644 --- a/share/functions/__fish_paginate.fish +++ b/share/functions/__fish_paginate.fish @@ -1,13 +1,13 @@ function __fish_paginate -d "Paginate the current command using the users default pager" - set -l cmd less - if set -q PAGER - set cmd $PAGER - end + set -l cmd less + if set -q PAGER + set cmd $PAGER + end - if commandline -j| string match -q -r -v "$cmd *\$" + if commandline -j | string match -q -r -v "$cmd *\$" - commandline -aj " ^&1 |$cmd;" - end + commandline -aj " ^&1 |$cmd;" + end end diff --git a/share/functions/__fish_ports_dirs.fish b/share/functions/__fish_ports_dirs.fish index 969569f95..f4d3dc3bf 100644 --- a/share/functions/__fish_ports_dirs.fish +++ b/share/functions/__fish_ports_dirs.fish @@ -1,5 +1,5 @@ # a function to print a list of ports local collections function __fish_ports_dirs -d 'Obtain a list of ports local collections' - ls /usr/ports + ls /usr/ports end diff --git a/share/functions/__fish_print_abook_emails.fish b/share/functions/__fish_print_abook_emails.fish index f32b2aed6..671dbb50e 100644 --- a/share/functions/__fish_print_abook_emails.fish +++ b/share/functions/__fish_print_abook_emails.fish @@ -1,4 +1,4 @@ function __fish_print_abook_emails --description 'Print email addresses (abook)' - abook --mutt-query "" | string match -r -v '^\s*$' + abook --mutt-query "" | string match -r -v '^\s*$' end diff --git a/share/functions/__fish_print_addresses.fish b/share/functions/__fish_print_addresses.fish index fd8c60351..ddc9ef5c1 100644 --- a/share/functions/__fish_print_addresses.fish +++ b/share/functions/__fish_print_addresses.fish @@ -1,11 +1,11 @@ function __fish_print_addresses --description "Print a list of known network addresses" - if command -s ip >/dev/null - command ip --oneline address | cut -d" " -f7 | sed "s:\(.*\)/.*:\1:" - else if command -s ifconfig >/dev/null - # This is for OSX/BSD - # There's also linux ifconfig but that has at least two different output formats - # is basically dead, and ip is installed on everything now - ifconfig | awk '/^\tinet/ { print $2 } ' - end + if command -s ip >/dev/null + command ip --oneline address | cut -d" " -f7 | sed "s:\(.*\)/.*:\1:" + else if command -s ifconfig >/dev/null + # This is for OSX/BSD + # There's also linux ifconfig but that has at least two different output formats + # is basically dead, and ip is installed on everything now + ifconfig | awk '/^\tinet/ { print $2 } ' + end end diff --git a/share/functions/__fish_print_arch_daemons.fish b/share/functions/__fish_print_arch_daemons.fish index 681a9546d..3a683c149 100644 --- a/share/functions/__fish_print_arch_daemons.fish +++ b/share/functions/__fish_print_arch_daemons.fish @@ -1,4 +1,4 @@ function __fish_print_arch_daemons --description 'Print arch daemons' - find /etc/rc.d/ -executable -type f -printf '%f\n' + find /etc/rc.d/ -executable -type f -printf '%f\n' end diff --git a/share/functions/__fish_print_debian_apache_confs.fish b/share/functions/__fish_print_debian_apache_confs.fish index c593bc999..39d732e19 100644 --- a/share/functions/__fish_print_debian_apache_confs.fish +++ b/share/functions/__fish_print_debian_apache_confs.fish @@ -1,6 +1,6 @@ function __fish_print_debian_apache_confs - # Helper script for completions for a2enconf/a2disconf - for conf in /etc/apache2/conf-available/*.conf - basename "$conf" .conf - end + # Helper script for completions for a2enconf/a2disconf + for conf in /etc/apache2/conf-available/*.conf + basename "$conf" .conf + end end diff --git a/share/functions/__fish_print_debian_apache_mods.fish b/share/functions/__fish_print_debian_apache_mods.fish index 4e41623ac..36a1fb984 100644 --- a/share/functions/__fish_print_debian_apache_mods.fish +++ b/share/functions/__fish_print_debian_apache_mods.fish @@ -1,6 +1,6 @@ function __fish_print_debian_apache_mods - # Helper script for completions for a2enmod/a2dismod - for mod in /etc/apache2/mods-available/*.load - basename "$mod" .load - end + # Helper script for completions for a2enmod/a2dismod + for mod in /etc/apache2/mods-available/*.load + basename "$mod" .load + end end diff --git a/share/functions/__fish_print_debian_apache_sites.fish b/share/functions/__fish_print_debian_apache_sites.fish index 08436a3ef..d3f1bbe37 100644 --- a/share/functions/__fish_print_debian_apache_sites.fish +++ b/share/functions/__fish_print_debian_apache_sites.fish @@ -1,6 +1,6 @@ function __fish_print_debian_apache_sites - # Helper script for completions for a2ensite/a2dissite - for site in /etc/apache2/sites-available/* - basename "$site" .conf - end + # Helper script for completions for a2ensite/a2dissite + for site in /etc/apache2/sites-available/* + basename "$site" .conf + end end diff --git a/share/functions/__fish_print_debian_services.fish b/share/functions/__fish_print_debian_services.fish index 378e6e39b..394c1e850 100644 --- a/share/functions/__fish_print_debian_services.fish +++ b/share/functions/__fish_print_debian_services.fish @@ -1,7 +1,7 @@ function __fish_print_debian_services --description 'Prints services installed' - for service in /etc/init.d/* - if [ -x $service ] - basename $service + for service in /etc/init.d/* + if [ -x $service ] + basename $service + end end - end end diff --git a/share/functions/__fish_print_encodings.fish b/share/functions/__fish_print_encodings.fish index 5770330b4..f5507d882 100644 --- a/share/functions/__fish_print_encodings.fish +++ b/share/functions/__fish_print_encodings.fish @@ -1,3 +1,3 @@ function __fish_print_encodings -d "Complete using available character encodings" - iconv --list|sed -e 's|//||' + iconv --list | sed -e 's|//||' end diff --git a/share/functions/__fish_print_filesystems.fish b/share/functions/__fish_print_filesystems.fish index c08a6da89..8dbadc7f4 100644 --- a/share/functions/__fish_print_filesystems.fish +++ b/share/functions/__fish_print_filesystems.fish @@ -1,9 +1,9 @@ function __fish_print_filesystems -d "Print a list of all known filesystem types" - set -l fs adfs affs autofs coda coherent cramfs devpts efs ext ext2 ext3 - set fs $fs hfs hpfs iso9660 jfs minix msdos ncpfs nfs ntfs proc qnx4 ramfs - set fs $fs reiserfs romfs smbfs sysv tmpfs udf ufs umsdos vfat xenix xfs xiafs - # Mount has helper binaries to mount filesystems - # These are called mount.* and are placed somewhere in $PATH - printf "%s\n" $fs (string replace -ra ".*/mount." "" -- $PATH/mount.*) + set -l fs adfs affs autofs coda coherent cramfs devpts efs ext ext2 ext3 + set fs $fs hfs hpfs iso9660 jfs minix msdos ncpfs nfs ntfs proc qnx4 ramfs + set fs $fs reiserfs romfs smbfs sysv tmpfs udf ufs umsdos vfat xenix xfs xiafs + # Mount has helper binaries to mount filesystems + # These are called mount.* and are placed somewhere in $PATH + printf "%s\n" $fs (string replace -ra ".*/mount." "" -- $PATH/mount.*) end diff --git a/share/functions/__fish_print_function_prototypes.fish b/share/functions/__fish_print_function_prototypes.fish index 148713523..862b8dcc9 100644 --- a/share/functions/__fish_print_function_prototypes.fish +++ b/share/functions/__fish_print_function_prototypes.fish @@ -1,5 +1,5 @@ function __fish_print_function_prototypes -d "Prints the names of all function prototypes found in the headers in the current directory" - cat *.h*|sed -n "s/^\(.*[^[a-zA-Z_0-9]\|\)\([a-zA-Z_][a-zA-Z_0-9]*\) *(.*);.*\$/\2/p" + cat *.h* | sed -n "s/^\(.*[^[a-zA-Z_0-9]\|\)\([a-zA-Z_][a-zA-Z_0-9]*\) *(.*);.*\$/\2/p" end diff --git a/share/functions/__fish_print_hostnames.fish b/share/functions/__fish_print_hostnames.fish index 7c7a28a81..2f192c93a 100644 --- a/share/functions/__fish_print_hostnames.fish +++ b/share/functions/__fish_print_hostnames.fish @@ -1,41 +1,39 @@ function __fish_print_hostnames -d "Print a list of known hostnames" - # HACK: This only deals with ipv4 + # HACK: This only deals with ipv4 - # 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 - # Ignore zero ips - 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' - end - - # Print nfs servers from /etc/fstab - if test -r /etc/fstab - string match -r '^\s*[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3]:|^[a-zA-Z\.]*:' /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 " " + else if test -r /etc/hosts + # Ignore commented lines and functionally empty lines + string match -r -v '^\s*0.0.0.0|^\s*#|^\s*$' /dev/null | string replace -r ':.*' '' + ninja -t targets 2>/dev/null | string replace -r ':.*' '' end end diff --git a/share/functions/__fish_print_packages.fish b/share/functions/__fish_print_packages.fish index a6b84b475..1dc0893c4 100644 --- a/share/functions/__fish_print_packages.fish +++ b/share/functions/__fish_print_packages.fish @@ -1,139 +1,139 @@ function __fish_print_packages - # apt-cache is much, much faster than rpm, and can do this in real - # time. We use it if available. + # apt-cache is much, much faster than rpm, and can do this in real + # time. We use it if available. - switch (commandline -tc) - case '-**' - return - end + switch (commandline -tc) + case '-**' + return + end - #Get the word 'Package' in the current language - set -l package (_ Package) + #Get the word 'Package' in the current language + set -l package (_ Package) - # Set up cache directory - if test -z "$XDG_CACHE_HOME" - set XDG_CACHE_HOME $HOME/.cache - end - mkdir -m 700 -p $XDG_CACHE_HOME + # Set up cache directory + if test -z "$XDG_CACHE_HOME" + set XDG_CACHE_HOME $HOME/.cache + end + mkdir -m 700 -p $XDG_CACHE_HOME - if type -q -f apt-cache - # Do not generate the cache as apparently sometimes this is slow. - # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=547550 - apt-cache --no-generate pkgnames (commandline -tc) ^/dev/null | sed -e 's/$/'\t$package'/' - return - end + if type -q -f apt-cache + # Do not generate the cache as apparently sometimes this is slow. + # http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=547550 + apt-cache --no-generate pkgnames (commandline -tc) ^/dev/null | sed -e 's/$/'\t$package'/' + return + end - # Pkg is fast on FreeBSD and provides versioning info which we want for - # installed packages - if begin - type -q -f pkg - and test (uname) = "FreeBSD" - end - pkg query "%n-%v" - return - end + # Pkg is fast on FreeBSD and provides versioning info which we want for + # installed packages + if begin + type -q -f pkg + and test (uname) = "FreeBSD" + end + pkg query "%n-%v" + return + end # Caches for 5 minutes - if type -q -f pacman - set cache_file $XDG_CACHE_HOME/.pac-cache.$USER - if test -f $cache_file - cat $cache_file - set age (math (date +%s) - (stat -c '%Y' $cache_file)) - set max_age 250 - if test $age -lt $max_age - return - end - end + if type -q -f pacman + set cache_file $XDG_CACHE_HOME/.pac-cache.$USER + if test -f $cache_file + cat $cache_file + set age (math (date +%s) - (stat -c '%Y' $cache_file)) + set max_age 250 + if test $age -lt $max_age + return + end + end - # prints: Package - pacman -Ssq | sed -e 's/$/\t'$package'/' >$cache_file & - return - end + # prints: Package + pacman -Ssq | sed -e 's/$/\t'$package'/' >$cache_file & + return + end - # Zypper needs caching as it is slow - if type -q -f zypper - # Use libzypp cache file if available - if test -f /var/cache/zypp/solv/@System/solv.idx - cat /var/cache/zypp/solv/*/solv.idx | awk '!/application:|srcpackage:|product:|pattern:|patch:/ {print $1'\t$package'}' - return - end + # Zypper needs caching as it is slow + if type -q -f zypper + # Use libzypp cache file if available + if test -f /var/cache/zypp/solv/@System/solv.idx + cat /var/cache/zypp/solv/*/solv.idx | awk '!/application:|srcpackage:|product:|pattern:|patch:/ {print $1'\t$package'}' + return + end - # If the cache is less than five minutes old, we do not recalculate it + # If the cache is less than five minutes old, we do not recalculate it - set -l cache_file $XDG_CACHE_HOME/.zypper-cache.$USER - if test -f $cache_file - cat $cache_file - set -l age (math (date +%s) - (stat -c '%Y' $cache_file)) - set -l max_age 300 - if test $age -lt $max_age - return - end - end + set -l cache_file $XDG_CACHE_HOME/.zypper-cache.$USER + if test -f $cache_file + cat $cache_file + set -l age (math (date +%s) - (stat -c '%Y' $cache_file)) + set -l max_age 300 + if test $age -lt $max_age + return + end + end - # Remove package version information from output and pipe into cache file - zypper --quiet --non-interactive search --type=package | tail -n +4 | sed -r 's/^. \| ((\w|[-_.])+).*/\1\t'$package'/g' > $cache_file & - return - end + # Remove package version information from output and pipe into cache file + zypper --quiet --non-interactive search --type=package | tail -n +4 | sed -r 's/^. \| ((\w|[-_.])+).*/\1\t'$package'/g' >$cache_file & + return + end - # yum is slow, just like rpm, so go to the background - if type -q -f /usr/share/yum-cli/completion-helper.py + # yum is slow, just like rpm, so go to the background + if type -q -f /usr/share/yum-cli/completion-helper.py - # If the cache is less than six hours old, we do not recalculate it + # If the cache is less than six hours old, we do not recalculate it - set cache_file $XDG_CACHE_HOME/.yum-cache.$USER - if test -f $cache_file - cat $cache_file - set age (math (date +%s) - (stat -c '%Y' $cache_file)) - set max_age 21600 - if test $age -lt $max_age - return - end - end + set cache_file $XDG_CACHE_HOME/.yum-cache.$USER + if test -f $cache_file + cat $cache_file + set age (math (date +%s) - (stat -c '%Y' $cache_file)) + set max_age 21600 + if test $age -lt $max_age + return + end + end - # Remove package version information from output and pipe into cache file - /usr/share/yum-cli/completion-helper.py list all -d 0 -C | sed "s/\..*/\t$package/" >$cache_file & - return - end + # Remove package version information from output and pipe into cache file + /usr/share/yum-cli/completion-helper.py list all -d 0 -C | sed "s/\..*/\t$package/" >$cache_file & + return + end - # Rpm is too slow for this job, so we set it up to do completions - # as a background job and cache the results. + # Rpm is too slow for this job, so we set it up to do completions + # as a background job and cache the results. - if type -q -f rpm + if type -q -f rpm - # If the cache is less than five minutes old, we do not recalculate it + # If the cache is less than five minutes old, we do not recalculate it - set cache_file $XDG_CACHE_HOME/.rpm-cache.$USER - if test -f $cache_file - cat $cache_file - set age (math (date +%s) - (stat -c '%Y' $cache_file)) - set max_age 250 - if test $age -lt $max_age - return - end - end + set cache_file $XDG_CACHE_HOME/.rpm-cache.$USER + if test -f $cache_file + cat $cache_file + set age (math (date +%s) - (stat -c '%Y' $cache_file)) + set max_age 250 + if test $age -lt $max_age + return + end + end - # Remove package version information from output and pipe into cache file - rpm -qa |sed -e 's/-[^-]*-[^-]*$/\t'$package'/' >$cache_file & - return - end + # Remove package version information from output and pipe into cache file + rpm -qa | sed -e 's/-[^-]*-[^-]*$/\t'$package'/' >$cache_file & + return + end - # This completes the package name from the portage tree. - # True for installing new packages. Function for printing - # installed on the system packages is in completions/emerge.fish + # This completes the package name from the portage tree. + # True for installing new packages. Function for printing + # installed on the system packages is in completions/emerge.fish - # eix is MUCH faster than emerge so use it if it is available - if type -q -f eix - eix --only-names "^"(commandline -tc) | cut -d/ -f2 - return - else - # FIXME? Seems to be broken - if type -q -f emerge - emerge -s \^(commandline -tc) | __fish_sgrep "^*" |cut -d\ -f3 |cut -d/ -f2 - return - end - end + # eix is MUCH faster than emerge so use it if it is available + if type -q -f eix + eix --only-names "^"(commandline -tc) | cut -d/ -f2 + return + else + # FIXME? Seems to be broken + if type -q -f emerge + emerge -s \^(commandline -tc) | __fish_sgrep "^*" | cut -d\ -f3 | cut -d/ -f2 + return + end + end end diff --git a/share/functions/__fish_print_pacman_repos.fish b/share/functions/__fish_print_pacman_repos.fish index 1998f7216..92d4919af 100644 --- a/share/functions/__fish_print_pacman_repos.fish +++ b/share/functions/__fish_print_pacman_repos.fish @@ -1,3 +1,3 @@ function __fish_print_pacman_repos --description "Print the repositories configured for arch's pacman package manager" - string replace -r -a "\[(.+)\]" "\1" < /etc/pacman.conf | string match -r -v "^#|options" + string replace -r -a "\[(.+)\]" "\1" /dev/null - return 1 - end + # if svn isn't installed then don't do anything + if not command -s svn >/dev/null + return 1 + end - # make sure that this is a svn repo - set -l checkout_info (command svn info ^/dev/null) - if [ $status -ne 0 ]; - return - end + # make sure that this is a svn repo + set -l checkout_info (command svn info ^/dev/null) + if [ $status -ne 0 ] - # get the current revision number - printf '(%s%s%s' (set_color $__fish_svn_prompt_color_revision) (__fish_print_svn_rev) (set_color normal) + return + end - # resolve the status of the checkout - # 1. perform `svn status` - # 2. remove extra lines that aren't necessary - # 3. cut the output down to the first 7 columns, as these contain the information needed - set -l svn_status_lines (command svn status | sed -e 's=^Summary of conflicts.*==' -e 's=^ Text conflicts.*==' -e 's=^ Property conflicts.*==' -e 's=^ Tree conflicts.*==' -e 's=.*incoming .* upon update.*==' | cut -c 1-7) + # get the current revision number + printf '(%s%s%s' (set_color $__fish_svn_prompt_color_revision) (__fish_print_svn_rev) (set_color normal) - # track the last column to contain a status flag - set -l last_column 0 + # resolve the status of the checkout + # 1. perform `svn status` + # 2. remove extra lines that aren't necessary + # 3. cut the output down to the first 7 columns, as these contain the information needed + set -l svn_status_lines (command svn status | sed -e 's=^Summary of conflicts.*==' -e 's=^ Text conflicts.*==' -e 's=^ Property conflicts.*==' -e 's=^ Tree conflicts.*==' -e 's=.*incoming .* upon update.*==' | cut -c 1-7) - # iterate over the 7 columns of output (the 7 columns are defined on `svn help status`) - for col in (seq 7) - # get the output for a particular column - # 1. echo the whole status flag text - # 2. cut out the current column of characters - # 3. remove spaces and newline characters - set -l column_status (printf '%s\n' $svn_status_lines | cut -c $col | tr -d ' \n') + # track the last column to contain a status flag + set -l last_column 0 - # 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 ]; - # 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 - set -l svn_status_flags (__fish_svn_prompt_parse_status $column_unique_status) + # iterate over the 7 columns of output (the 7 columns are defined on `svn help status`) + for col in (seq 7) + # get the output for a particular column + # 1. echo the whole status flag text + # 2. cut out the current column of characters + # 3. remove spaces and newline characters + set -l column_status (printf '%s\n' $svn_status_lines | cut -c $col | tr -d ' \n') - # the default separator is empty - set -l prompt_separator "" - for index in (seq (math "$col - $last_column")) - # the prompt separator variable has to be updated with the number of separators needed to represent empty status columns (eg: if a file has the status "A +" then it should display as "A|||+" in the prompt) - set prompt_separator $prompt_separator$__fish_svn_prompt_char_separator - end + # 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 ] - # record that the current column was the last one printed to the prompt - set last_column $col - # print the separator string then the current column's status flags - printf '%s%s' $prompt_separator $svn_status_flags - end - end + # 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 + set -l svn_status_flags (__fish_svn_prompt_parse_status $column_unique_status) - # print the close of the svn status prompt - printf ')' + # the default separator is empty + set -l prompt_separator "" + for index in (seq (math "$col - $last_column")) + # the prompt separator variable has to be updated with the number of separators needed to represent empty status columns (eg: if a file has the status "A +" then it should display as "A|||+" in the prompt) + set prompt_separator $prompt_separator$__fish_svn_prompt_char_separator + end + + # record that the current column was the last one printed to the prompt + set last_column $col + # print the separator string then the current column's status flags + printf '%s%s' $prompt_separator $svn_status_flags + end + end + + # print the close of the svn status prompt + printf ')' end \ No newline at end of file diff --git a/share/functions/__fish_systemctl_automounts.fish b/share/functions/__fish_systemctl_automounts.fish index 614412293..e62b8afc5 100644 --- a/share/functions/__fish_systemctl_automounts.fish +++ b/share/functions/__fish_systemctl_automounts.fish @@ -1,9 +1,9 @@ function __fish_systemctl_automounts - if type -q systemctl - if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=automount ^/dev/null | cut -f 1 -d ' ' - else - systemctl list-unit-files --no-legend --type=automount ^/dev/null | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + systemctl --user list-unit-files --no-legend --type=automount ^/dev/null | cut -f 1 -d ' ' + else + systemctl list-unit-files --no-legend --type=automount ^/dev/null | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_devices.fish b/share/functions/__fish_systemctl_devices.fish index bad24a19f..082e65d7d 100644 --- a/share/functions/__fish_systemctl_devices.fish +++ b/share/functions/__fish_systemctl_devices.fish @@ -1,11 +1,11 @@ function __fish_systemctl_devices - if type -q systemctl - if __fish_contains_opt user - # Devices are usually generated at runtime - # Therefore show known _units_, not unit-files - systemctl --user list-units --no-legend --type=device ^/dev/null | cut -f 1 -d ' ' - else - systemctl list-units --no-legend --type=device ^/dev/null | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + # Devices are usually generated at runtime + # Therefore show known _units_, not unit-files + systemctl --user list-units --no-legend --type=device ^/dev/null | cut -f 1 -d ' ' + else + systemctl list-units --no-legend --type=device ^/dev/null | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_mounts.fish b/share/functions/__fish_systemctl_mounts.fish index b3e7dd6ab..feac7b1a6 100644 --- a/share/functions/__fish_systemctl_mounts.fish +++ b/share/functions/__fish_systemctl_mounts.fish @@ -1,9 +1,9 @@ function __fish_systemctl_mounts - if type -q systemctl - if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=mount ^/dev/null | cut -f 1 -d ' ' - else - systemctl list-unit-files --no-legend --type=mount ^/dev/null | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + systemctl --user list-unit-files --no-legend --type=mount ^/dev/null | cut -f 1 -d ' ' + else + systemctl list-unit-files --no-legend --type=mount ^/dev/null | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_scopes.fish b/share/functions/__fish_systemctl_scopes.fish index f2f5cbccc..3b705718b 100644 --- a/share/functions/__fish_systemctl_scopes.fish +++ b/share/functions/__fish_systemctl_scopes.fish @@ -1,11 +1,11 @@ function __fish_systemctl_scopes - if type -q systemctl - if __fish_contains_opt user - # Scopes are usually generated at runtime - # Therefore show known _units_, not unit-files - systemctl --user list-units --no-legend --type=scope ^/dev/null | cut -f 1 -d ' ' - else - systemctl list-units --no-legend --type=scope ^/dev/null | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + # Scopes are usually generated at runtime + # Therefore show known _units_, not unit-files + systemctl --user list-units --no-legend --type=scope ^/dev/null | cut -f 1 -d ' ' + else + systemctl list-units --no-legend --type=scope ^/dev/null | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_service_paths.fish b/share/functions/__fish_systemctl_service_paths.fish index 5691ee0d0..5208bf8ba 100644 --- a/share/functions/__fish_systemctl_service_paths.fish +++ b/share/functions/__fish_systemctl_service_paths.fish @@ -1,9 +1,9 @@ function __fish_systemctl_service_paths - if type -q systemctl - if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=path ^/dev/null $argv | cut -f 1 -d ' ' - else - systemctl list-unit-files --no-legend --type=path ^/dev/null $argv | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + systemctl --user list-unit-files --no-legend --type=path ^/dev/null $argv | cut -f 1 -d ' ' + else + systemctl list-unit-files --no-legend --type=path ^/dev/null $argv | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_services.fish b/share/functions/__fish_systemctl_services.fish index ae779828c..c80f7333d 100644 --- a/share/functions/__fish_systemctl_services.fish +++ b/share/functions/__fish_systemctl_services.fish @@ -1,13 +1,13 @@ function __fish_systemctl_services - if type -q systemctl - if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=service ^/dev/null $argv | cut -f 1 -d ' ' - systemctl --user list-units --state=loaded --no-legend --type=service ^/dev/null | cut -f 1 -d ' ' - else - # list-unit-files will also show disabled units - systemctl list-unit-files --no-legend --type=service ^/dev/null $argv | cut -f 1 -d ' ' - # list-units will not show disabled units but will show instances (like wpa_supplicant@wlan0.service) - systemctl list-units --state=loaded --no-legend --type=service ^/dev/null | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + systemctl --user list-unit-files --no-legend --type=service ^/dev/null $argv | cut -f 1 -d ' ' + systemctl --user list-units --state=loaded --no-legend --type=service ^/dev/null | cut -f 1 -d ' ' + else + # list-unit-files will also show disabled units + systemctl list-unit-files --no-legend --type=service ^/dev/null $argv | cut -f 1 -d ' ' + # list-units will not show disabled units but will show instances (like wpa_supplicant@wlan0.service) + systemctl list-units --state=loaded --no-legend --type=service ^/dev/null | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_slices.fish b/share/functions/__fish_systemctl_slices.fish index 40628f98d..4d8ddf6dc 100644 --- a/share/functions/__fish_systemctl_slices.fish +++ b/share/functions/__fish_systemctl_slices.fish @@ -1,11 +1,11 @@ function __fish_systemctl_slices - if type -q systemctl - if __fish_contains_opt user - # Slices are usually generated at runtime - # Therefore show known _units_, not unit-files - systemctl --user list-units --no-legend --type=slice ^/dev/null | cut -f 1 -d ' ' - else - systemctl list-units --no-legend --type=slice ^/dev/null | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + # Slices are usually generated at runtime + # Therefore show known _units_, not unit-files + systemctl --user list-units --no-legend --type=slice ^/dev/null | cut -f 1 -d ' ' + else + systemctl list-units --no-legend --type=slice ^/dev/null | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_snapshots.fish b/share/functions/__fish_systemctl_snapshots.fish index 7b6cb5ee9..7017d8075 100644 --- a/share/functions/__fish_systemctl_snapshots.fish +++ b/share/functions/__fish_systemctl_snapshots.fish @@ -1,12 +1,12 @@ function __fish_systemctl_snapshots - if type -q systemctl - if __fish_contains_opt user - # Snapshots are usually generated at runtime - # Therefore show known _units_, not unit-files - # They are also often not loaded, so add "--all" - systemctl --user list-units --all --no-legend --type=snapshot ^/dev/null | cut -f 1 -d ' ' - else - systemctl list-units --all --no-legend --type=snapshot ^/dev/null | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + # Snapshots are usually generated at runtime + # Therefore show known _units_, not unit-files + # They are also often not loaded, so add "--all" + systemctl --user list-units --all --no-legend --type=snapshot ^/dev/null | cut -f 1 -d ' ' + else + systemctl list-units --all --no-legend --type=snapshot ^/dev/null | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_sockets.fish b/share/functions/__fish_systemctl_sockets.fish index d45dfc1b3..5358eaf4c 100644 --- a/share/functions/__fish_systemctl_sockets.fish +++ b/share/functions/__fish_systemctl_sockets.fish @@ -1,9 +1,9 @@ function __fish_systemctl_sockets - if type -q systemctl - if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=socket ^/dev/null $argv | cut -f 1 -d ' ' - else - systemctl list-unit-files --no-legend --type=socket ^/dev/null $argv | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + systemctl --user list-unit-files --no-legend --type=socket ^/dev/null $argv | cut -f 1 -d ' ' + else + systemctl list-unit-files --no-legend --type=socket ^/dev/null $argv | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_swaps.fish b/share/functions/__fish_systemctl_swaps.fish index 57df43676..91547f752 100644 --- a/share/functions/__fish_systemctl_swaps.fish +++ b/share/functions/__fish_systemctl_swaps.fish @@ -1,9 +1,9 @@ function __fish_systemctl_swaps - if type -q systemctl - if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=swap ^/dev/null | cut -f 1 -d ' ' - else - systemctl list-unit-files --no-legend --type=swap ^/dev/null | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + systemctl --user list-unit-files --no-legend --type=swap ^/dev/null | cut -f 1 -d ' ' + else + systemctl list-unit-files --no-legend --type=swap ^/dev/null | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_targets.fish b/share/functions/__fish_systemctl_targets.fish index c63afdea4..d444d0cb6 100644 --- a/share/functions/__fish_systemctl_targets.fish +++ b/share/functions/__fish_systemctl_targets.fish @@ -1,9 +1,9 @@ function __fish_systemctl_targets - if type -q systemctl - if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=target ^/dev/null | cut -f 1 -d ' ' - else - systemctl list-unit-files --no-legend --type=target ^/dev/null | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + systemctl --user list-unit-files --no-legend --type=target ^/dev/null | cut -f 1 -d ' ' + else + systemctl list-unit-files --no-legend --type=target ^/dev/null | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemctl_timers.fish b/share/functions/__fish_systemctl_timers.fish index 1dea2dc18..726a7100a 100644 --- a/share/functions/__fish_systemctl_timers.fish +++ b/share/functions/__fish_systemctl_timers.fish @@ -1,9 +1,9 @@ function __fish_systemctl_timers - if type -q systemctl - if __fish_contains_opt user - systemctl --user list-unit-files --no-legend --type=timer ^/dev/null $argv | cut -f 1 -d ' ' - else - systemctl list-unit-files --no-legend --type=timer ^/dev/null $argv | cut -f 1 -d ' ' - end - end + if type -q systemctl + if __fish_contains_opt user + systemctl --user list-unit-files --no-legend --type=timer ^/dev/null $argv | cut -f 1 -d ' ' + else + systemctl list-unit-files --no-legend --type=timer ^/dev/null $argv | cut -f 1 -d ' ' + end + end end diff --git a/share/functions/__fish_systemd_machine_images.fish b/share/functions/__fish_systemd_machine_images.fish index 8ff0a69d1..c14865a0a 100644 --- a/share/functions/__fish_systemd_machine_images.fish +++ b/share/functions/__fish_systemd_machine_images.fish @@ -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 diff --git a/share/functions/__fish_systemd_machines.fish b/share/functions/__fish_systemd_machines.fish index 09becb2d3..a4ab375f7 100644 --- a/share/functions/__fish_systemd_machines.fish +++ b/share/functions/__fish_systemd_machines.fish @@ -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 diff --git a/share/functions/__fish_test_arg.fish b/share/functions/__fish_test_arg.fish index 6ebe8fb0b..695c96866 100644 --- a/share/functions/__fish_test_arg.fish +++ b/share/functions/__fish_test_arg.fish @@ -3,7 +3,7 @@ function __fish_test_arg --description "Test if the token under the cursor match switch (commandline -ct) case $argv return 0 - end + end return 1 end diff --git a/share/functions/__fish_toggle_comment_commandline.fish b/share/functions/__fish_toggle_comment_commandline.fish index 8bdd7e822..d6cba8445 100644 --- a/share/functions/__fish_toggle_comment_commandline.fish +++ b/share/functions/__fish_toggle_comment_commandline.fish @@ -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 diff --git a/share/functions/__fish_urlencode.fish b/share/functions/__fish_urlencode.fish index df07eee03..0e336813e 100644 --- a/share/functions/__fish_urlencode.fish +++ b/share/functions/__fish_urlencode.fish @@ -1,22 +1,26 @@ 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 - printf '%s' $join - # chomp off a trailing newline - if test "$chars[-1]" = \n - set -e chars[-1] - set join '%0A%00' - else - set join '%00' - end - for c in $chars - if string match -q -r '[/._~A-Za-z0-9-]' $c - printf '%s' $c - else - printf '%%%02X' "'$c" - end - end - end + 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 + printf '%s' $join + # chomp off a trailing newline + if test "$chars[-1]" = \n + set -e chars[-1] + set join '%0A%00' + else + set join '%00' + end + for c in $chars + if string match -q -r '[/._~A-Za-z0-9-]' $c + printf '%s' $c + else + printf '%%%02X' "'$c" + end + end + end end diff --git a/share/functions/__fish_use_subcommand.fish b/share/functions/__fish_use_subcommand.fish index 1ec2398b1..dd262c15f 100644 --- a/share/functions/__fish_use_subcommand.fish +++ b/share/functions/__fish_use_subcommand.fish @@ -1,14 +1,14 @@ function __fish_use_subcommand -d "Test if a non-switch argument has been given in the current commandline" - set -l cmd (commandline -poc) - set -e cmd[1] - for i in $cmd - switch $i - case '-*' - continue - end - return 1 - end - return 0 + set -l cmd (commandline -poc) + set -e cmd[1] + for i in $cmd + switch $i + case '-*' + continue + end + return 1 + end + return 0 end diff --git a/share/functions/__fish_vcs_prompt.fish b/share/functions/__fish_vcs_prompt.fish index 6695cfbaa..04101a73b 100644 --- a/share/functions/__fish_vcs_prompt.fish +++ b/share/functions/__fish_vcs_prompt.fish @@ -1,5 +1,5 @@ function __fish_vcs_prompt --description "Print the prompts for all available vcsen" - __fish_git_prompt - __fish_hg_prompt - __fish_svn_prompt + __fish_git_prompt + __fish_hg_prompt + __fish_svn_prompt end diff --git a/share/functions/__terlar_git_prompt.fish b/share/functions/__terlar_git_prompt.fish index 9b3c84a85..32ffff9e9 100644 --- a/share/functions/__terlar_git_prompt.fish +++ b/share/functions/__terlar_git_prompt.fish @@ -21,63 +21,70 @@ set -g fish_prompt_git_status_unmerged '!' set -g fish_prompt_git_status_order added modified renamed copied deleted untracked unmerged function __terlar_git_prompt --description 'Write out the git prompt' - # If git isn't installed, there's nothing we can do - # Return 1 so the calling prompt can deal with it - if not command -s git >/dev/null - return 1 - end - set -l branch (git rev-parse --abbrev-ref HEAD ^/dev/null) - if test -z $branch - return - end + # If git isn't installed, there's nothing we can do + # Return 1 so the calling prompt can deal with it + if not command -s git >/dev/null + return 1 + end + set -l branch (git rev-parse --abbrev-ref HEAD ^/dev/null) + if test -z $branch + return + end - echo -n '|' + echo -n '|' - set -l index (git status --porcelain ^/dev/null|cut -c 1-2|sort -u) + set -l index (git status --porcelain ^/dev/null|cut -c 1-2|sort -u) + + if test -z "$index" + set_color $fish_color_git_clean + echo -n $branch'✓' + set_color normal + return + end + + set -l gs + set -l staged + + for i in $index + if echo $i | grep '^[AMRCD]' >/dev/null + set staged 1 + 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 + end + end + + if set -q staged[1] + set_color $fish_color_git_staged + else + set_color $fish_color_git_dirty + end + + echo -n $branch'⚡' + + for i in $fish_prompt_git_status_order + if contains $i in $gs + set -l color_name fish_color_git_$i + set -l status_name fish_prompt_git_status_$i + + set_color $$color_name + echo -n $$status_name + end + end - if test -z "$index" - set_color $fish_color_git_clean - echo -n $branch'✓' set_color normal - return - end - - set -l gs - set -l staged - - for i in $index - if echo $i | grep '^[AMRCD]' >/dev/null - set staged 1 - 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 - end - end - - if set -q staged[1] - set_color $fish_color_git_staged - else - set_color $fish_color_git_dirty - end - - echo -n $branch'⚡' - - for i in $fish_prompt_git_status_order - if contains $i in $gs - set -l color_name fish_color_git_$i - set -l status_name fish_prompt_git_status_$i - - set_color $$color_name - echo -n $$status_name - end - end - - set_color normal end diff --git a/share/functions/abbr.fish b/share/functions/abbr.fish index cdb528aef..c3a942c13 100644 --- a/share/functions/abbr.fish +++ b/share/functions/abbr.fish @@ -1,155 +1,158 @@ function abbr --description "Manage abbreviations" - # parse arguments - set -l mode - set -l mode_flag # the flag that was specified, for better errors - set -l mode_arg - set -l needs_arg no - while set -q argv[1] - set -l new_mode - switch $argv[1] - case '-h' '--help' - __fish_print_help abbr - return 0 - case '-a' '--add' - set new_mode add - set needs_arg multi - case '-e' '--erase' - set new_mode erase - set needs_arg single - case '-l' '--list' - set new_mode list - case '-s' '--show' - set new_mode show - case '--' - set -e argv[1] - break - case '-*' - printf ( _ "%s: invalid option -- %s\n" ) abbr $argv[1] >&2 - return 1 - case '*' - break - end - if test -n "$mode" -a -n "$new_mode" - # we're trying to set two different modes - printf ( _ "%s: %s cannot be specified along with %s\n" ) abbr $argv[1] $mode_flag >&2 - return 1 - end - set mode $new_mode - set mode_flag $argv[1] - set -e argv[1] - end + # parse arguments + set -l mode + set -l mode_flag # the flag that was specified, for better errors + set -l mode_arg + set -l needs_arg no + while set -q argv[1] + set -l new_mode + switch $argv[1] + case '-h' '--help' + __fish_print_help abbr + return 0 + case '-a' '--add' + set new_mode add + set needs_arg multi + case '-e' '--erase' + set new_mode erase + set needs_arg single + case '-l' '--list' + set new_mode list + case '-s' '--show' + set new_mode show + case '--' + set -e argv[1] + break + case '-*' + printf ( _ "%s: invalid option -- %s\n" ) abbr $argv[1] >&2 + return 1 + case '*' + break + end + if test -n "$mode" -a -n "$new_mode" + # we're trying to set two different modes + printf ( _ "%s: %s cannot be specified along with %s\n" ) abbr $argv[1] $mode_flag >&2 + return 1 + end + set mode $new_mode + set mode_flag $argv[1] + set -e argv[1] + end - # If run with no options, treat it like --add if we have an argument, or - # --show if we do not have an argument - if not set -q mode[1] - if set -q argv[1] - set mode add - set needs_arg multi - else - set mode show - end - end + # If run with no options, treat it like --add if we have an argument, or + # --show if we do not have an argument + if not set -q mode[1] + if set -q argv[1] + set mode add + set needs_arg multi + else + set mode show + end + end - if test $needs_arg = single - set mode_arg $argv[1] - set needs_arg no - set -e argv[1] - else if test $needs_arg = multi - set mode_arg $argv - set needs_arg no - set -e argv - end - if test $needs_arg != no - printf ( _ "%s: option requires an argument -- %s\n" ) abbr $mode_flag >&2 - return 1 - end - - # none of our modes want any excess arguments - if set -q argv[1] - printf ( _ "%s: Unexpected argument -- %s\n" ) abbr $argv[1] >&2 - return 1 - end + if test $needs_arg = single + set mode_arg $argv[1] + set needs_arg no + set -e argv[1] + else if test $needs_arg = multi + set mode_arg $argv + set needs_arg no + set -e argv + end + if test $needs_arg != no + printf ( _ "%s: option requires an argument -- %s\n" ) abbr $mode_flag >&2 + return 1 + end - switch $mode - 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 - set mode_arg (string split "=" -- $mode_arg) - end + # none of our modes want any excess arguments + if set -q argv[1] + printf ( _ "%s: Unexpected argument -- %s\n" ) abbr $argv[1] >&2 + return 1 + end - # Bail out early if the exact abbr is already in - 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" - # Because we later store "$key $value", there can't be any spaces in the key - if string match -q "* *" -- $key - printf ( _ "%s: abbreviation cannot have spaces in the key\n" ) abbr >&2 - return 1 - end - if test -z "$value" - printf ( _ "%s: abbreviation must have a value\n" ) abbr >&2 - return 1 - end - if set -l idx (__fish_abbr_get_by_key $key) - # erase the existing abbreviation - set -e fish_user_abbreviations[$idx] - end - if not set -q fish_user_abbreviations - # initialize as a universal variable, so we can skip the -U later - # and therefore work properly if someone sets this as a global variable - set -U fish_user_abbreviations - end - set fish_user_abbreviations $fish_user_abbreviations "$key $value" - return 0 + switch $mode + 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 + set mode_arg (string split "=" -- $mode_arg) + end - case 'erase' - if set -l idx (__fish_abbr_get_by_key $mode_arg) - set -e fish_user_abbreviations[$idx] - return 0 - else - printf ( _ "%s: no such abbreviation '%s'\n" ) abbr $mode_arg >&2 - return 2 - end + # Bail out early if the exact abbr is already in + 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" + # Because we later store "$key $value", there can't be any spaces in the key + if string match -q "* *" -- $key + printf ( _ "%s: abbreviation cannot have spaces in the key\n" ) abbr >&2 + return 1 + end + if test -z "$value" + printf ( _ "%s: abbreviation must have a value\n" ) abbr >&2 + return 1 + end + if set -l idx (__fish_abbr_get_by_key $key) + # erase the existing abbreviation + set -e fish_user_abbreviations[$idx] + end + if not set -q fish_user_abbreviations + # initialize as a universal variable, so we can skip the -U later + # and therefore work properly if someone sets this as a global variable + set -U fish_user_abbreviations + end + set fish_user_abbreviations $fish_user_abbreviations "$key $value" + return 0 - case 'show' - for i in $fish_user_abbreviations - set -l opt_double_dash - set -l kv (string split " " -m 1 -- $i) - set -l key $kv[1] - set -l value $kv[2] - - # 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 '--' - echo abbr $opt_double_dash (string escape -- $key $value) - end - return 0 + case 'erase' + if set -l idx (__fish_abbr_get_by_key $mode_arg) + set -e fish_user_abbreviations[$idx] + return 0 + else + printf ( _ "%s: no such abbreviation '%s'\n" ) abbr $mode_arg >&2 + return 2 + end - case 'list' - for i in $fish_user_abbreviations - set -l key (string split " " -m 1 -- $i)[1] - printf "%s\n" $key - end - return 0 - end + case 'show' + for i in $fish_user_abbreviations + set -l opt_double_dash + set -l kv (string split " " -m 1 -- $i) + set -l key $kv[1] + set -l value $kv[2] + + # 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 '--' + echo abbr $opt_double_dash (string escape -- $key $value) + end + return 0 + + case 'list' + for i in $fish_user_abbreviations + set -l key (string split " " -m 1 -- $i)[1] + printf "%s\n" $key + end + return 0 + end end function __fish_abbr_get_by_key - if not set -q argv[1] - echo "__fish_abbr_get_by_key: expected one argument, got none" >&2 - return 2 - end - # Going through all entries is still quicker than calling `seq` - set -l keys - for kv in $fish_user_abbreviations - # If this does not match, we have screwed up before and the error should be reported - set keys $keys (string split " " -m 1 -- $kv)[1] - end - if set -l idx (contains -i -- $argv[1] $keys) - echo $idx - return 0 - end - return 1 + if not set -q argv[1] + echo "__fish_abbr_get_by_key: expected one argument, got none" >&2 + return 2 + end + # Going through all entries is still quicker than calling `seq` + set -l keys + for kv in $fish_user_abbreviations + # If this does not match, we have screwed up before and the error should be reported + set keys $keys (string split " " -m 1 -- $kv)[1] + end + if set -l idx (contains -i -- $argv[1] $keys) + echo $idx + return 0 + end + return 1 end diff --git a/share/functions/alias.fish b/share/functions/alias.fish index 41d1b7ae8..5566e2487 100644 --- a/share/functions/alias.fish +++ b/share/functions/alias.fish @@ -1,5 +1,5 @@ function alias --description 'Creates a function wrapping a command' - if count $argv > /dev/null + if count $argv >/dev/null switch $argv[1] case -h --h --he --hel --help __fish_print_help alias diff --git a/share/functions/contains_seq.fish b/share/functions/contains_seq.fish index 9fae7cacf..d3a20e1c8 100644 --- a/share/functions/contains_seq.fish +++ b/share/functions/contains_seq.fish @@ -1,46 +1,46 @@ function contains_seq --description 'Return true if array contains a sequence' - set -l printnext - switch $argv[1] - case --printnext - set printnext[1] 1 - set -e argv[1] - end - set -l pattern - set -l string - set -l dest pattern - for i in $argv - if test "$i" = -- - set dest string - continue - end - set $dest $$dest $i - end - set -l nomatch 1 - set -l i 1 - for s in $string - if set -q printnext[2] - return 0 - end - if test "$s" = "$pattern[$i]" - set -e nomatch[1] - set i (math $i + 1) - if not set -q pattern[$i] - if set -q printnext[1] - set printnext[2] 1 - continue - end - return 0 - end - else - if not set -q nomatch[1] - set nomatch 1 - set i 1 - end - end - end - if set -q printnext[1] - echo '' - end - set -q printnext[2] + set -l printnext + switch $argv[1] + case --printnext + set printnext[1] 1 + set -e argv[1] + end + set -l pattern + set -l string + set -l dest pattern + for i in $argv + if test "$i" = -- + set dest string + continue + end + set $dest $$dest $i + end + set -l nomatch 1 + set -l i 1 + for s in $string + if set -q printnext[2] + return 0 + end + if test "$s" = "$pattern[$i]" + set -e nomatch[1] + set i (math $i + 1) + if not set -q pattern[$i] + if set -q printnext[1] + set printnext[2] 1 + continue + end + return 0 + end + else + if not set -q nomatch[1] + set nomatch 1 + set i 1 + end + end + end + if set -q printnext[1] + echo '' + end + set -q printnext[2] end diff --git a/share/functions/delete-or-exit.fish b/share/functions/delete-or-exit.fish index 2a8d7286c..5a83ab8ac 100644 --- a/share/functions/delete-or-exit.fish +++ b/share/functions/delete-or-exit.fish @@ -7,17 +7,17 @@ function delete-or-exit - set -l cmd (commandline) + set -l cmd (commandline) - switch "$cmd" + switch "$cmd" - case '' - exit 0 + case '' + exit 0 - case '*' - commandline -f delete-char + case '*' + commandline -f delete-char - end + end end diff --git a/share/functions/dirs.fish b/share/functions/dirs.fish index 207f66328..9f57aba93 100644 --- a/share/functions/dirs.fish +++ b/share/functions/dirs.fish @@ -1,18 +1,18 @@ function dirs --description 'Print directory stack' - # process options - if count $argv >/dev/null - switch $argv[1] - case -c - # clear directory stack - set -e -g dirstack - return 0 - end + # process options + if count $argv >/dev/null + switch $argv[1] + case -c + # clear directory stack + set -e -g dirstack + return 0 end + end - # replace $HOME with ~ - echo -n (echo (command pwd) | sed -e "s|^$HOME|~|")" " - for i in $dirstack - echo -n (echo $i | sed -e "s|^$HOME|~|")" " - end - echo + # replace $HOME with ~ + echo -n (echo (command pwd) | sed -e "s|^$HOME|~|")" " + for i in $dirstack + echo -n (echo $i | sed -e "s|^$HOME|~|")" " + end + echo end diff --git a/share/functions/down-or-search.fish b/share/functions/down-or-search.fish index 967342391..b21232417 100644 --- a/share/functions/down-or-search.fish +++ b/share/functions/down-or-search.fish @@ -1,28 +1,28 @@ function down-or-search -d "Depending on cursor position and current mode, either search forward or move down one line" - # If we are already in search mode, continue - if commandline --search-mode - commandline -f history-search-forward - return - end + # If we are already in search mode, continue + if commandline --search-mode + commandline -f history-search-forward + return + end - # If we are navigating the pager, then up always navigates - if commandline --paging-mode - commandline -f down-line - return - end + # If we are navigating the pager, then up always navigates + if commandline --paging-mode + commandline -f down-line + return + end - # We are not already in search mode. - # If we are on the bottom line, start search mode, - # otherwise move down - set lineno (commandline -L) - set line_count (count (commandline)) + # We are not already in search mode. + # If we are on the bottom line, start search mode, + # otherwise move down + set lineno (commandline -L) + set line_count (count (commandline)) - switch $lineno - case $line_count - commandline -f history-search-forward + switch $lineno + case $line_count + commandline -f history-search-forward - case '*' - commandline -f down-line - end + case '*' + commandline -f down-line + end end diff --git a/share/functions/eval.fish b/share/functions/eval.fish index 052d41718..fc5f5aef4 100644 --- a/share/functions/eval.fish +++ b/share/functions/eval.fish @@ -1,65 +1,65 @@ function eval -S -d "Evaluate parameters as a command" - # keep a copy of the previous $status and use restore_status - # to preserve the status in case the block that is evaluated - # does not modify the status itself. - set -l status_copy $status - function __fish_restore_status - return $argv[1] - end + # keep a copy of the previous $status and use restore_status + # to preserve the status in case the block that is evaluated + # does not modify the status itself. + set -l status_copy $status + function __fish_restore_status + return $argv[1] + end - if not set -q argv[2] - # like most builtins, we only check for -h/--help - # if we only have a single argument - switch "$argv[1]" - case -h --help - __fish_print_help eval - return 0 - end - end + if not set -q argv[2] + # like most builtins, we only check for -h/--help + # if we only have a single argument + switch "$argv[1]" + case -h --help + __fish_print_help eval + return 0 + end + end - # If we are in an interactive shell, eval should enable full - # job control since it should behave like the real code was - # executed. If we don't do this, commands that expect to be - # used interactively, like less, wont work using eval. + # If we are in an interactive shell, eval should enable full + # job control since it should behave like the real code was + # executed. If we don't do this, commands that expect to be + # used interactively, like less, wont work using eval. - set -l mode - if status --is-interactive-job-control - set mode interactive - else - if status --is-full-job-control - set mode full - else - set mode none - end - end - if status --is-interactive - status --job-control full - end - __fish_restore_status $status_copy + set -l mode + if status --is-interactive-job-control + set mode interactive + else + if status --is-full-job-control + set mode full + else + set mode none + end + end + if status --is-interactive + status --job-control full + end + __fish_restore_status $status_copy - # To eval 'foo', we construct a block "begin ; foo; end <&3 3<&-" - # Note the redirections are also within the quotes. - # - # We then pipe this to 'source 3<&0’. - # - # You might expect that the dup2(3, stdin) should overwrite stdin, - # and therefore prevent 'source' from reading the piped-in block. This doesn't happen - # because when you pipe to a builtin, we don't overwrite stdin with the read end - # of the block; instead we set a separate fd in a variable 'builtin_stdin', which is - # what it reads from. So builtins are magic in that, in pipes, their stdin - # is not fd 0. - # - # ‘source’ does not apply the redirections to itself. Instead it saves them and passes - # them as block-level redirections to parser.eval(). Ultimately the eval’d code sees - # the following redirections (in the following order): - # dup2 0 -> 3 - # dup2 pipe -> 0 - # dup2 3 -> 0 - # where the pipe is the pipe we get from piping ‘echo’ to ‘source’. Thus the redirection - # effectively makes stdin fd0, instead of the thing that was piped to ‘source’ - echo "begin; $argv "\n" ;end <&3 3<&-" | source 3<&0 - set -l res $status + # To eval 'foo', we construct a block "begin ; foo; end <&3 3<&-" + # Note the redirections are also within the quotes. + # + # We then pipe this to 'source 3<&0’. + # + # You might expect that the dup2(3, stdin) should overwrite stdin, + # and therefore prevent 'source' from reading the piped-in block. This doesn't happen + # because when you pipe to a builtin, we don't overwrite stdin with the read end + # of the block; instead we set a separate fd in a variable 'builtin_stdin', which is + # what it reads from. So builtins are magic in that, in pipes, their stdin + # is not fd 0. + # + # ‘source’ does not apply the redirections to itself. Instead it saves them and passes + # them as block-level redirections to parser.eval(). Ultimately the eval’d code sees + # the following redirections (in the following order): + # dup2 0 -> 3 + # dup2 pipe -> 0 + # dup2 3 -> 0 + # where the pipe is the pipe we get from piping ‘echo’ to ‘source’. Thus the redirection + # effectively makes stdin fd0, instead of the thing that was piped to ‘source’ + echo "begin; $argv "\n" ;end <&3 3<&-" | source 3<&0 + set -l res $status - status --job-control $mode - return $res + status --job-control $mode + return $res end diff --git a/share/functions/fish_clipboard_copy.fish b/share/functions/fish_clipboard_copy.fish index a65efc045..a973e4437 100644 --- a/share/functions/fish_clipboard_copy.fish +++ b/share/functions/fish_clipboard_copy.fish @@ -1,5 +1,5 @@ function fish_clipboard_copy - if type -q pbcopy + if type -q pbcopy commandline | pbcopy else if type -q xsel commandline | xsel --clipboard diff --git a/share/functions/fish_clipboard_paste.fish b/share/functions/fish_clipboard_paste.fish index c6a4a3e45..7be522291 100644 --- a/share/functions/fish_clipboard_paste.fish +++ b/share/functions/fish_clipboard_paste.fish @@ -1,5 +1,5 @@ function fish_clipboard_paste - if type -q pbpaste + if type -q pbpaste commandline -i -- (pbpaste) else if type -q xsel commandline -i -- (xsel --clipboard) diff --git a/share/functions/fish_config.fish b/share/functions/fish_config.fish index 9bcac866e..48b113c78 100644 --- a/share/functions/fish_config.fish +++ b/share/functions/fish_config.fish @@ -1,9 +1,9 @@ function fish_config --description "Launch fish's web based configuration" - # Support passing an initial tab like "colors" or "functions" - set -l initial_tab - if count $argv >/dev/null - set initial_tab $argv[1] - end - set -x __fish_bin_dir $__fish_bin_dir - eval (string escape $__fish_datadir/tools/web_config/webconfig.py) $initial_tab + # Support passing an initial tab like "colors" or "functions" + set -l initial_tab + if count $argv >/dev/null + set initial_tab $argv[1] + end + set -x __fish_bin_dir $__fish_bin_dir + eval (string escape $__fish_datadir/tools/web_config/webconfig.py) $initial_tab end diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index 58b3712bc..bf99c5d6d 100644 --- a/share/functions/fish_default_key_bindings.fish +++ b/share/functions/fish_default_key_bindings.fish @@ -6,7 +6,7 @@ function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fis end if not set -q argv[1] - bind --erase --all # clear earlier bindings, if any + bind --erase --all # clear earlier bindings, if any if test "$fish_key_bindings" != "fish_default_key_bindings" # Allow the user to set the variable universally set -q fish_key_bindings @@ -20,11 +20,11 @@ function fish_default_key_bindings -d "Default (Emacs-like) key bindings for fis # These are shell-specific bindings that we share with vi mode. __fish_shared_key_bindings $argv - or return # protect against invalid $argv + or return # protect against invalid $argv # This is the default binding, i.e. the one used if no other binding matches bind $argv "" self-insert - or exit # protect against invalid $argv + or exit # protect against invalid $argv bind $argv \n execute bind $argv \r execute diff --git a/share/functions/fish_fallback_prompt.fish b/share/functions/fish_fallback_prompt.fish index 1910eeaea..d8b976001 100644 --- a/share/functions/fish_fallback_prompt.fish +++ b/share/functions/fish_fallback_prompt.fish @@ -3,20 +3,20 @@ # Set the default prompt command. function fish_fallback_prompt --description "A simple fallback prompt without too much color or special characters for linux VTs" - set -l color_cwd - set -l suffix - switch $USER - case root toor - if set -q fish_color_cwd_root - set color_cwd $fish_color_cwd_root - else - set color_cwd $fish_color_cwd - end - set suffix '#' - case '*' - set color_cwd $fish_color_cwd - set suffix '>' - end + set -l color_cwd + set -l suffix + switch $USER + case root toor + if set -q fish_color_cwd_root + set color_cwd $fish_color_cwd_root + else + set color_cwd $fish_color_cwd + end + set suffix '#' + case '*' + set color_cwd $fish_color_cwd + set suffix '>' + end - echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix " + echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix " end diff --git a/share/functions/fish_hybrid_key_bindings.fish b/share/functions/fish_hybrid_key_bindings.fish index a7dbf7abb..bf2bbf015 100644 --- a/share/functions/fish_hybrid_key_bindings.fish +++ b/share/functions/fish_hybrid_key_bindings.fish @@ -1,5 +1,5 @@ function fish_hybrid_key_bindings --description "Vi-style bindings that inherit emacs-style bindings in all modes" - bind --erase --all # clear earlier bindings, if any + bind --erase --all # clear earlier bindings, if any if test "$fish_key_bindings" != "fish_hybrid_key_bindings" # Allow the user to set the variable universally diff --git a/share/functions/fish_indent.fish b/share/functions/fish_indent.fish index a97e1c2e8..03e30995a 100644 --- a/share/functions/fish_indent.fish +++ b/share/functions/fish_indent.fish @@ -1,6 +1,6 @@ # check if command fish_indent works and is the same version that # came with this fish. This will happen one time. -command -s fish_indent > /dev/null +command -s fish_indent >/dev/null and command fish_indent --version 2>&1 | string match -rq $FISH_VERSION # if alias doesn't define the function here, this is an autoloaded "nothing". # the command (if there is one) will be used by default. diff --git a/share/functions/fish_key_reader.fish b/share/functions/fish_key_reader.fish index 5a955e13f..0cf5b29a7 100644 --- a/share/functions/fish_key_reader.fish +++ b/share/functions/fish_key_reader.fish @@ -1,6 +1,6 @@ # check if command fish_key_reader works and is the same version that # came with this fish. This will happen one time. -command -s fish_key_reader > /dev/null +command -s fish_key_reader >/dev/null and command fish_key_reader --version 2>&1 | string match -rq $FISH_VERSION # if alias doesn't define the function here, this is an autoloaded "nothing". # the command (if there is one) will be used by default. diff --git a/share/functions/fish_mode_prompt.fish b/share/functions/fish_mode_prompt.fish index 0945b560c..06737d4f3 100644 --- a/share/functions/fish_mode_prompt.fish +++ b/share/functions/fish_mode_prompt.fish @@ -1,23 +1,23 @@ # The fish_mode_prompt function is prepended to the prompt function fish_mode_prompt --description "Displays the current mode" - # Do nothing if not in vi mode - if test "$fish_key_bindings" = "fish_vi_key_bindings" - or test "$fish_key_bindings" = "fish_hybrid_key_bindings" - switch $fish_bind_mode - case default - set_color --bold --background red white - echo '[N]' - case insert - set_color --bold --background green white - echo '[I]' - case replace-one - set_color --bold --background green white - echo '[R]' - case visual - set_color --bold --background magenta white - echo '[V]' + # Do nothing if not in vi mode + if test "$fish_key_bindings" = "fish_vi_key_bindings" + or test "$fish_key_bindings" = "fish_hybrid_key_bindings" + switch $fish_bind_mode + case default + set_color --bold --background red white + echo '[N]' + case insert + set_color --bold --background green white + echo '[I]' + case replace-one + set_color --bold --background green white + echo '[R]' + case visual + set_color --bold --background magenta white + echo '[V]' + end + set_color normal + echo -n ' ' end - set_color normal - echo -n ' ' - end end diff --git a/share/functions/fish_prompt.fish b/share/functions/fish_prompt.fish index 7f8581971..153d3adbc 100644 --- a/share/functions/fish_prompt.fish +++ b/share/functions/fish_prompt.fish @@ -3,20 +3,20 @@ # Set the default prompt command. function fish_prompt --description "Write out the prompt" - set -l color_cwd - set -l suffix - switch $USER - case root toor - if set -q fish_color_cwd_root - set color_cwd $fish_color_cwd_root - else - set color_cwd $fish_color_cwd - end - set suffix '#' - case '*' - set color_cwd $fish_color_cwd - set suffix '>' - end + set -l color_cwd + set -l suffix + switch $USER + case root toor + if set -q fish_color_cwd_root + set color_cwd $fish_color_cwd_root + else + set color_cwd $fish_color_cwd + end + set suffix '#' + case '*' + set color_cwd $fish_color_cwd + set suffix '>' + end - echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix " + echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix " end diff --git a/share/functions/fish_update_completions.fish b/share/functions/fish_update_completions.fish index 17b47ecb9..0fb007983 100644 --- a/share/functions/fish_update_completions.fish +++ b/share/functions/fish_update_completions.fish @@ -1,4 +1,4 @@ function fish_update_completions --description "Update man-page based completions" - # Clean up old paths - python -B $__fish_datadir/tools/create_manpage_completions.py --manpath --progress --cleanup-in '~/.config/fish/completions' --cleanup-in '~/.config/fish/generated_completions' + # Clean up old paths + python -B $__fish_datadir/tools/create_manpage_completions.py --manpath --progress --cleanup-in '~/.config/fish/completions' --cleanup-in '~/.config/fish/generated_completions' end diff --git a/share/functions/fish_vi_cursor.fish b/share/functions/fish_vi_cursor.fish index 63951b8c3..30192556f 100644 --- a/share/functions/fish_vi_cursor.fish +++ b/share/functions/fish_vi_cursor.fish @@ -16,7 +16,7 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes' # We use the `tput` here just to see if terminfo thinks we can change the cursor. # We cannot use that sequence directly as it's not the correct one for konsole and iTerm, # and because we may want to change the cursor even though terminfo says we can't (tmux). - if not tput Ss > /dev/null ^/dev/null + if not tput Ss >/dev/null ^/dev/null # Whitelist tmux... and not begin set -q TMUX @@ -54,7 +54,7 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes' or test (string replace -r "XTerm\((\d+)\)" '$1' -- $XTERM_VERSION) -ge 280 ^/dev/null end end - + return end @@ -67,7 +67,7 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes' switch "$terminal" case auto if set -q KONSOLE_PROFILE_NAME - or set -q ITERM_PROFILE + or set -q ITERM_PROFILE set function __fish_cursor_konsole set uses_echo 1 else @@ -85,7 +85,7 @@ function fish_vi_cursor -d 'Set cursor shape for different vi modes' set -l tmux_prefix set -l tmux_postfix if set -q TMUX - and set -q uses_echo[1] + and set -q uses_echo[1] set tmux_prefix echo -ne "'\ePtmux;\e'" set tmux_postfix echo -ne "'\e\\\\'" end diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index 7fbe3d007..aac703f37 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -14,7 +14,7 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' set rebind false set -e argv[1] else - bind --erase --all # clear earlier bindings, if any + bind --erase --all # clear earlier bindings, if any end # Allow just calling this function to correctly set the bindings. @@ -58,7 +58,7 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' bind -M insert \r execute bind -M insert \n execute - + bind -M insert "" self-insert # Add way to kill current command line while in insert mode. diff --git a/share/functions/fish_vi_mode.fish b/share/functions/fish_vi_mode.fish index 49023055e..8e2a92488 100644 --- a/share/functions/fish_vi_mode.fish +++ b/share/functions/fish_vi_mode.fish @@ -1,6 +1,6 @@ function fish_vi_mode - echo 'The `fish_vi_mode` function is deprecated.' >&2 - echo 'Please switch to calling `fish_vi_key_bindings`.' >&2 - # Turn on vi keybindings - set -g fish_key_bindings fish_vi_key_bindings + echo 'The `fish_vi_mode` function is deprecated.' >&2 + echo 'Please switch to calling `fish_vi_key_bindings`.' >&2 + # Turn on vi keybindings + set -g fish_key_bindings fish_vi_key_bindings end diff --git a/share/functions/funced.fish b/share/functions/funced.fish index fd3060a7e..686c89b7c 100644 --- a/share/functions/funced.fish +++ b/share/functions/funced.fish @@ -48,9 +48,9 @@ function funced --description 'Edit function definition' set -l init switch $funcname case '-*' - set init function -- $funcname\n\nend + set init function -- $funcname\n\nend case '*' - set init function $funcname\n\nend + set init function $funcname\n\nend end # Break editor up to get its first command (i.e. discard flags) @@ -63,13 +63,16 @@ function funced --description 'Edit function definition' set editor fish end end - + # If no editor is specified, use fish if test -z "$editor" 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,40 +92,41 @@ 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 if functions -q -- $funcname - functions -- $funcname > $tmpname + functions -- $funcname >$tmpname else - echo $init > $tmpname + echo $init >$tmpname end - # Repeatedly edit until it either parses successfully, or the user cancels - # If the editor command itself fails, we assume the user cancelled or the file - # could not be edited, and we do not try again - while true - if not eval $editor $tmpname - _ "Editing failed or was cancelled" - echo - else - if not source $tmpname - # Failed to source the function file. Prompt to try again. - echo # add a line between the parse error and the prompt - set -l repeat - set -l prompt (_ 'Edit the file again\? [Y/n]') - while test -z "$repeat" - read -p "echo $prompt\ " repeat - end - if not contains $repeat n N no NO No nO - continue - end - _ "Cancelled function editing" - echo - end + # Repeatedly edit until it either parses successfully, or the user cancels + # If the editor command itself fails, we assume the user cancelled or the file + # could not be edited, and we do not try again + while true + if not eval $editor $tmpname + _ "Editing failed or was cancelled" + echo + else + if not source $tmpname + # Failed to source the function file. Prompt to try again. + echo # add a line between the parse error and the prompt + set -l repeat + set -l prompt (_ 'Edit the file again\? [Y/n]') + while test -z "$repeat" + read -p "echo $prompt\ " repeat end - break + if not contains $repeat n N no NO No nO + continue + end + _ "Cancelled function editing" + echo + end end + break + end set -l stat $status rm $tmpname >/dev/null and rmdir $tmpdir >/dev/null diff --git a/share/functions/funcsave.fish b/share/functions/funcsave.fish index bbf7a32a8..cbd186efe 100644 --- a/share/functions/funcsave.fish +++ b/share/functions/funcsave.fish @@ -1,43 +1,43 @@ function funcsave --description "Save the current definition of all specified functions to file" - if count $argv >/dev/null - switch $argv[1] - case -h --h --he --hel --help - __fish_print_help funcsave - return 0 - end - else - printf (_ "%s: Expected function name\n") funcsave - __fish_print_help funcsave - return 1 - end + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help funcsave + return 0 + end + else + printf (_ "%s: Expected function name\n") funcsave + __fish_print_help funcsave + return 1 + end - set -l res 0 + set -l res 0 - set -l configdir ~/.config - if set -q XDG_CONFIG_HOME - set configdir $XDG_CONFIG_HOME - end + set -l configdir ~/.config + if set -q XDG_CONFIG_HOME + set configdir $XDG_CONFIG_HOME + end - for i in $configdir $configdir/fish $configdir/fish/functions - if not test -d $i - if not command mkdir $i >/dev/null - printf (_ "%s: Could not create configuration directory\n") funcsave - return 1 - end - end - end + for i in $configdir $configdir/fish $configdir/fish/functions + if not test -d $i + if not command mkdir $i >/dev/null + printf (_ "%s: Could not create configuration directory\n") funcsave + return 1 + end + end + end - for i in $argv - if functions -q -- $i - functions -- $i > $configdir/fish/functions/$i.fish - else - printf (_ "%s: Unknown function '%s'\n") funcsave $i - set res 1 - end - end + for i in $argv + if functions -q -- $i + functions -- $i >$configdir/fish/functions/$i.fish + else + printf (_ "%s: Unknown function '%s'\n") funcsave $i + set res 1 + end + end - return $res + return $res end diff --git a/share/functions/grep.fish b/share/functions/grep.fish index bedf18be7..0647494fa 100644 --- a/share/functions/grep.fish +++ b/share/functions/grep.fish @@ -3,7 +3,7 @@ # if echo | command grep --color=auto "" >/dev/null 2>&1 - function grep - command grep --color=auto $argv - end + function grep + command grep --color=auto $argv + end end diff --git a/share/functions/help.fish b/share/functions/help.fish index 9caf34b87..341f79aad 100644 --- a/share/functions/help.fish +++ b/share/functions/help.fish @@ -1,151 +1,151 @@ function help --description 'Show help for the fish shell' - - # Declare variables to set correct scope - set -l fish_browser - set -l h syntax completion editor job-control todo bugs history killring help - set h $h color prompt title variables builtin-overview changes expand - set h $h expand-variable expand-home expand-brace expand-wildcard - set -l help_topics $h expand-command-substitution expand-process + # Declare variables to set correct scope + set -l fish_browser - # 'help -h' should launch 'help help' - if count $argv >/dev/null - switch $argv[1] - case -h --h --he --hel --help - __fish_print_help help - return 0 - end - end + set -l h syntax completion editor job-control todo bugs history killring help + set h $h color prompt title variables builtin-overview changes expand + set h $h expand-variable expand-home expand-brace expand-wildcard + set -l help_topics $h expand-command-substitution expand-process - # - # Find a suitable browser for viewing the help pages. This is needed - # by the help function defined below. - # - set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape rekonq google-chrome chromium-browser + # 'help -h' should launch 'help help' + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help help + return 0 + end + end - if set -q fish_help_browser[1] - # User has set a fish-specific help browser. This overrides the - # browser that may be defined by $BROWSER. The fish_help_browser - # variable may be an array containing a browser name plus options. - set fish_browser $fish_help_browser - else - set -l text_browsers htmlview www-browser links elinks lynx w3m + # + # Find a suitable browser for viewing the help pages. This is needed + # by the help function defined below. + # + set -l graphical_browsers htmlview x-www-browser firefox galeon mozilla konqueror epiphany opera netscape rekonq google-chrome chromium-browser - if set -q BROWSER - # User has manually set a preferred browser, so we respect that - set fish_browser $BROWSER - else - # Check for a text-based browser. - for i in $text_browsers - if type -q -f $i - set fish_browser $i - break - end - end - - # If we are in a graphical environment, check if there is a graphical - # browser to use instead. - if test "$DISPLAY" -a \( "$XAUTHORITY" = "$HOME/.Xauthority" -o "$XAUTHORITY" = "" \) - for i in $graphical_browsers - if type -q -f $i - set fish_browser $i - break - end - end - end + if set -q fish_help_browser[1] + # User has set a fish-specific help browser. This overrides the + # browser that may be defined by $BROWSER. The fish_help_browser + # variable may be an array containing a browser name plus options. + set fish_browser $fish_help_browser + else + set -l text_browsers htmlview www-browser links elinks lynx w3m - # If the OS appears to be Windows (graphical), try to use cygstart - if type -q cygstart - set fish_browser cygstart - # If xdg-open is available, just use that - else if type -q xdg-open - set fish_browser xdg-open - end - - # On OS X, we go through osascript by default - if test (uname) = Darwin - if type -q osascript - set fish_browser osascript - end - end - end - end + if set -q BROWSER + # User has manually set a preferred browser, so we respect that + set fish_browser $BROWSER + else + # Check for a text-based browser. + for i in $text_browsers + if type -q -f $i + set fish_browser $i + break + end + end - if not set -q fish_browser - printf (_ '%s: Could not find a web browser.\n') help - printf (_ 'Please set the variable $BROWSER or fish_help_browser and try again.\n\n') - return 1 - end + # If we are in a graphical environment, check if there is a graphical + # browser to use instead. + if test "$DISPLAY" -a \( "$XAUTHORITY" = "$HOME/.Xauthority" -o "$XAUTHORITY" = "" \) + for i in $graphical_browsers + if type -q -f $i + set fish_browser $i + break + end + end + end - # In Cygwin, start the user-specified browser using cygstart - if type -q cygstart - if test $fish_browser != "cygstart" - # Escaped quotes are necessary to work with spaces in the path - # when the command is finally eval'd. - set fish_browser cygstart \"$fish_browser\" - end - end + # If the OS appears to be Windows (graphical), try to use cygstart + if type -q cygstart + set fish_browser cygstart + # If xdg-open is available, just use that + else if type -q xdg-open + set fish_browser xdg-open + end - set -l fish_help_item $argv[1] + # On OS X, we go through osascript by default + if test (uname) = Darwin + if type -q osascript + set fish_browser osascript + end + end + end + end - switch "$fish_help_item" - case "" - set fish_help_page index.html - case "." - set fish_help_page "commands.html\#source" - case globbing - set fish_help_page "index.html\#expand" - case (__fish_print_commands) - set fish_help_page "commands.html\#$fish_help_item" - case $help_topics - set fish_help_page "index.html\#$fish_help_item" - case "*" - if type -q -f $fish_help_item - # Prefer to use fish's man pages, to avoid - # the annoying useless "builtin" man page bash - # installs on OS X - set -l man_arg "$__fish_datadir/man/man1/$fish_help_item.1" - if test -f "$man_arg" - man $man_arg - return - end - end - set fish_help_page "index.html" - end - - set -l page_url - if test -f $__fish_help_dir/index.html - # Help is installed, use it - set page_url file://$__fish_help_dir/$fish_help_page + if not set -q fish_browser + printf (_ '%s: Could not find a web browser.\n') help + printf (_ 'Please set the variable $BROWSER or fish_help_browser and try again.\n\n') + return 1 + end - # In Cygwin, we need to convert the base help dir to a Windows path before converting it to a file URL - if type -q cygpath - set page_url file://(cygpath -m $__fish_help_dir)/$fish_help_page - end - else - # Go to the web. Only include one dot in the version string - set -l version_string (echo $FISH_VERSION| cut -d . -f 1,2) - set page_url http://fishshell.com/docs/$version_string/$fish_help_page - end - - # OS X /usr/bin/open swallows fragments (anchors), so use osascript - # Eval is just a cheesy way of removing the hash escaping - if test "$fish_browser" = osascript - osascript -e 'open location "'(eval echo $page_url)'"' - return - end - + # In Cygwin, start the user-specified browser using cygstart + if type -q cygstart + if test $fish_browser != "cygstart" + # Escaped quotes are necessary to work with spaces in the path + # when the command is finally eval'd. + set fish_browser cygstart \"$fish_browser\" + end + end - # If browser is known to be graphical, put into background - if contains -- $fish_browser[1] $graphical_browsers - switch $fish_browser[1] - case 'htmlview' 'x-www-browser' - printf (_ 'help: Help is being displayed in your default browser.\n') - case '*' - printf (_ 'help: Help is being displayed in %s.\n') $fish_browser[1] - end - eval "$fish_browser $page_url &" - else - eval $fish_browser $page_url - end + set -l fish_help_item $argv[1] + + switch "$fish_help_item" + case "" + set fish_help_page index.html + case "." + set fish_help_page "commands.html\#source" + case globbing + set fish_help_page "index.html\#expand" + case (__fish_print_commands) + set fish_help_page "commands.html\#$fish_help_item" + case $help_topics + set fish_help_page "index.html\#$fish_help_item" + case "*" + if type -q -f $fish_help_item + # Prefer to use fish's man pages, to avoid + # the annoying useless "builtin" man page bash + # installs on OS X + set -l man_arg "$__fish_datadir/man/man1/$fish_help_item.1" + if test -f "$man_arg" + man $man_arg + return + end + end + set fish_help_page "index.html" + end + + set -l page_url + if test -f $__fish_help_dir/index.html + # Help is installed, use it + set page_url file://$__fish_help_dir/$fish_help_page + + # In Cygwin, we need to convert the base help dir to a Windows path before converting it to a file URL + if type -q cygpath + set page_url file://(cygpath -m $__fish_help_dir)/$fish_help_page + end + else + # Go to the web. Only include one dot in the version string + set -l version_string (echo $FISH_VERSION| cut -d . -f 1,2) + set page_url http://fishshell.com/docs/$version_string/$fish_help_page + end + + # OS X /usr/bin/open swallows fragments (anchors), so use osascript + # Eval is just a cheesy way of removing the hash escaping + if test "$fish_browser" = osascript + osascript -e 'open location "'(eval echo $page_url)'"' + return + end + + + # If browser is known to be graphical, put into background + if contains -- $fish_browser[1] $graphical_browsers + switch $fish_browser[1] + case 'htmlview' 'x-www-browser' + printf (_ 'help: Help is being displayed in your default browser.\n') + case '*' + printf (_ 'help: Help is being displayed in %s.\n') $fish_browser[1] + end + eval "$fish_browser $page_url &" + else + eval $fish_browser $page_url + end end diff --git a/share/functions/hostname.fish b/share/functions/hostname.fish index d4d2d2591..e45d984de 100644 --- a/share/functions/hostname.fish +++ b/share/functions/hostname.fish @@ -1,10 +1,10 @@ # Query for USERDOMAIN to shorten waiting times when OS isn't Windows. set -q USERDOMAIN and switch (uname) -case 'CYGWIN_*' - # Cygwin's hostname is broken when computer name contains Unicode - # characters. This hack "fixes" hostname in Cygwin. - function hostname --description "Show or set the system's host name" - echo $USERDOMAIN - end + case 'CYGWIN_*' + # Cygwin's hostname is broken when computer name contains Unicode + # characters. This hack "fixes" hostname in Cygwin. + function hostname --description "Show or set the system's host name" + echo $USERDOMAIN + end end diff --git a/share/functions/isatty.fish b/share/functions/isatty.fish index df8199250..02282928a 100644 --- a/share/functions/isatty.fish +++ b/share/functions/isatty.fish @@ -1,30 +1,30 @@ function isatty -d "Tests if a file descriptor is a tty" - set -l fd 0 - if count $argv >/dev/null - switch $argv[1] + set -l fd 0 + if count $argv >/dev/null + switch $argv[1] - case -h --h --he --hel --help - __fish_print_help isatty - return 0 + case -h --h --he --hel --help + __fish_print_help isatty + return 0 - case stdin '' - set fd 0 + case stdin '' + set fd 0 - case stdout - set fd 1 + case stdout + set fd 1 - case stderr - set fd 2 + case stderr + set fd 2 - case '*' - set fd $argv[1] + case '*' + set fd $argv[1] - end - end + end + end - # Use `command test` because `builtin test` doesn't open the regular fd's. - # See https://github.com/fish-shell/fish-shell/issues/1228 - command test -t "$fd" + # Use `command test` because `builtin test` doesn't open the regular fd's. + # See https://github.com/fish-shell/fish-shell/issues/1228 + command test -t "$fd" end diff --git a/share/functions/la.fish b/share/functions/la.fish index 818aa11ec..355e1f83a 100644 --- a/share/functions/la.fish +++ b/share/functions/la.fish @@ -2,6 +2,6 @@ # These are very common and useful # function la --description "List contents of directory, including hidden files in directory using long format" - ls -lah $argv + ls -lah $argv end diff --git a/share/functions/ll.fish b/share/functions/ll.fish index d5aba9e57..e8230f4ec 100644 --- a/share/functions/ll.fish +++ b/share/functions/ll.fish @@ -2,5 +2,5 @@ # These are very common and useful # function ll --description "List contents of directory using long format" - ls -lh $argv + ls -lh $argv end diff --git a/share/functions/ls.fish b/share/functions/ls.fish index 2da4d6b81..2b6118c8e 100644 --- a/share/functions/ls.fish +++ b/share/functions/ls.fish @@ -3,34 +3,34 @@ # if command ls --version 1>/dev/null 2>/dev/null - # This is GNU ls - function ls --description "List contents of directory" - set -l param --color=auto - if isatty 1 - set param $param --indicator-style=classify - end - command ls $param $argv - end + # This is GNU ls + function ls --description "List contents of directory" + set -l param --color=auto + if isatty 1 + set param $param --indicator-style=classify + end + command ls $param $argv + end - if not set -q LS_COLORS - if type -q -f dircolors - set -l colorfile - for file in ~/.dir_colors ~/.dircolors /etc/DIR_COLORS - if test -f $file - set colorfile $file - break - end - end - set -gx LS_COLORS (dircolors -c $colorfile | string replace -r 'setenv LS_COLORS \'(.*)\'' '$1') - end - end + if not set -q LS_COLORS + if type -q -f dircolors + set -l colorfile + for file in ~/.dir_colors ~/.dircolors /etc/DIR_COLORS + if test -f $file + set colorfile $file + break + end + end + set -gx LS_COLORS (dircolors -c $colorfile | string replace -r 'setenv LS_COLORS \'(.*)\'' '$1') + end + end else - # BSD, OS X and a few more support colors through the -G switch instead - if command ls -G / 1>/dev/null 2>/dev/null - function ls --description "List contents of directory" - command ls -G $argv - end - end + # BSD, OS X and a few more support colors through the -G switch instead + if command ls -G / 1>/dev/null 2>/dev/null + function ls --description "List contents of directory" + command ls -G $argv + end + end end diff --git a/share/functions/man.fish b/share/functions/man.fish index 25c81a4bb..c9d3ff7f0 100644 --- a/share/functions/man.fish +++ b/share/functions/man.fish @@ -1,23 +1,24 @@ function man --description "Format and display the on-line manual pages" - # Work around the "builtin" manpage that everything symlinks to, - # by prepending our fish datadir to man. This also ensures that man gives fish's - # man pages priority, without having to put fish's bin directories first in $PATH + # Work around the "builtin" manpage that everything symlinks to, + # by prepending our fish datadir to man. This also ensures that man gives fish's + # man pages priority, without having to put fish's bin directories first in $PATH - # Notice local but exported variable - set -lx MANPATH (string join : $MANPATH) - if test -z "$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" - set MANPATH "$fish_manpath":$MANPATH + # Notice local but exported variable + set -lx MANPATH (string join : $MANPATH) + if test -z "$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" + set MANPATH "$fish_manpath":$MANPATH - # Invoke man with this manpath, and we're done - command man $argv - return - end - - # If fish's man pages could not be found, just invoke man normally - command man $argv + # Invoke man with this manpath, and we're done + command man $argv + return + end + + # If fish's man pages could not be found, just invoke man normally + command man $argv end diff --git a/share/functions/nextd-or-forward-word.fish b/share/functions/nextd-or-forward-word.fish index 037dd9946..9428b89e2 100644 --- a/share/functions/nextd-or-forward-word.fish +++ b/share/functions/nextd-or-forward-word.fish @@ -1,9 +1,9 @@ function nextd-or-forward-word - set -l cmd (commandline) - if test -z "$cmd" - nextd - commandline -f repaint - else - commandline -f forward-word - end + set -l cmd (commandline) + if test -z "$cmd" + nextd + commandline -f repaint + else + commandline -f forward-word + end end diff --git a/share/functions/nextd.fish b/share/functions/nextd.fish index 3f28d07ac..3a94e7d8e 100644 --- a/share/functions/nextd.fish +++ b/share/functions/nextd.fish @@ -1,18 +1,18 @@ function nextd --description "Move forward in the directory history" - if count $argv >/dev/null - switch $argv[1] - case -h --h --he --hel --help - __fish_print_help nextd - return 0 - end - end + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help nextd + return 0 + end + end - # Parse arguments - set -l show_hist 0 - set -l times 1 - if count $argv > /dev/null + # Parse arguments + set -l show_hist 0 + set -l times 1 + if count $argv >/dev/null for i in (seq (count $argv)) switch $argv[$i] case '-l' --l --li --lis --list @@ -33,12 +33,13 @@ function nextd --description "Move forward in the directory history" end end - # Traverse history - set -l code 1 - if count $times > /dev/null + # Traverse history + set -l code 1 + 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 @@ -48,16 +49,16 @@ function nextd --description "Move forward in the directory history" end end - # Show history if needed - if test $show_hist = 1 - dirh - end + # Show history if needed + if test $show_hist = 1 + dirh + end - # Set direction for 'cd -' - if test $code = 0 ^/dev/null - set -g __fish_cd_direction prev - end + # Set direction for 'cd -' + if test $code = 0 ^/dev/null + set -g __fish_cd_direction prev + end - # All done - return $code + # All done + return $code end diff --git a/share/functions/open.fish b/share/functions/open.fish index 9eaa7eda6..6e606aeba 100644 --- a/share/functions/open.fish +++ b/share/functions/open.fish @@ -4,25 +4,25 @@ # if not command -s open >/dev/null - function open --description "Open file in default application" - if count $argv >/dev/null - switch $argv[1] - case -h --h --he --hel --help - __fish_print_help open - return 0 - end - end + function open --description "Open file in default application" + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help open + return 0 + end + end - if type -q -f cygstart - for i in $argv - cygstart $i - end - else if type -q -f xdg-open - for i in $argv - xdg-open $i - end - else - echo (_ 'No open utility found. Try installing "xdg-open" or "xdg-utils".') - end - end + if type -q -f cygstart + for i in $argv + cygstart $i + end + else if type -q -f xdg-open + for i in $argv + xdg-open $i + end + else + echo (_ 'No open utility found. Try installing "xdg-open" or "xdg-utils".') + end + end end diff --git a/share/functions/popd.fish b/share/functions/popd.fish index 44a19593d..3a8287f5f 100644 --- a/share/functions/popd.fish +++ b/share/functions/popd.fish @@ -1,19 +1,19 @@ function popd --description "Pop directory from the stack and cd to it" - if count $argv >/dev/null - switch $argv[1] - case -h --h --he --hel --help - __fish_print_help popd - return 0 - end - end + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help popd + return 0 + end + end - if test $dirstack[1] - cd $dirstack[1] - else - printf (_ "%s: Directory stack is empty…\n") popd 1>&2 - return 1 - end + if test $dirstack[1] + cd $dirstack[1] + else + printf (_ "%s: Directory stack is empty…\n") popd 1>&2 + return 1 + end - set -e dirstack[1] + set -e dirstack[1] end diff --git a/share/functions/prevd-or-backward-word.fish b/share/functions/prevd-or-backward-word.fish index bbaca8aea..5f0c740ed 100644 --- a/share/functions/prevd-or-backward-word.fish +++ b/share/functions/prevd-or-backward-word.fish @@ -2,7 +2,7 @@ function prevd-or-backward-word set -l cmd (commandline) if test -z "$cmd" prevd - commandline -f repaint + commandline -f repaint else commandline -f backward-word end diff --git a/share/functions/prevd.fish b/share/functions/prevd.fish index a1e2d3d30..3b538d884 100644 --- a/share/functions/prevd.fish +++ b/share/functions/prevd.fish @@ -1,18 +1,18 @@ function prevd --description "Move back in the directory history" - if count $argv >/dev/null - switch $argv[1] - case -h --h --he --hel --help - __fish_print_help prevd - return 0 - end - end + if count $argv >/dev/null + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help prevd + return 0 + end + end - # Parse arguments - set -l show_hist 0 - set -l times 1 - if count $argv > /dev/null + # Parse arguments + set -l show_hist 0 + set -l times 1 + if count $argv >/dev/null for i in (seq (count $argv)) switch $argv[$i] case '-l' --l --li --lis --list @@ -31,14 +31,15 @@ function prevd --description "Move back in the directory history" continue end end - end + end - # Traverse history - set -l code 1 - if count $times > /dev/null + # Traverse history + set -l code 1 + 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 @@ -48,16 +49,16 @@ function prevd --description "Move back in the directory history" end end - # Show history if needed - if test $show_hist = 1 - dirh - end + # Show history if needed + if test $show_hist = 1 + dirh + end - # Set direction for 'cd -' - if test $code = 0 ^/dev/null - set -g __fish_cd_direction next - end + # Set direction for 'cd -' + if test $code = 0 ^/dev/null + set -g __fish_cd_direction next + end - # All done - return $code + # All done + return $code end diff --git a/share/functions/prompt_pwd.fish b/share/functions/prompt_pwd.fish index 96e9b2f33..71dfc461e 100644 --- a/share/functions/prompt_pwd.fish +++ b/share/functions/prompt_pwd.fish @@ -1,21 +1,23 @@ function prompt_pwd --description "Print the current working directory, shortened to fit the prompt" - set -q argv[1]; and switch $argv[1] - case -h --help - __fish_print_help prompt_pwd - return 0 - end + 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 + # 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 - # Replace $HOME with "~" - set realhome ~ - set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD) + # Replace $HOME with "~" + set realhome ~ + set -l tmp (string replace -r '^'"$realhome"'($|/)' '~$1' $PWD) - if [ $fish_prompt_pwd_dir_length -eq 0 ] - echo $tmp - else - # Shorten to at most $fish_prompt_pwd_dir_length characters per directory - string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp - end + if [ $fish_prompt_pwd_dir_length -eq 0 ] + echo $tmp + else + # Shorten to at most $fish_prompt_pwd_dir_length characters per directory + string replace -ar '(\.?[^/]{'"$fish_prompt_pwd_dir_length"'})[^/]*/' '$1/' $tmp + end end diff --git a/share/functions/psub.fish b/share/functions/psub.fish index 221045312..afed1788e 100644 --- a/share/functions/psub.fish +++ b/share/functions/psub.fish @@ -1,96 +1,99 @@ function psub --description "Read from stdin into a file and output the filename. Remove the file when the command that called psub exits." - set -l dirname - set -l filename - set -l funcname - set -l suffix - set -l use_fifo 1 + set -l dirname + set -l filename + set -l funcname + set -l suffix + set -l use_fifo 1 - while count $argv >/dev/null + while count $argv >/dev/null - switch $argv[1] - case -h --help - __fish_print_help psub - return 0 + switch $argv[1] + case -h --help + __fish_print_help psub + return 0 - case -f --file - set use_fifo 0 - set -e argv[1] + case -f --file + set use_fifo 0 + set -e argv[1] - case -s --suffix - if not set -q argv[2] - printf "psub: missing operand\n" - return 1 - end - set suffix $argv[2] - set -e argv[1..2] + case -s --suffix + if not set -q argv[2] + printf "psub: missing operand\n" + return 1 + end + set suffix $argv[2] + set -e argv[1..2] - case -- - set -e argv[1] - break + case -- + set -e argv[1] + break - case "-?" "--*" - printf "psub: invalid option: '%s'\n" $argv[1] - return 1 + case "-?" "--*" + printf "psub: invalid option: '%s'\n" $argv[1] + return 1 - case "-*" - # Ungroup short options: -hfs => -h -f -s - set opts "-"(string sub -s 2 -- $argv[1] | string split "") - set -e argv[1] - set argv $opts $argv + case "-*" + # Ungroup short options: -hfs => -h -f -s + set opts "-"(string sub -s 2 -- $argv[1] | string split "") + set -e argv[1] + set argv $opts $argv - case "*" - printf "psub: extra operand: '%s'\n" $argv[1] - return 1 - end - end + case "*" + printf "psub: extra operand: '%s'\n" $argv[1] + return 1 + end + end - if not status --is-command-substitution - echo psub: Not inside of command substitution >&2 - return 1 - end + if not status --is-command-substitution + echo psub: Not inside of command substitution >&2 + return 1 + end - set -l TMPDIR $TMPDIR - if test -z "$TMPDIR[1]" - set TMPDIR /tmp - end + set -l TMPDIR $TMPDIR + if test -z "$TMPDIR[1]" + set TMPDIR /tmp + end - if test use_fifo = 1 - # 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 filename $dirname/psub.fifo"$suffix" - mkfifo $filename - cat >$filename & - else if test -z $suffix - set filename (mktemp "$TMPDIR[1]"/.psub.XXXXXXXXXX) - cat >$filename - else - set dirname (mktemp -d "$TMPDIR[1]"/.psub.XXXXXXXXXX) - set filename $dirname/psub"$suffix" - cat >$filename - end + if test use_fifo = 1 + # 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 filename $dirname/psub.fifo"$suffix" + mkfifo $filename + cat >$filename & + else if test -z $suffix + set filename (mktemp "$TMPDIR[1]"/.psub.XXXXXXXXXX) + cat >$filename + else + set dirname (mktemp -d "$TMPDIR[1]"/.psub.XXXXXXXXXX) + set filename $dirname/psub"$suffix" + cat >$filename + end - # Write filename to stdout - echo $filename + # Write filename to stdout + echo $filename - # Find unique function name - while true - set funcname __fish_psub_(random); - if not functions $funcname >/dev/null ^/dev/null - break; - end - end + # Find unique function name + while true + set funcname __fish_psub_(random) - # Make sure we erase file when caller exits - function $funcname --on-job-exit caller --inherit-variable filename --inherit-variable dirname --inherit-variable funcname - command rm $filename - if count $dirname >/dev/null - command rmdir $dirname - end - functions -e $funcname - end + if not functions $funcname >/dev/null ^/dev/null + break + + end + end + + # Make sure we erase file when caller exits + function $funcname --on-job-exit caller --inherit-variable filename --inherit-variable dirname --inherit-variable funcname + command rm $filename + if count $dirname >/dev/null + command rmdir $dirname + end + functions -e $funcname + end end diff --git a/share/functions/pushd.fish b/share/functions/pushd.fish index 64f213ee1..b9847b4ce 100644 --- a/share/functions/pushd.fish +++ b/share/functions/pushd.fish @@ -1,77 +1,77 @@ function pushd --description 'Push directory to stack' - if count $argv >/dev/null - # check for --help - switch $argv[1] - case -h --h --he --hel --help - __fish_print_help pushd - return 0 - end + if count $argv >/dev/null + # check for --help + switch $argv[1] + case -h --h --he --hel --help + __fish_print_help pushd + return 0 + end - # emulate bash by checking if argument of form +n or -n - set -l rot_r - set -l rot_l - if string match -qr '^-[0-9]+$' -- $argv[1] - set rot_r (string sub -s 2 -- $argv[1]) - else if string match -qr '^\+[0-9]+$' -- $argv[1] - set rot_l (string sub -s 2 -- $argv[1]) - end - end + # emulate bash by checking if argument of form +n or -n + set -l rot_r + set -l rot_l + if string match -qr '^-[0-9]+$' -- $argv[1] + set rot_r (string sub -s 2 -- $argv[1]) + else if string match -qr '^\+[0-9]+$' -- $argv[1] + set rot_l (string sub -s 2 -- $argv[1]) + end + end - # emulate bash: an empty pushd should switch the top of dirs - if test (count $argv) -eq 0 - # check that the stack isn't empty - if test (count $dirstack) -eq 0 - echo "pushd: no other directory" - return 1 - end + # emulate bash: an empty pushd should switch the top of dirs + if test (count $argv) -eq 0 + # check that the stack isn't empty + if test (count $dirstack) -eq 0 + echo "pushd: no other directory" + return 1 + end - # get the top two values of the dirs stack ... the first is pwd - set -l top_dir (command pwd) - set -l next_dir $dirstack[1] + # get the top two values of the dirs stack ... the first is pwd + set -l top_dir (command pwd) + set -l next_dir $dirstack[1] - # alter the top of dirstack and move to directory - set -g dirstack[1] $top_dir - cd $next_dir - return - end + # alter the top of dirstack and move to directory + set -g dirstack[1] $top_dir + cd $next_dir + return + end - # emulate bash: check for rotations - if test -n "$rot_l" -o -n "$rot_r" - # grab the current stack - set -l stack (command pwd) $dirstack + # emulate bash: check for rotations + if test -n "$rot_l" -o -n "$rot_r" + # grab the current stack + set -l stack (command pwd) $dirstack - # translate a right rotation to a left rotation - if test -n "$rot_r" - # check the rotation in range - if test $rot_r -ge (count $stack) - echo "pushd: -$rot_r: directory stack index out of range" - return 1 - end + # translate a right rotation to a left rotation + if test -n "$rot_r" + # check the rotation in range + if test $rot_r -ge (count $stack) + echo "pushd: -$rot_r: directory stack index out of range" + return 1 + end - set rot_l (math (count $stack) - 1 - $rot_r) - end + set rot_l (math (count $stack) - 1 - $rot_r) + end - # check the rotation in range - if test $rot_l -ge (count $stack) - echo "pushd: +$rot_l: directory stack index out of range" - return 1 - else - # rotate stack unless rot_l is 0 - if test $rot_l -gt 0 - set stack $stack[(math $rot_l + 1)..(count $stack)] $stack[1..$rot_l] - end + # check the rotation in range + if test $rot_l -ge (count $stack) + echo "pushd: +$rot_l: directory stack index out of range" + return 1 + else + # rotate stack unless rot_l is 0 + if test $rot_l -gt 0 + set stack $stack[(math $rot_l + 1)..(count $stack)] $stack[1..$rot_l] + end - # now reconstruct dirstack and change directory - set -g dirstack $stack[2..(count $stack)] - cd $stack[1] - end + # now reconstruct dirstack and change directory + set -g dirstack $stack[2..(count $stack)] + cd $stack[1] + end - # print the new stack - dirs - return - end + # print the new stack + dirs + return + end - # argv[1] is a directory - set -g dirstack (command pwd) $dirstack - cd $argv[1] + # argv[1] is a directory + set -g dirstack (command pwd) $dirstack + cd $argv[1] end diff --git a/share/functions/seq.fish b/share/functions/seq.fish index 3675c9905..4d2af7541 100644 --- a/share/functions/seq.fish +++ b/share/functions/seq.fish @@ -2,47 +2,47 @@ # We can't call type here because that also calls seq if not command -s seq >/dev/null - # No seq command - function seq --description "Print sequences of numbers" - __fish_fallback_seq $argv - end + # No seq command + function seq --description "Print sequences of numbers" + __fish_fallback_seq $argv + end - function __fish_fallback_seq --description "Fallback implementation of the seq command" - - set -l from 1 - set -l step 1 - set -l to 1 - - switch (count $argv) - case 1 - set to $argv[1] - - case 2 - set from $argv[1] - set to $argv[2] - - case 3 - set from $argv[1] - set step $argv[2] - set to $argv[3] - - case '*' - printf (_ "%s: Expected 1, 2 or 3 arguments, got %d\n") seq (count $argv) - return 1 - - end - - for i in $from $step $to - if not echo $i | grep -E '^-?[0-9]*([0-9]*|\.[0-9]+)$' >/dev/null - printf (_ "%s: '%s' is not a number\n") seq $i - return 1 - end - end - - if [ $step -ge 0 ] - echo "for( i=$from; i<=$to ; i+=$step ) i;" | bc - else - echo "for( i=$from; i>=$to ; i+=$step ) i;" | bc - end - end + function __fish_fallback_seq --description "Fallback implementation of the seq command" + + set -l from 1 + set -l step 1 + set -l to 1 + + switch (count $argv) + case 1 + set to $argv[1] + + case 2 + set from $argv[1] + set to $argv[2] + + case 3 + set from $argv[1] + set step $argv[2] + set to $argv[3] + + case '*' + printf (_ "%s: Expected 1, 2 or 3 arguments, got %d\n") seq (count $argv) + return 1 + + end + + for i in $from $step $to + if not echo $i | grep -E '^-?[0-9]*([0-9]*|\.[0-9]+)$' >/dev/null + printf (_ "%s: '%s' is not a number\n") seq $i + return 1 + end + end + + if [ $step -ge 0 ] + echo "for( i=$from; i<=$to ; i+=$step ) i;" | bc + else + echo "for( i=$from; i>=$to ; i+=$step ) i;" | bc + end + end end diff --git a/share/functions/setenv.fish b/share/functions/setenv.fish index f32a17f6e..23cc94790 100644 --- a/share/functions/setenv.fish +++ b/share/functions/setenv.fish @@ -1,4 +1,4 @@ function setenv --description 'Set global variable. Alias for set -g, made for csh compatibility' - set -gx $argv + set -gx $argv end diff --git a/share/functions/suspend.fish b/share/functions/suspend.fish index af2ce5012..1d6e35a92 100644 --- a/share/functions/suspend.fish +++ b/share/functions/suspend.fish @@ -1,7 +1,8 @@ function suspend -d "Suspend the current shell." - if contains -- $argv --help; or contains -- $argv -h - __fish_print_help suspend - and return 0 + if contains -- $argv --help + or contains -- $argv -h + __fish_print_help suspend + and return 0 end if begin contains -- $argv --force or not status --is-interactive and not status --is-login diff --git a/share/functions/trap.fish b/share/functions/trap.fish index 094d37f1b..248d91f58 100644 --- a/share/functions/trap.fish +++ b/share/functions/trap.fish @@ -1,143 +1,143 @@ function __trap_translate_signal - set upper (echo $argv[1]|tr a-z A-Z) - string replace -r '^SIG' '' -- $upper + set upper (echo $argv[1]|tr a-z A-Z) + string replace -r '^SIG' '' -- $upper end function __trap_switch - switch $argv[1] - case EXIT - echo --on-process-exit %self + switch $argv[1] + case EXIT + echo --on-process-exit %self - case '*' - echo --on-signal $argv[1] - end + case '*' + echo --on-signal $argv[1] + end end function trap -d 'Perform an action when the shell receives a signal' - set -l mode - set -l cmd - set -l sig + set -l mode + set -l cmd + set -l sig - set -l options - set -l longopt - set -l shortopt lph - if not getopt -T > /dev/null - # GNU getopt - set longopt print,help,list-signals - set options -o $shortopt -l $longopt -- - # Verify options - if not getopt -n type $options $argv >/dev/null - return 1 - end - else - # Old getopt, used on OS X - set options $shortopt - # Verify options - if not getopt $options $argv >/dev/null - return 1 - end - end + set -l options + set -l longopt + set -l shortopt lph + if not getopt -T >/dev/null + # GNU getopt + set longopt print,help,list-signals + set options -o $shortopt -l $longopt -- + # Verify options + if not getopt -n type $options $argv >/dev/null + return 1 + end + else + # Old getopt, used on OS X + set options $shortopt + # Verify options + if not getopt $options $argv >/dev/null + return 1 + end + end - # Do the real getopt invocation - set -l tmp (getopt $options $argv) + # Do the real getopt invocation + set -l tmp (getopt $options $argv) - # Break tmp up into an array - set -l opt - eval set opt $tmp + # Break tmp up into an array + set -l opt + eval set opt $tmp - while count $opt >/dev/null - switch $opt[1] - case -h --help - __fish_print_help trap - return 0 + while count $opt >/dev/null + switch $opt[1] + case -h --help + __fish_print_help trap + return 0 - case -p --print - set mode print + case -p --print + set mode print - case -l --list-signals - set mode list + case -l --list-signals + set mode list - case -- - set -e opt[1] - break + case -- + set -e opt[1] + break - end - set -e opt[1] - end + end + set -e opt[1] + end - if not count $mode >/dev/null + if not count $mode >/dev/null - switch (count $opt) + switch (count $opt) - case 0 - set mode print + case 0 + set mode print - case 1 - set mode clear + case 1 + set mode clear - case '*' - if test opt[1] = - - set -e opt[1] - set mode clear - else - set mode set - end - end - end + case '*' + if test opt[1] = - + set -e opt[1] + set mode clear + else + set mode set + end + end + end - switch $mode - case clear - for i in $opt - set sig (__trap_translate_signal $i) - if test $sig - functions -e __trap_handler_$sig - end - end + switch $mode + case clear + for i in $opt + set sig (__trap_translate_signal $i) + if test $sig + functions -e __trap_handler_$sig + end + end - case set - set -l cmd $opt[1] - set -e opt[1] + case set + set -l cmd $opt[1] + set -e opt[1] - for i in $opt + for i in $opt - set -l sig (__trap_translate_signal $i) - set sw (__trap_switch $sig) + set -l sig (__trap_translate_signal $i) + set sw (__trap_switch $sig) - if test $sig - eval "function __trap_handler_$sig $sw; $cmd; end" - else - return 1 - end - end + if test $sig + eval "function __trap_handler_$sig $sw; $cmd; end" + else + return 1 + end + end - case print - set -l names + case print + set -l names - if count $opt >/dev/null - set names $opt - else - set names (functions -na| string match "__trap_handler_*" | string replace '__trap_handler_' '') - end + if count $opt >/dev/null + set names $opt + else + set names (functions -na| string match "__trap_handler_*" | string replace '__trap_handler_' '') + end - for i in $names + for i in $names - set sig (__trap_translate_signal $i) + set sig (__trap_translate_signal $i) - if test sig - functions __trap_handler_$i - else - return 1 - end + if test sig + functions __trap_handler_$i + else + return 1 + end - end + end - case list - kill -l + case list + kill -l - end + end end diff --git a/share/functions/type.fish b/share/functions/type.fish index ed113ea5d..ab0cd28b1 100644 --- a/share/functions/type.fish +++ b/share/functions/type.fish @@ -1,153 +1,156 @@ function type --description "Print the type of a command" - # Initialize - set -l res 1 - set -l mode normal - set -l multi no - set -l selection all - set -l IFS \n\ \t + # Initialize + set -l res 1 + set -l mode normal + set -l multi no + set -l selection all + set -l IFS \n\ \t - # Parse options - set -l names - if test (count $argv) -gt 0 - for i in (seq (count $argv)) - set -l arg $argv[$i] - set -l needbreak 0 - while test -n $arg - set -l flag $arg - set arg '' - switch $flag - case '--*' - # do nothing; this just prevents it matching the next case - case '-??*' - # combined flags - set -l IFS - echo -n $flag | read __ flag arg - set flag -$flag - set arg -$arg - end - switch $flag - case -t --type - if test $mode != quiet - set mode type - end + # Parse options + set -l names + if test (count $argv) -gt 0 + for i in (seq (count $argv)) + set -l arg $argv[$i] + set -l needbreak 0 + while test -n $arg + set -l flag $arg + set arg '' + switch $flag + case '--*' + # do nothing; this just prevents it matching the next case + case '-??*' + # combined flags + set -l IFS + echo -n $flag | read __ flag arg + set flag -$flag + set arg -$arg + end + switch $flag + case -t --type + if test $mode != quiet + set mode type + end - case -p --path - if test $mode != quiet - set mode path - end + case -p --path + if test $mode != quiet + set mode path + end - case -P --force-path - if test $mode != quiet - set mode path - end - set selection files + case -P --force-path + if test $mode != quiet + set mode path + end + set selection files - case -a --all - set multi yes + case -a --all + set multi yes - case -f --no-functions - set selection files + case -f --no-functions + set selection files - case -q --quiet - set mode quiet + case -q --quiet + set mode quiet - case -h --help - __fish_print_help type - return 0 + case -h --help + __fish_print_help type + return 0 - case -- - set names $argv[$i..-1] - set -e names[1] - set needbreak 1 - break + case -- + set names $argv[$i..-1] + set -e names[1] + set needbreak 1 + break - case '*' - set names $argv[$i..-1] - set needbreak 1 - break - end - end - if test $needbreak -eq 1 - break - end - end - end + case '*' + set names $argv[$i..-1] + set needbreak 1 + break + end + end + if test $needbreak -eq 1 + break + end + end + end - # Check all possible types for the remaining arguments - for i in $names - # Found will be set to 1 if a match is found - set -l found 0 + # Check all possible types for the remaining arguments + for i in $names + # Found will be set to 1 if a match is found + set -l found 0 - if test $selection != files + if test $selection != files - if functions -q -- $i - set res 0 - set found 1 - switch $mode - case normal - printf (_ '%s is a function with definition\n') $i - if isatty stdout - functions $i | fish_indent --ansi - else - functions $i | fish_indent - end - case type - echo (_ 'function') - end - if test $multi != yes - continue - end - end + if functions -q -- $i + set res 0 + set found 1 + switch $mode + case normal + printf (_ '%s is a function with definition\n') $i + if isatty stdout + functions $i | fish_indent --ansi + else + functions $i | fish_indent + end + case type + echo (_ 'function') + end + if test $multi != yes + continue + end + end - if contains -- $i (builtin -n) + if contains -- $i (builtin -n) - set res 0 - set found 1 - switch $mode - case normal - printf (_ '%s is a builtin\n') $i + set res 0 + set found 1 + switch $mode + case normal + printf (_ '%s is a builtin\n') $i - case type - echo (_ 'builtin') - end - if test $multi != yes - continue - end - end + case type + echo (_ 'builtin') + end + if test $multi != yes + continue + end + end - end + end - set -l paths - if test $multi != yes - set paths (command -s -- $i) - else - set paths (command which -a -- $i ^/dev/null) - end - for path in $paths - set res 0 - set found 1 - switch $mode - case normal - printf (_ '%s is %s\n') $i $path + set -l paths + if test $multi != yes + set paths (command -s -- $i) + else + set paths (command which -a -- $i ^/dev/null) + end + for path in $paths + set res 0 + set found 1 + switch $mode + case normal + printf (_ '%s is %s\n') $i $path - case type - echo (_ 'file') + case type + echo (_ 'file') - case path - echo $path - end - if test $multi != yes - continue - end - end + case path + echo $path + end + if test $multi != yes + continue + end + end - if begin; test $found = 0; and test $mode != quiet; end - printf (_ "%s: Could not find '%s'\n") type $i >&2 - end + if begin + test $found = 0 + and test $mode != quiet + end + printf (_ "%s: Could not find '%s'\n") type $i >&2 + end - end + end - return $res + return $res end diff --git a/share/functions/umask.fish b/share/functions/umask.fish index a03c39b7e..4ad547818 100644 --- a/share/functions/umask.fish +++ b/share/functions/umask.fish @@ -1,216 +1,218 @@ 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 - echo $argv - else - # Test if argument really is a valid symbolic mask - if not echo $argv | __fish_sgrep -E '^(((u|g|o|a|)(=|\+|-)|)(r|w|x)*)(,(((u|g|o|a|)(=|\+|-)|)(r|w|x)*))*$' >/dev/null - printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2 - return 1 - end + # 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 + echo $argv + else + # Test if argument really is a valid symbolic mask + if not echo $argv | __fish_sgrep -E '^(((u|g|o|a|)(=|\+|-)|)(r|w|x)*)(,(((u|g|o|a|)(=|\+|-)|)(r|w|x)*))*$' >/dev/null + printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2 + return 1 + end - set -l implicit_all + set -l implicit_all - # Insert inverted umask into res variable + # Insert inverted umask into res variable - set -l mode - set -l val - set -l tmp $umask - set -l res + set -l mode + set -l val + set -l tmp $umask + set -l res - for i in 1 2 3 - set tmp (echo $tmp|cut -c 2-) - set -l char_count (echo $tmp|cut -c 1) - set res[$i] (math 7 - $char_count) - end + for i in 1 2 3 + set tmp (echo $tmp|cut -c 2-) + set -l char_count (echo $tmp|cut -c 1) + set res[$i] (math 7 - $char_count) + end - set -l el (echo $argv|tr , \n) - for i in $el - switch $i - case 'u*' - set idx 1 - set i (echo $i| cut -c 2-) + set -l el (echo $argv|tr , \n) + for i in $el + switch $i + case 'u*' + set idx 1 + set i (echo $i| cut -c 2-) - case 'g*' - set idx 2 - set i (echo $i| cut -c 2-) + case 'g*' + set idx 2 + set i (echo $i| cut -c 2-) - case 'o*' - set idx 3 - set i (echo $i| cut -c 2-) + case 'o*' + set idx 3 + set i (echo $i| cut -c 2-) - case 'a*' - set idx 1 2 3 - set i (echo $i| cut -c 2-) + case 'a*' + set idx 1 2 3 + set i (echo $i| cut -c 2-) - case '*' - set implicit_all 1 - set idx 1 2 3 - end + case '*' + set implicit_all 1 + set idx 1 2 3 + end - switch $i - case '=*' - set mode set - set i (echo $i| cut -c 2-) + switch $i + case '=*' + set mode set + set i (echo $i| cut -c 2-) - case '+*' - set mode add - set i (echo $i| cut -c 2-) + case '+*' + set mode add + set i (echo $i| cut -c 2-) - case '-*' - set mode remove - set i (echo $i| cut -c 2-) + case '-*' + set mode remove + set i (echo $i| cut -c 2-) - case '*' - if not count $implicit_all >/dev/null - printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2 - return - end - set mode set - end + case '*' + if not count $implicit_all >/dev/null + printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2 + return + end + set mode set + end - if not echo $perm| __fish_sgrep -E '^(r|w|x)*$' >/dev/null - printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2 - return - end + if not echo $perm | __fish_sgrep -E '^(r|w|x)*$' >/dev/null + printf (_ "%s: Invalid mask '%s'\n") umask $argv >&2 + return + end - set val 0 - if echo $i | __fish_sgrep 'r' >/dev/null - set val 4 - end - if echo $i | __fish_sgrep 'w' >/dev/null - set val (math $val + 2) - end - if echo $i | __fish_sgrep 'x' >/dev/null - set val (math $val + 1) - end + set val 0 + if echo $i | __fish_sgrep 'r' >/dev/null + set val 4 + end + if echo $i | __fish_sgrep 'w' >/dev/null + set val (math $val + 2) + end + if echo $i | __fish_sgrep 'x' >/dev/null + set val (math $val + 1) + end - for j in $idx - switch $mode - case set - set res[$j] $val + for j in $idx + switch $mode + case set + set res[$j] $val - case add - set res[$j] (perl -e 'print( ( '$res[$j]'|'$val[$j]' )."\n" )') + case add + set res[$j] (perl -e 'print( ( '$res[$j]'|'$val[$j]' )."\n" )') - case remove - set res[$j] (perl -e 'print( ( (7-'$res[$j]')&'$val[$j]' )."\n" )') - end - end - end + case remove + set res[$j] (perl -e 'print( ( (7-'$res[$j]')&'$val[$j]' )."\n" )') + end + end + end - for i in 1 2 3 - set res[$i] (math 7 - $res[$i]) - end - echo 0$res[1]$res[2]$res[3] - end + for i in 1 2 3 + set res[$i] (math 7 - $res[$i]) + end + echo 0$res[1]$res[2]$res[3] + end end function __fish_umask_print_symbolic - set -l res "" - set -l letter a u g o + set -l res "" + set -l letter a u g o - for i in 2 3 4 - set res $res,$letter[$i]= - set val (echo $umask|cut -c $i) + for i in 2 3 4 + set res $res,$letter[$i]= + set val (echo $umask|cut -c $i) - if contains $val 0 1 2 3 - set res {$res}r - end + if contains $val 0 1 2 3 + set res {$res}r + end - if contains $val 0 1 4 5 - set res {$res}w - end + if contains $val 0 1 4 5 + set res {$res}w + end - if contains $val 0 2 4 6 - set res {$res}x - end + if contains $val 0 2 4 6 + set res {$res}x + end - end + end - echo $res|cut -c 2- + echo $res | cut -c 2- end function umask --description "Set default file permission mask" - set -l as_command 0 - set -l symbolic 0 - - set -l options - set -l shortopt pSh - if not getopt -T >/dev/null - # GNU getopt - set longopt -l as-command,symbolic,help - set options -o $shortopt $longopt -- - # Verify options - if not getopt -n umask $options $argv >/dev/null - return 1 - end - else - # Old getopt, used on OS X - set options $shortopt - # Verify options - if not getopt $options $argv >/dev/null - return 1 - end - end + set -l as_command 0 + set -l symbolic 0 - set -l tmp (getopt $options $argv) - eval set opt $tmp + set -l options + set -l shortopt pSh + if not getopt -T >/dev/null + # GNU getopt + set longopt -l as-command,symbolic,help + set options -o $shortopt $longopt -- + # Verify options + if not getopt -n umask $options $argv >/dev/null + return 1 + end + else + # Old getopt, used on OS X + set options $shortopt + # Verify options + if not getopt $options $argv >/dev/null + return 1 + end + end - while count $opt >/dev/null + set -l tmp (getopt $options $argv) + eval set opt $tmp - switch $opt[1] - case -h --help - __fish_print_help umask - return 0 + while count $opt >/dev/null - case -p --as-command - set as_command 1 + switch $opt[1] + case -h --help + __fish_print_help umask + return 0 - case -S --symbolic - set symbolic 1 + case -p --as-command + set as_command 1 - case -- - set -e opt[1] - break + case -S --symbolic + set symbolic 1 - end + case -- + set -e opt[1] + break - set -e opt[1] + end - end + set -e opt[1] - switch (count $opt) + end - case 0 - if not set -q umask - set -g umask 113 - end - if test $as_command -eq 1 - echo umask $umask - else - if test $symbolic -eq 1 - __fish_umask_print_symbolic $umask - else - echo $umask - end - end + switch (count $opt) - case 1 - set -l parsed (__fish_umask_parse $opt) - if test (count $parsed) -eq 1 - set -g umask $parsed - return 0 - end - return 1 + case 0 + if not set -q umask + set -g umask 113 + end + if test $as_command -eq 1 + echo umask $umask + else + if test $symbolic -eq 1 + __fish_umask_print_symbolic $umask + else + echo $umask + end + end - case '*' - printf (_ '%s: Too many arguments\n') umask >&2 + case 1 + set -l parsed (__fish_umask_parse $opt) + if test (count $parsed) -eq 1 + set -g umask $parsed + return 0 + end + return 1 - end + case '*' + printf (_ '%s: Too many arguments\n') umask >&2 + + end end diff --git a/share/functions/up-or-search.fish b/share/functions/up-or-search.fish index 98179ad7c..e0e64f6dd 100644 --- a/share/functions/up-or-search.fish +++ b/share/functions/up-or-search.fish @@ -1,26 +1,26 @@ function up-or-search -d "Depending on cursor position and current mode, either search backward or move up one line" - # If we are already in search mode, continue - if commandline --search-mode - commandline -f history-search-backward - return - end + # If we are already in search mode, continue + if commandline --search-mode + commandline -f history-search-backward + return + end - # If we are navigating the pager, then up always navigates - if commandline --paging-mode - commandline -f up-line - return - end + # If we are navigating the pager, then up always navigates + if commandline --paging-mode + commandline -f up-line + return + end - # We are not already in search mode. - # If we are on the top line, start search mode, - # otherwise move up - set lineno (commandline -L) + # We are not already in search mode. + # If we are on the top line, start search mode, + # otherwise move up + set lineno (commandline -L) - switch $lineno - case 1 - commandline -f history-search-backward + switch $lineno + case 1 + commandline -f history-search-backward - case '*' - commandline -f up-line - end + case '*' + commandline -f up-line + end end diff --git a/share/functions/vared.fish b/share/functions/vared.fish index ecd157e9d..f14794df7 100644 --- a/share/functions/vared.fish +++ b/share/functions/vared.fish @@ -4,43 +4,43 @@ # function vared --description "Edit variable value" - if test (count $argv) = 1 - switch $argv + if test (count $argv) = 1 + switch $argv - case '-h' '--h' '--he' '--hel' '--help' - __fish_print_help vared - return 0 + case '-h' '--h' '--he' '--hel' '--help' + __fish_print_help vared + return 0 - case '-*' - printf (_ "%s: Unknown option %s\n") vared $argv - return 1 + case '-*' + printf (_ "%s: Unknown option %s\n") vared $argv + return 1 - case '*' - if test (count $$argv ) -lt 2 - set -l init '' - if test $$argv - set init $$argv - end - set -l prompt 'set_color green; echo '$argv'; set_color normal; echo "> "' - if read -p $prompt -c $init tmp + case '*' + if test (count $$argv ) -lt 2 + set -l init '' + if test $$argv + set init $$argv + end + set -l prompt 'set_color green; echo '$argv'; set_color normal; echo "> "' + if read -p $prompt -c $init tmp - # If variable already exists, do not add any - # switches, so we don't change export rules. But - # if it does not exist, we make the variable - # global, so that it will not die when this - # function dies + # If variable already exists, do not add any + # switches, so we don't change export rules. But + # if it does not exist, we make the variable + # global, so that it will not die when this + # function dies - if test $$argv - set $argv $tmp - else - set -g $argv $tmp - end - end - else - printf (_ '%s: %s is an array variable. Use %svared%s %s[n]%s to edit the n:th element of %s\n') vared $argv (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) $argv (set_color normal; echo) $argv - end - end - else - printf (_ '%s: Expected exactly one argument, got %s.\n\nSynopsis:\n\t%svared%s VARIABLE\n') vared (count $argv) (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) - end + if test $$argv + set $argv $tmp + else + set -g $argv $tmp + end + end + else + printf (_ '%s: %s is an array variable. Use %svared%s %s[n]%s to edit the n:th element of %s\n') vared $argv (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) $argv (set_color normal; echo) $argv + end + end + else + printf (_ '%s: Expected exactly one argument, got %s.\n\nSynopsis:\n\t%svared%s VARIABLE\n') vared (count $argv) (set_color $fish_color_command; echo) (set_color $fish_color_normal; echo) + end end