Implement shell_activity_report function
[khome.git] / home / lib / login_functions.sh
index 41f44b8..87746c6 100644 (file)
@@ -1,3 +1,69 @@
+#
+
+d() {
+    local -r word=$(fzf < /usr/share/dict/words)
+    dict "$word"
+}
+
+shell_activity_report() {
+    history \
+    | awk '
+        {
+            time = $3
+            ok = split(time, t, ":")
+            if (ok) {
+                hour = t[1] + 0  # Coerce number from string
+                cnt = count[hour]++
+            }
+            if (cnt > max)
+                max = cnt
+        }
+
+            END {
+                for (hour=0; hour<24; hour++) {
+                    c = count[hour]
+                    printf "%2d ", hour
+                    for (i=1; i<=((c * 100) / max); i++)
+                        printf "|"
+                    printf "\n"
+                }
+            }'
+}
+
+top_commands() {
+    history \
+    | awk '
+        {
+            count[$4]++
+        }
+
+        END {
+            for (cmd in count)
+                print count[cmd], cmd
+        }' \
+    | sort -n -r -k 1 \
+    | head -50 \
+    | awk '
+        {
+            cmd[NR] = $2
+            c = count[NR] = $1 + 0  # + 0 to coerce number from string
+            if (c > max)
+                max = c
+        }
+
+        END {
+            for (i = 1; i <= NR; i++) {
+                c = count[i]
+                printf "%s %d ", cmd[i], c
+                scaled = (c * 100) / max
+                for (j = 1; j <= scaled; j++)
+                    printf "|"
+                printf "\n"
+            }
+        }' \
+    | column -t
+}
+
 # Top Disk-Using directories
 # TODO: Consider using numfmt instead of awk
 tdu() {
@@ -140,7 +206,7 @@ gh_clone_repo() {
 
 work_log_template() {
 cat << EOF
-$(date +%F)
+$(date '+%F %A')
 ==========
 
 Morning report
This page took 0.032854 seconds and 4 git commands to generate.