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.
Brennen Bearnes 9 months 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
45 45
 
46 46
 And you should get output something like the following:
47 47
 
48
-                  id = 96
49
-             command = commandlog log
50
-    expanded_command = commandlog log
51
-                path = /home/brennen/code/commandlog
52
-            hostname = exuberance
53
-            username = brennen
54
-               shell = /usr/bin/zsh
55
-            terminal = xterm
56
-               notes = 
57
-            datetime = 2016-10-26 03:56:12
58
-
59
-                  id = 95
60
-             command = vim README.md
61
-    expanded_command = vim README.md
62
-                path = /home/brennen/code/commandlog
63
-            hostname = exuberance
64
-            username = brennen
65
-               shell = /usr/bin/zsh
66
-            terminal = xterm
67
-               notes = 
68
-            datetime = 2016-10-26 03:48:40
69
-
70
-                  id = 94
71
-             command = ll
72
-    expanded_command = ls --color -l
73
-                path = /home/brennen/code/commandlog
74
-            hostname = exuberance
75
-            username = brennen
76
-               shell = /usr/bin/zsh
77
-            terminal = xterm
78
-               notes = 
79
-            datetime = 2016-10-26 03:48:30
48
+    2018-03-23 05:29:22	v lib/App/CommandLog.pm
49
+    2018-03-23 05:29:09	vim Build.PL
50
+    2018-03-23 05:29:04	ll
51
+    2018-03-23 05:28:54	fg
52
+    2018-03-23 05:28:52	c log
53
+    2018-03-23 05:28:43	sudo ./Build install
54
+    2018-03-23 05:28:40	./Build install
55
+    2018-03-23 05:28:37	cd ..
56
+    2018-03-23 05:28:34	ll
57
+    2018-03-23 05:28:32	mv commandlog-log.pl commandlog-log
80 58
 
81 59
 No promises though.  If anybody tries this and has thoughts, please do let me
82 60
 know.

+ 31
- 50
bin/commandlog-log View File

@@ -1,61 +1,42 @@
1
-#!/usr/bin/env bash
1
+#!/usr/bin/env perl
2 2
 
3
-set -e
3
+=pod
4 4
 
5
-usage() {
6
-    cat<<HELP
7
-$(basename "$0") [OPTIONS]
5
+=head1 NAME
8 6
 
9
-OPTIONS:
10
-    -o <columns>  Where <columns> is a comma-separated list of values to
11
-                  display in output.
12
-    -[NUM]        Where [NUM] is the number of commands to show.
7
+commandlog-log - show commandlog history
13 8
 
14
-EXAMPLES:
9
+=head1 SYNOPSIS
15 10
 
16
-    Show last 5 commands:
17
-        $ $(basename "$0") -5
18
-    Show date and command of last 3 commands:
19
-        $ $(basename "$0") -o datetime,command
20
-HELP
21
-}
11
+    commandlog log
22 12
 
23
-show_log() {
24
-    local log_count cmd
25
-    log_count="$1"
26
-    columns="$2"
13
+=head1 AUTHOR
27 14
 
28
-    cmd=$(printf \
29
-        'SELECT %s FROM commands ORDER BY datetime DESC LIMIT %d;' \
30
-        "$columns" \
31
-        "$log_count")
15
+Brennen Bearnes <bbearnes@gmail.com>
32 16
 
33
-    exec sqlite3 -line ~/cli.db "$cmd"
34
-}
17
+=cut
18
+
19
+use warnings;
20
+use strict;
21
+use 5.10.0;
22
+use Cwd;
23
+use DBI;
24
+use Sys::Hostname;
25
+use App::CommandLog;
26
+
27
+my $dbfile = $ENV{HOME} . "/cli.db";
28
+my $dbh = App::CommandLog::get_dbh($dbfile);
35 29
 
36
-main() {
37
-    local log_count columns
38
-    log_count=3
39
-    columns='*'
40
-
41
-    while [ -n "$1" ]; do
42
-        case "$1" in
43
-            --help|-h)
44
-                usage
45
-                exit 0
46
-            ;;
47
-            -o)
48
-                shift
49
-                columns="$1"
50
-                ;;
51
-            -*)
52
-                log_count="${1:1}"
53
-            ;;
54
-        esac
55
-        shift
56
-    done
57
-
58
-    show_log "$log_count" "$columns"
30
+my $sth = $dbh->prepare(q{
31
+  SELECT * FROM commands ORDER BY datetime DESC LIMIT 10
32
+});
33
+
34
+$sth->execute();
35
+
36
+while (my $data = $sth->fetchrow_hashref()) {
37
+  say join "\t", $data->{datetime}, $data->{command};
59 38
 }
