diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-02 00:24:39 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-07-02 00:24:39 +1200 |
commit | ef9a12e780efdd1eb0ddcb745b9d93e312353b73 (patch) | |
tree | 52672882a2f8c89cd76ef5df0ef706e8bbb933d5 /bash/bashrc.d/ed.bash | |
parent | Terser pa/paz implementations (diff) | |
download | dotfiles-ef9a12e780efdd1eb0ddcb745b9d93e312353b73.tar.gz dotfiles-ef9a12e780efdd1eb0ddcb745b9d93e312353b73.zip |
Use set rather than building arg arrays
Allows for terser functions and avoids error-prone local variables; also
nicer to have a single `command` call at the end of the function
(although there are still two at the end of the ed(1) wrapper)
Diffstat (limited to 'bash/bashrc.d/ed.bash')
-rw-r--r-- | bash/bashrc.d/ed.bash | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/bash/bashrc.d/ed.bash b/bash/bashrc.d/ed.bash index 0f069b85..4653743b 100644 --- a/bash/bashrc.d/ed.bash +++ b/bash/bashrc.d/ed.bash @@ -4,26 +4,23 @@ # it's available. ed() { - # Options for ed(1), and a command string in which to wrap the call if - # appropriate - local -a opts wrap - + # We're only adding options if input is from a terminal if [[ -t 0 ]] ; then - # Assemble options for interactive use: colon prompt, and verbose if - # available (-p is POSIX, but -v is not) - opts=(-p :) - if ed -sv - </dev/null >&0 2>&0 ; then - opts[${#opts[@]}]=-v - fi + # Colon prompt (POSIX) + set -- -p : "$@" - # Use rlwrap(1) if it's available, but don't throw a fit if it isn't - if hash rlwrap 2>/dev/null ; then - wrap=(rlwrap) + # Verbose if availble (not POSIX) + if ed -sv - </dev/null >&0 2>&0 ; then + set -- -v "$@" fi fi # Execute the ed(1) call, in a wrapper if appropriate and with the # concluded options - command "${wrap[@]}" ed "${opts[@]}" "$@" + if [[ -t 0 ]] && hash rlwrap 2>/dev/null ; then + command rlwrap ed "$@" + else + command ed "$@" + fi } |