remove some uses of $IFS

This is a step towards resolving issue #4156. It replaces uses of `$IFS`
with other solutions.
This commit is contained in:
Kurtis Rader 2017-07-24 20:45:43 -07:00
parent 6f46f6b45a
commit 8e87d595b7
9 changed files with 187 additions and 228 deletions

View file

@ -3,17 +3,12 @@ complete -c dd -d 'display help and exit' -xa '--help'
complete -c dd -d 'output version information and exit' -xa '--version' complete -c dd -d 'output version information and exit' -xa '--version'
function __fish_complete_dd --description 'Complete dd operands' function __fish_complete_dd --description 'Complete dd operands'
# set operand_string as a local variable containing the current command-line token. # set operand_string as a local variable containing the current command-line token.
set -l operand_string (commandline -t) set -l operand_string (commandline -t)
switch $operand_string switch $operand_string
case 'if=*' 'of=*' case 'if=*' 'of=*'
# the read command uses $IFS to tokenise stdin input string replace = ' ' -- $operand_string | read -l operand value
set -l IFS =
# $operand now contains the left side of the operator, $value the right
echo $operand_string | read -l operand value
for entry in $value* for entry in $value*
# if $entry is a directory, append a '/' # if $entry is a directory, append a '/'
@ -25,18 +20,9 @@ function __fish_complete_dd --description 'Complete dd operands'
end end
case 'iflag=*' 'oflag=*' case 'iflag=*' 'oflag=*'
set -l IFS = string replace = ' ' -- $operand_string | read -l operand complete
echo $operand_string | read -l operand value string match -q '*,' -- $complete
or set complete ''
set -l IFS ' '
echo $value | sed -e 's/\(.*\)\(,\)/\1 \2/' | read -l complete comma
# check if there is only one option
if test $comma = ''
set complete ''
else
set complete $complete,
end
printf "%s\t%s\n" "$operand=$complete""append" "append mode (makes sense only for output; conv=notrunc suggested)" printf "%s\t%s\n" "$operand=$complete""append" "append mode (makes sense only for output; conv=notrunc suggested)"
printf "%s\t%s\n" "$operand=$complete""direct" "use direct I/O for data" printf "%s\t%s\n" "$operand=$complete""direct" "use direct I/O for data"
@ -51,17 +37,9 @@ function __fish_complete_dd --description 'Complete dd operands'
printf "%s\t%s\n" "$operand=$complete""nofollow" "do not follow symbolic links" printf "%s\t%s\n" "$operand=$complete""nofollow" "do not follow symbolic links"
case 'conv=*' case 'conv=*'
set -l IFS = string replace = ' ' -- $operand_string | read -l operand complete
echo $operand_string | read -l operand value string match -q '*,' -- $complete
or set complete ''
set -l IFS ' '
echo $value | sed -e 's/\(.*\)\(,\)/\1 \2/' | read -l complete comma
if test $comma = ''
set complete ''
else
set complete $complete,
end
printf "%s\t%s\n" "$operand=$complete""ascii" "from EBCDIC to ASCII" printf "%s\t%s\n" "$operand=$complete""ascii" "from EBCDIC to ASCII"
printf "%s\t%s\n" "$operand=$complete""ebcdic" "from ASCII to EBCDIC" printf "%s\t%s\n" "$operand=$complete""ebcdic" "from ASCII to EBCDIC"

View file

@ -5,10 +5,7 @@ function __fish_iptables_current_table
for token in (commandline -oc) for token in (commandline -oc)
switch $token switch $token
case "--table=*" case "--table=*"
set -l IFS "=" echo (string split -m1 = -- $token)[2]
echo $token | while read a b
echo $b
end
return 0 return 0
case "--table" case "--table"
set next_is_table 0 set next_is_table 0
@ -40,7 +37,8 @@ end
function __fish_iptables_chains function __fish_iptables_chains
set -l table (__fish_iptables_current_table) set -l table (__fish_iptables_current_table)
[ -z $table ]; and set -l table "*" [ -z $table ]
and set -l table "*"
set -l prerouting "PREROUTING For packets that are coming in" set -l prerouting "PREROUTING For packets that are coming in"
set -l input "INPUT For packets destined to local sockets" set -l input "INPUT For packets destined to local sockets"
set -l output "OUTPUT For locally-generated packets" set -l output "OUTPUT For locally-generated packets"
@ -80,9 +78,7 @@ end
function __fish_iptables_has_chain function __fish_iptables_has_chain
# Remove descriptions # Remove descriptions
set -l IFS " " set -l chains (__fish_iptables_chains | string split -m1 " " | while read a b; echo $a; end)
set -l chains (__fish_iptables_chains | while read a b; echo $a; end)
set -e IFS
set -l cmdline (commandline -op) set -l cmdline (commandline -op)
for c in $chains for c in $chains
if contains -- $c $cmdline if contains -- $c $cmdline