60 39
 
61
-main "$@"
40
+$sth->execute();
41
+
42
+

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

@@ -1,42 +0,0 @@
1
-#!/usr/bin/env perl
2
-
3
-=pod
4
-
5
-=head1 NAME
6
-
7
-commandlog-log - show commandlog history
8
-
9
-=head1 SYNOPSIS
10
-
11
-    commandlog log
12
-
13
-=head1 AUTHOR
14
-
15
-Brennen Bearnes <bbearnes@gmail.com>
16
-
17
-=cut
18
-
19
-use warnings;
20
-use strict;
21
-use 5.10.0;
22
-use Cwd;
23
-use DBI;
24
-use Sys::Hostname;
25
-use App::CommandLog;
26
-
27
-my $dbfile = $ENV{HOME} . "/cli.db";
28
-my $dbh = App::CommandLog::get_dbh($dbfile);
29
-
30
-my $sth = $dbh->prepare(q{
31
-  SELECT * FROM commands ORDER BY datetime DESC LIMIT 3
32
-});
33
-
34
-$sth->execute();
35
-
36
-while (my $data = $sth->fetchrow_hashref()) {
37
-  say join "\t", $data->{datetime}, $data->{command};
38
-}
39
-
40
-$sth->execute();
41
-
42
-

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

@@ -0,0 +1,61 @@
1
+#!/usr/bin/env bash
2
+
3
+set -e
4
+
5
+usage() {
6
+    cat<<HELP
7
+$(basename "$0") [OPTIONS]
8
+
9
+OPTIONS:
10
+    -o <columns>  Where <columns> is a comma-separated list of values to
11
+                  display in output.
12
+    -[NUM]        Where [NUM] is the number of commands to show.
13
+
14
+EXAMPLES:
15
+
16
+    Show last 5 commands:
17
+        $ $(basename "$0") -5
18
+    Show date and command of last 3 commands:
19
+        $ $(basename "$0") -o datetime,command
20
+HELP
21
+}
22
+
23
+show_log() {
24
+    local log_count cmd
25
+    log_count="$1"
26
+    columns="$2"
27
+
28
+    cmd=$(printf \
29
+        'SELECT %s FROM commands ORDER BY datetime DESC LIMIT %d;' \
30
+        "$columns" \
31
+        "$log_count")
32
+
33
+    exec sqlite3 -line ~/cli.db "$cmd"
34
+}
35
+
36
+main() {
37
+    local log_count columns
38
+    log_count=3
39
+    columns='*'
40
+
41
+    while [ -n "$1" ]; do
42
+        case "$1" in
43
+            --help|-h)
44
+                usage
45
+                exit 0
46
+            ;;
47
+            -o)
48
+                shift
49
+                columns="$1"
50
+                ;;
51
+            -*)
52
+                log_count="${1:1}"
53
+            ;;
54
+        esac
55
+        shift
56
+    done
57
+
58
+    show_log "$log_count" "$columns"
59
+}
60
+
61
+main "$@"

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

@@ -18,13 +18,15 @@ tk tk tk
18 18
 
19 19
 package App::CommandLog;
20 20
 
21
-our ($VERSION) = '0.0.1';
21
+our ($VERSION) = '0.2.0';
22 22
 
23 23
 use strict;
24 24
 use warnings;
25 25
 
26 26
 use DBI;
27 27
 
28
+=over
29
+
28 30
 =item get_dbh()
29 31
 
30 32
 Get database handle for default commandlog database.
@@ -65,9 +67,11 @@ SQL
65 67
   );
66 68
 }
67 69
 
70
+=back
71
+
68 72
 =head1 AUTHOR
69 73
 
70
-Copyright 2016 Brennen Bearnes
74
+Copyright 2016-2018 Brennen Bearnes
71 75
 
72 76
     commandlog is free software; you can redistribute it and/or modify
73 77
     it under the terms of the GNU General Public License as published by