X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=home%2Flib%2Flogin_functions.sh;h=e006eee32825e21e395e9fea93f8e4d19ec4c85a;hb=d265cd11ac471b7d2596ac1c41b81e64094b788e;hp=163c09ebe41ef15ff596bcd3cf2f6c88ca98542b;hpb=0a061319ece42cc0123135a9d2b18e984a82d751;p=khome.git diff --git a/home/lib/login_functions.sh b/home/lib/login_functions.sh index 163c09e..e006eee 100644 --- a/home/lib/login_functions.sh +++ b/home/lib/login_functions.sh @@ -5,6 +5,40 @@ d() { dict "$word" } +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() {