mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
Add a -f switch to psub to use regular files instead of fifos. This makes psub work with programs that need to seek. This change was suggested by Alexander Kellet.
darcs-hash:20070115174330-ac50b-2349cef2d1a26a9e7c9356691bc74991135c1d2c.gz
This commit is contained in:
parent
5753d63958
commit
c6ebb23f38
@ -4,17 +4,40 @@ function psub -d (N_ "Read from stdin into a file and output the filename. Remov
|
|||||||
|
|
||||||
set -l filename
|
set -l filename
|
||||||
set -l funcname
|
set -l funcname
|
||||||
|
set -l use_fifo 1
|
||||||
|
set -l shortopt -o hf
|
||||||
|
set -l longopt -l help,file
|
||||||
|
|
||||||
if count $argv >/dev/null
|
if getopt -T >/dev/null
|
||||||
switch $argv[1]
|
set longopt
|
||||||
case '-h*' --h --he --hel --help
|
end
|
||||||
|
|
||||||
|
if not getopt -n psub -Q $shortopt $longopt -- $argv
|
||||||
|
return 1
|
||||||
|
end
|
||||||
|
|
||||||
|
set -l tmp (getopt $shortopt $longopt -- $argv)
|
||||||
|
|
||||||
|
eval set opt $tmp
|
||||||
|
|
||||||
|
while count $opt >/dev/null
|
||||||
|
|
||||||
|
switch $opt[1]
|
||||||
|
case -h --help
|
||||||
__fish_print_help psub
|
__fish_print_help psub
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
case '*'
|
case -f --file
|
||||||
printf (_ "%s: Unknown argument '%s'\n") psub $argv[1]
|
set use_fifo 0
|
||||||
return 1
|
|
||||||
|
case --
|
||||||
|
set -e opt[1]
|
||||||
|
break
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
set -e opt[1]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not status --is-command-substitution
|
if not status --is-command-substitution
|
||||||
@ -30,11 +53,15 @@ function psub -d (N_ "Read from stdin into a file and output the filename. Remov
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write output to pipe. This needs to be done in the background so
|
if test use_fifo = 1
|
||||||
# that the command substitution exits without needing to wait for
|
# Write output to pipe. This needs to be done in the background so
|
||||||
# all the commands to exit
|
# that the command substitution exits without needing to wait for
|
||||||
mkfifo $filename
|
# all the commands to exit
|
||||||
cat >$filename &
|
mkfifo $filename
|
||||||
|
cat >$filename &
|
||||||
|
else
|
||||||
|
cat >$filename
|
||||||
|
end
|
||||||
|
|
||||||
# Write filename to stdout
|
# Write filename to stdout
|
||||||
echo $filename
|
echo $filename
|
||||||
|
Loading…
x
Reference in New Issue
Block a user