X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=home%2Flib%2Flogin_functions.sh;h=e17c5c64adfef27310839a1117bcef1a24440dcc;hb=9699e21d467d3f7d8577aa283dc73c9d7bcef9f9;hp=8057711cf44e6067a6c34cc83fa1f6ed7113c8e8;hpb=828524b279cdc4e4b9e60cf27a819272c750dd42;p=khome.git diff --git a/home/lib/login_functions.sh b/home/lib/login_functions.sh index 8057711..e17c5c6 100644 --- a/home/lib/login_functions.sh +++ b/home/lib/login_functions.sh @@ -411,6 +411,24 @@ bar_gauge() { ' } +flat_top_5() { + sort -n -k 1 -r \ + | head -5 \ + | awk ' + { + cur = $1 + max = $2 + name = $3 + pct = cur / max * 100 + printf "%s%s:%.2f%%", sep, name, pct + sep = " " + } + + END {printf "\n"} + ' \ + | column -t +} + motd_batt() { case "$(uname)" in 'Linux') @@ -549,7 +567,7 @@ motd() { echo - echo 'Process owners' + echo 'Process owners (top 5)' ps -eo user \ | awk ' NR > 1 { @@ -562,9 +580,7 @@ motd() { print count_by_user[user], total, user } ' \ - | sort -n -k 1 -r \ - | bar_gauge -v num=1 -v ch_left=' ' -v ch_right=' ' -v ch_blank=' ' \ - | column -t \ + | flat_top_5 \ | indent "${indent_unit}" echo @@ -588,10 +604,7 @@ motd() { for (prog in count) print count[prog], total, prog }' \ - | sort -n -k 1 -r \ - | head -5 \ - | bar_gauge -v width=30 -v num=1 -v ch_left=' ' -v ch_right=' ' -v ch_blank=' ' \ - | column -t \ + | flat_top_5 \ | indent "${indent_unit}" }