diff options
-rw-r--r-- | README.markdown | 1 | ||||
-rw-r--r-- | bash/bashrc.d/lhn.bash | 7 |
2 files changed, 8 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown index 76521f0a..2367aac9 100644 --- a/README.markdown +++ b/README.markdown @@ -201,6 +201,7 @@ There are a few other little tricks defined for other shells, mostly in depending on the capabilities of the system `grep(1)`. It's dependent on information written by the `grep.sh` script in `~/.profile.d`. * `keep()` stores ad-hoc shell functions and variables. +* `lhn()` gets the history number of the last command. * `ls()` tries to apply color to `ls(1)` for interactive use if available. It's dependent on information written by the `ls.sh` script in `~/.profile.d`. diff --git a/bash/bashrc.d/lhn.bash b/bash/bashrc.d/lhn.bash new file mode 100644 index 00000000..89c6f5da --- /dev/null +++ b/bash/bashrc.d/lhn.bash @@ -0,0 +1,7 @@ +# Print the history number of the last command +lhn () { + local last + last=$(fc -l -1) || return + [[ -n $last ]] || return + printf '%u\n' "${last%%[^0-9]*}" +} |