Skip to content

Commit

Permalink
+ func: lhistory: sort all by timestamp and display last N entries
Browse files Browse the repository at this point in the history
also implements a '-a' that looks at all cmdhist files (much larger but
includes past history bases that we might not always want to search)
  • Loading branch information
smemsh committed Jul 14, 2024
1 parent 666ddbe commit cb98c51
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions func.d/history
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,18 @@ hist ()

lhistory ()
{
HISTTIMEFORMAT="${HISTTIMEFORMAT} " \
history \
| sort -sk 2,2 \
local logdir
local -a logfiles

if [[ $1 == -a ]]
then
logdir=${LOGFILE_CMDS%/*}
logfiles=($logdir/cmdhist.*)
shift
else
logfiles=($LOGFILE_CMDS)
fi
sort -sk 2,2 <(cat "${logfiles[@]}") \
| tail -n ${1:-+1} \
| less -FX
}

0 comments on commit cb98c51

Please sign in to comment.