View file

@ -1,9 +1,5 @@
set -l systemd_version (systemctl --version | string match "systemd*" | string replace -r "\D*(\d+)" '$1') set -l systemd_version (systemctl --version | string match "systemd*" | string replace -r "\D*(\d+)" '$1')
set -l commands list-units list-sockets start stop reload restart try-restart reload-or-restart reload-or-try-restart \ set -l commands list-units list-sockets start stop reload restart try-restart reload-or-restart reload-or-try-restart isolate kill is-active is-failed status show get-cgroup-attr set-cgroup-attr unset-cgroup-attr set-cgroup help reset-failed list-unit-files enable disable is-enabled reenable preset mask unmask link load list-jobs cancel dump list-dependencies snapshot delete daemon-reload daemon-reexec show-environment set-environment unset-environment default rescue emergency halt poweroff reboot kexec exit suspend hibernate hybrid-sleep switch-root
isolate kill is-active is-failed status show get-cgroup-attr set-cgroup-attr unset-cgroup-attr set-cgroup help \
reset-failed list-unit-files enable disable is-enabled reenable preset mask unmask link load list-jobs cancel dump \
list-dependencies snapshot delete daemon-reload daemon-reexec show-environment set-environment unset-environment \
default rescue emergency halt poweroff reboot kexec exit suspend hibernate hybrid-sleep switch-root
if test $systemd_version -gt 208 if test $systemd_version -gt 208
set commands $commands cat set commands $commands cat
if test $systemd_version -gt 217 if test $systemd_version -gt 217
@ -14,18 +10,14 @@ set -l types services sockets mounts service_paths targets automounts timers
function __fish_systemd_properties function __fish_systemd_properties
if type -q /usr/lib/systemd/systemd if type -q /usr/lib/systemd/systemd
set IFS "=" /usr/lib/systemd/systemd --dump-configuration-items | string split -m1 = | while read key value
/usr/lib/systemd/systemd --dump-configuration-items | while read key value test -n "$value"
if not test -z $value and echo $key
echo $key
end
end end
else if type -q /lib/systemd/systemd # Debian has not merged /lib and /usr/lib else if type -q /lib/systemd/systemd # Debian has not merged /lib and /usr/lib
set IFS "=" /lib/systemd/systemd --dump-configuration-items | string split -m1 = | while read key value
/lib/systemd/systemd --dump-configuration-items | while read key value test -n "$value"
if not test -z $value and echo $key
echo $key
end
end end
end end
end end

View file

@ -7,21 +7,23 @@ end
function __fish_vagrant_using_command function __fish_vagrant_using_command
set -l cmd (commandline -opc) set -l cmd (commandline -opc)
set -q cmd[2]; and test "$argv[1]" = $cmd[2] set -q cmd[2]
and test "$argv[1]" = $cmd[2]
end end
function __fish_vagrant_using_command_and_no_subcommand function __fish_vagrant_using_command_and_no_subcommand
set -l cmd (commandline -opc) set -l cmd (commandline -opc)
test (count $cmd) -eq 2; and test "$argv[1]" = "$cmd[2]" test (count $cmd) -eq 2
and test "$argv[1]" = "$cmd[2]"
end end
function __fish_vagrant_using_subcommand --argument-names cmd_main cmd_sub function __fish_vagrant_using_subcommand --argument-names cmd_main cmd_sub
set -l cmd (commandline -opc) set -l cmd (commandline -opc)
set -q cmd[3]; and test "$cmd_main" = $cmd[2] -a "$cmd_sub" = $cmd[3] set -q cmd[3]
and test "$cmd_main" = $cmd[2] -a "$cmd_sub" = $cmd[3]
end end
function __fish_vagrant_boxes --description 'Lists all available Vagrant boxes' function __fish_vagrant_boxes --description 'Lists all available Vagrant boxes'
set -l IFS \n\ \t
command vagrant box list | while read -l name _ command vagrant box list | while read -l name _
echo $name echo $name
end end

