Command-line history logging utilities
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

61 lines
1.1 KiB

#!/usr/bin/env bash
set -e
usage() {
cat<<HELP
$(basename "$0") [OPTIONS]
OPTIONS:
-o <columns> Where <columns> is a comma-separated list of values to
display in output.
-[NUM] Where [NUM] is the number of commands to show.
EXAMPLES:
Show last 5 commands:
$ $(basename "$0") -5
Show date and command of last 3 commands:
$ $(basename "$0") -o datetime,command
HELP
}
show_log() {
local log_count cmd
log_count="$1"
columns="$2"
cmd=$(printf \
'SELECT %s FROM commands ORDER BY datetime DESC LIMIT %d;' \
"$columns" \
"$log_count")
exec sqlite3 -line ~/cli.db "$cmd"
}
main() {
local log_count columns
log_count=3
columns='*'
while [ -n "$1" ]; do
case "$1" in
--help|-h)
usage
exit 0
;;
-o)
shift
columns="$1"
;;
-*)
log_count="${1:1}"
;;
esac
shift
done
show_log "$log_count" "$columns"
}
main "$@"