Doesn't incorporate the options from the shell variant, which for now lives in commandlog-log.sh.v2
@ -1,61 +1,42 @@ | |||
#!/usr/bin/env bash | |||
#!/usr/bin/env perl | |||
set -e | |||
=pod | |||
usage() { | |||
cat<<HELP | |||
$(basename "$0") [OPTIONS] | |||
=head1 NAME | |||
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. | |||
commandlog-log - show commandlog history | |||
EXAMPLES: | |||
=head1 SYNOPSIS | |||
Show last 5 commands: | |||
$ $(basename "$0") -5 | |||
Show date and command of last 3 commands: | |||
$ $(basename "$0") -o datetime,command | |||
HELP | |||
} | |||
commandlog log | |||
show_log() { | |||
local log_count cmd | |||
log_count="$1" | |||
columns="$2" | |||
=head1 AUTHOR | |||
cmd=$(printf \ | |||
'SELECT %s FROM commands ORDER BY datetime DESC LIMIT %d;' \ | |||
"$columns" \ | |||
"$log_count") | |||
Brennen Bearnes <bbearnes@gmail.com> | |||
exec sqlite3 -line ~/cli.db "$cmd" | |||
} | |||
=cut | |||
use warnings; | |||
use strict; | |||
use 5.10.0; | |||
use Cwd; | |||
use DBI; | |||
use Sys::Hostname; | |||
use App::CommandLog; | |||
my $dbfile = $ENV{HOME} . "/cli.db"; | |||
my $dbh = App::CommandLog::get_dbh($dbfile); | |||
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" | |||
my $sth = $dbh->prepare(q{ | |||
SELECT * FROM commands ORDER BY datetime DESC LIMIT 10 | |||
}); | |||
$sth->execute(); | |||
while (my $data = $sth->fetchrow_hashref()) { | |||
say join "\t", $data->{datetime}, $data->{command}; | |||
} | |||
main "$@" | |||
$sth->execute(); | |||
@ -1,42 +0,0 @@ | |||
#!/usr/bin/env perl | |||
=pod | |||
=head1 NAME | |||
commandlog-log - show commandlog history | |||
=head1 SYNOPSIS | |||
commandlog log | |||
=head1 AUTHOR | |||
Brennen Bearnes <bbearnes@gmail.com> | |||
=cut | |||
use warnings; | |||
use strict; | |||
use 5.10.0; | |||
use Cwd; | |||
use DBI; | |||
use Sys::Hostname; | |||
use App::CommandLog; | |||
my $dbfile = $ENV{HOME} . "/cli.db"; | |||
my $dbh = App::CommandLog::get_dbh($dbfile); | |||
my $sth = $dbh->prepare(q{ | |||
SELECT * FROM commands ORDER BY datetime DESC LIMIT 3 | |||
}); | |||
$sth->execute(); | |||
while (my $data = $sth->fetchrow_hashref()) { | |||
say join "\t", $data->{datetime}, $data->{command}; | |||
} | |||
$sth->execute(); | |||
@ -0,0 +1,61 @@ | |||
#!/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 "$@" |