aboutsummaryrefslogtreecommitdiff
path: root/sh/shrc.d/ed.sh
diff options
context:
space:
mode:
Diffstat (limited to 'sh/shrc.d/ed.sh')
-rw-r--r--sh/shrc.d/ed.sh38
1 files changed, 18 insertions, 20 deletions
diff --git a/sh/shrc.d/ed.sh b/sh/shrc.d/ed.sh
index 4638d2cb..243dcffc 100644
--- a/sh/shrc.d/ed.sh
+++ b/sh/shrc.d/ed.sh
@@ -1,26 +1,24 @@
-# Add a colon prompt to ed when a command is expected rather than text; makes
-# it feel a lot more like using ex. Only do this when stdin is a terminal,
-# however. Also try and use -v for more verbose error output, and rlwrap(1) if
-# it's available.
+# Define function proper
ed() {
- # We're only adding options if input is from a terminal
- if [ -t 0 ] ; then
+ # Don't mess with original call if input not a terminal
+ if ! [ -t 0 ] ; then
+ command ed "$@"
+ return
+ fi
- # Colon prompt (POSIX)
- set -- -p : "$@"
+ # Add --verbose to explain errors
+ [ -e "$HOME"/.cache/ed/verbose ] &&
+ set -- --verbose "$@"
- # Verbose if available (not POSIX)
- if ed -sv - </dev/null >&0 2>&0 ; then
- set -- -v "$@"
- fi
- fi
+ # Add a colon prompt (POSIX feature)
+ set -- -p: "$@"
- # Execute the ed(1) call, in a wrapper if appropriate and with the
- # concluded options
- if [ -t 0 ] && command -v rlwrap >/dev/null 2>&1 ; then
- command rlwrap ed "$@"
- else
- command ed "$@"
- fi
+ # Run in rlwrap(1) if available
+ set -- ed "$@"
+ command -v rlwrap >/dev/null 2>&1 &&
+ set -- rlwrap "$@"
+
+ # Run determined command
+ command "$@"
}