diff options
author | axel <axel@liljencrantz.se> | 2007-01-16 03:43:30 +1000 |
---|---|---|
committer | axel <axel@liljencrantz.se> | 2007-01-16 03:43:30 +1000 |
commit | c6ebb23f38218c561888cfb83a683c51affaa7e3 (patch) | |
tree | 03e2d42cdfe974e64bf40619fde45b90f0db9d37 /share | |
parent | 5753d6395839ca11ea6c7e48474db5798ad5d7d7 (diff) |
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
Diffstat (limited to 'share')
-rw-r--r-- | share/functions/psub.fish | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/share/functions/psub.fish b/share/functions/psub.fish index e6d3d0fb..c40c90b1 100644 --- a/share/functions/psub.fish +++ b/share/functions/psub.fish @@ -4,17 +4,40 @@ function psub -d (N_ "Read from stdin into a file and output the filename. Remov set -l filename set -l funcname + set -l use_fifo 1 + set -l shortopt -o hf + set -l longopt -l help,file - if count $argv >/dev/null - switch $argv[1] - case '-h*' --h --he --hel --help + if getopt -T >/dev/null + set longopt + 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 return 0 - case '*' - printf (_ "%s: Unknown argument '%s'\n") psub $argv[1] - return 1 + case -f --file + set use_fifo 0 + + case -- + set -e opt[1] + break + end + + set -e opt[1] + end 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 - # 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 - mkfifo $filename - cat >$filename & + 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 + mkfifo $filename + cat >$filename & + else + cat >$filename + end # Write filename to stdout echo $filename |