aboutsummaryrefslogtreecommitdiff
path: root/sh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-20 15:53:19 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-20 15:53:39 +1200
commita143ce9c38942ebe2245ad0e7c33462087692809 (patch)
treeb86f9f8882c043cd074f6e061086f92cc653823b /sh
parentAdd an issue about vr() (diff)
downloaddotfiles-a143ce9c38942ebe2245ad0e7c33462087692809.tar.gz
dotfiles-a143ce9c38942ebe2245ad0e7c33462087692809.zip
Port lhn() to POSIX sh
Diffstat (limited to 'sh')
-rw-r--r--sh/shrc.d/lhn.sh12
1 files changed, 12 insertions, 0 deletions
diff --git a/sh/shrc.d/lhn.sh b/sh/shrc.d/lhn.sh
new file mode 100644
index 00000000..15fced6e
--- /dev/null
+++ b/sh/shrc.d/lhn.sh
@@ -0,0 +1,12 @@
+# Print the history number of the last command
+# "fc" is specified by POSIX, but does not seem to be in dash, so its being
+# included here rather than in e.g. ~/.bashrc.d is a bit tenuous.
+lhn () {
+ if ! command -v fc >/dev/null 2>&1 ; then
+ printf 'lhn(): fc: command not found\n'
+ return 1
+ fi
+ set -- "$(fc -l -1)"
+ [ -n "$1" ] || return
+ printf '%u\n' "$1"
+}