Browse Source

Merge pull request #4 from thcipriani/command-log-o

 Make command log accept -o option
Brennen Bearnes 2 years ago
parent
commit
0ea822051e
1 changed files with 20 additions and 8 deletions
  1. 20
    8
      bin/commandlog-log

+ 20
- 8
bin/commandlog-log View File

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

Loading…
Cancel
Save