diff options
author | Kevin Ballard <kevin@sb.org> | 2014-10-02 16:32:16 -0700 |
---|---|---|
committer | Kevin Ballard <kevin@sb.org> | 2014-10-02 18:41:39 -0700 |
commit | 33a76e1f8e386e2bfce1613cc164908f0939bc27 (patch) | |
tree | d937046b87ba49fafa2ebbf935826b83a9a2c1d4 /share/functions/psub.fish | |
parent | cfc06203e7ad7707acadd160292d47b25d6daba6 (diff) |
Update psub for the new --inherit-variable flag
Also do some minor formatting cleanup, make psub return 1 when executed
outside of a command substitution, and make it respect $TMPDIR.
Diffstat (limited to 'share/functions/psub.fish')
-rw-r--r-- | share/functions/psub.fish | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/share/functions/psub.fish b/share/functions/psub.fish index 7877aa4e..67863ad0 100644 --- a/share/functions/psub.fish +++ b/share/functions/psub.fish @@ -42,19 +42,24 @@ function psub --description "Read from stdin into a file and output the filename if not status --is-command-substitution echo psub: Not inside of command substitution >&2 - return + return 1 + 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 dir (mktemp -d /tmp/.psub.XXXXXXXXXX); or return - set filename $dir/psub.fifo + set dir (mktemp -d "$TMPDIR[1]"/.psub.XXXXXXXXXX); or return + set filename $dir/psub.fifo mkfifo $filename cat >$filename & else - set filename (mktemp /tmp/.psub.XXXXXXXXXX) + set filename (mktemp "$TMPDIR[1]"/.psub.XXXXXXXXXX) cat >$filename end @@ -70,6 +75,9 @@ function psub --description "Read from stdin into a file and output the filename end # Make sure we erase file when caller exits - eval function $funcname --on-job-exit caller\; command rm $filename\; functions -e $funcname\; end + function $funcname --on-job-exit caller --inherit-variable filename --inherit-variable funcname + command rm $filename + functions -e $funcname + end end |