View file

@ -2,8 +2,7 @@ function __fish_complete_lpr_option --description 'Complete lpr option'
set -l optstr (commandline -t) set -l optstr (commandline -t)
switch $optstr switch $optstr
case '*=*' case '*=*'
set -l IFS = string split -m1 = -- "$optstr" | read -l opt val
echo $optstr | read -l opt val
set -l descr set -l descr
for l in (lpoptions -l ^/dev/null | string match -- "*$opt*" | string replace -r '.*/(.*):\s*(.*)$' '$1 $2' | string split " ") for l in (lpoptions -l ^/dev/null | string match -- "*$opt*" | string replace -r '.*/(.*):\s*(.*)$' '$1 $2' | string split " ")
if not set -q descr[1] if not set -q descr[1]

View file

@ -265,8 +265,7 @@ function __fish_git_prompt_show_upstream --description "Helper function for __fi
# Use fetch config to fix upstream # Use fetch config to fix upstream
set -l fetch_val (command git config "$cur_prefix".fetch) set -l fetch_val (command git config "$cur_prefix".fetch)
if test -n "$fetch_val" if test -n "$fetch_val"
set -l IFS : string split -m1 : -- "$fetch_val" | read -l trunk pattern
echo "$fetch_val" | read -l trunk pattern
set upstream (string replace -r -- "/$trunk\$" '' $pattern) /$upstream set upstream (string replace -r -- "/$trunk\$" '' $pattern) /$upstream
end end
end end

View file

@ -15,8 +15,6 @@ function __fish_print_help --description "Print help message for the specified f
return return
end end
set -l IFS \n\ \t
# Render help output, save output into the variable 'help' # Render help output, save output into the variable 'help'
set -l help set -l help
set -l cols set -l cols

View file

@ -56,25 +56,21 @@ function funced --description 'Edit function definition'
end end
if test "$editor" = fish if test "$editor" = fish
set -l IFS
if functions -q -- $funcname if functions -q -- $funcname
# Shadow IFS here to avoid array splitting in command substitution functions -- $funcname | fish_indent --no-indent | read -z init
set init (functions -- $funcname | fish_indent --no-indent)
end end
set -l prompt 'printf "%s%s%s> " (set_color green) '$funcname' (set_color normal)' set -l prompt 'printf "%s%s%s> " (set_color green) '$funcname' (set_color normal)'
# Unshadow IFS since the fish_title breaks otherwise
set -e IFS
if read -p $prompt -c "$init" -s cmd if read -p $prompt -c "$init" -s cmd
# Shadow IFS _again_ to avoid array splitting in command substitution echo -n $cmd | fish_indent | read -lz cmd
set -l IFS eval "$cmd"
eval (echo -n $cmd | fish_indent)
end end
return 0 return 0
end end
# OSX mktemp is rather restricted - no suffix, no way to automatically use TMPDIR # OS X (macOS) `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 # 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 set -q TMPDIR
or set -l TMPDIR /tmp or set -l TMPDIR /tmp
set -l tmpdir (mktemp -d $TMPDIR/fish.XXXXXX) set -l tmpdir (mktemp -d $TMPDIR/fish.XXXXXX)

View file

@ -50,8 +50,7 @@ function mktemp
# So let's outlaw them anywhere besides the end. # So let's outlaw them anywhere besides the end.
# Similarly GNU sed requires at least 3 X's, BSD sed requires none. Let's require 3. # Similarly GNU sed requires at least 3 X's, BSD sed requires none. Let's require 3.
begin begin
set -l IFS set -l chars (string split '' -- $template)
printf '%s' "$template" | read -la chars
set -l found_x set -l found_x
for c in $chars for c in $chars
if test $c = X if test $c = X