Browse Source

move commandlog-log over to perl

Doesn't incorporate the options from the shell variant, which for now
lives in commandlog-log.sh.
v2
Brennen Bearnes 3 years ago
parent
commit
e46edf7afd
5 changed files with 108 additions and 126 deletions
  1. +10
    -32
      README.md
  2. +31
    -50
      bin/commandlog-log
  3. +0
    -42
      bin/commandlog-log.pl
  4. +61
    -0
      bin/commandlog-log.sh
  5. +6
    -2
      lib/App/CommandLog.pm

+ 10
- 32
README.md View File

@ -45,38 +45,16 @@ commandlog log
And you should get output something like the following:
id = 96
command = commandlog log
expanded_command = commandlog log
path = /home/brennen/code/commandlog
hostname = exuberance
username = brennen
shell = /usr/bin/zsh
terminal = xterm
notes =
datetime = 2016-10-26 03:56:12
id = 95
command = vim README.md
expanded_command = vim README.md
path = /home/brennen/code/commandlog
hostname = exuberance
username = brennen
shell = /usr/bin/zsh
terminal = xterm
notes =
datetime = 2016-10-26 03:48:40
id = 94
command = ll
expanded_command = ls --color -l
path = /home/brennen/code/commandlog
hostname = exuberance
username = brennen
shell = /usr/bin/zsh
terminal = xterm
notes =
datetime = 2016-10-26 03:48:30
2018-03-23 05:29:22 v lib/App/CommandLog.pm
2018-03-23 05:29:09 vim Build.PL
2018-03-23 05:29:04 ll
2018-03-23 05:28:54 fg
2018-03-23 05:28:52 c log
2018-03-23 05:28:43 sudo ./Build install
2018-03-23 05:28:40 ./Build install
2018-03-23 05:28:37 cd ..
2018-03-23 05:28:34 ll
2018-03-23 05:28:32 mv commandlog-log.pl commandlog-log
No promises though. If anybody tries this and has thoughts, please do let me
know.

+ 31
- 50
bin/commandlog-log View File

@ -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();

+ 0
- 42
bin/commandlog-log.pl View File

@ -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();

+ 61
- 0
bin/commandlog-log.sh View File

@ -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 "$@"

+ 6
- 2
lib/App/CommandLog.pm View File

@ -18,13 +18,15 @@ tk tk tk
package App::CommandLog;
our ($VERSION) = '0.0.1';
our ($VERSION) = '0.2.0';
use strict;
use warnings;
use DBI;
=over
=item get_dbh()
Get database handle for default commandlog database.
@ -65,9 +67,11 @@ SQL
);
}
=back
=head1 AUTHOR
Copyright 2016 Brennen Bearnes
Copyright 2016-2018 Brennen Bearnes
commandlog is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by


Loading…
Cancel
Save