diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-20 16:47:37 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-20 16:47:37 +1200 |
commit | fa2f423345776d8a99dae604f89e5b0ba76ceabb (patch) | |
tree | 8e1d83f9ea24ce519246b52921cc66350e39bdd0 /bash/bashrc.d | |
parent | Remove readv() and readz() (diff) | |
download | dotfiles-fa2f423345776d8a99dae604f89e5b0ba76ceabb.tar.gz dotfiles-fa2f423345776d8a99dae604f89e5b0ba76ceabb.zip |
Port fnl() to POSIX sh script fnl(1)
No real compelling reason to make it a shell function in the first
place.
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r-- | bash/bashrc.d/fnl.bash | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/bash/bashrc.d/fnl.bash b/bash/bashrc.d/fnl.bash deleted file mode 100644 index 1f543dbf..00000000 --- a/bash/bashrc.d/fnl.bash +++ /dev/null @@ -1,41 +0,0 @@ -# Run a command and push its stdout and stderr into temporary files, printing -# the names of the files once done, and saving them into two variables. Return -# the exit status of the command. -# -# $ fnl grep foo /bar -# declare -p fnl_stdout="/tmp/fnl.xQmhe/stdout" -# declare -p fnl_stderr="/tmp/fnl.xQmhe/stderr" -# -fnl() { - - # Must be called with at least one command argument - if ! (($#)) ; then - printf 'bash: %s: usage: %s COMMAND [ARG1 ...]\n' \ - "$FUNCNAME" "$FUNCNAME" >&2 - return 2 - fi - - # Try to stop infinitely recursive calls - if [[ $1 == "$FUNCNAME" ]] ; then - printf 'bash: %s: Cannot nest calls\n' \ - "$FUNCNAME" >&2 - return 2 - fi - - # Create a temporary directory or bail - local dirname - dirname=$(mktd "$FUNCNAME") || return - - # Run the command and save its exit status - local ret - "$@" >"$dirname"/stdout 2>"$dirname"/stderr - ret=$? - - # Note these are *not* local variables - # shellcheck disable=SC2034 - fnl_stdout=$dirname/stdout fnl_stderr=$dirname/stderr - declare -p fnl_std{out,err} - - # Return the exit status of the command, not the declare builtin - return "$ret" -} |