Use dash in unfilled gauge space instead of space
[khome.git] / home / lib / login_functions.sh
index 2a90695..92a111b 100644 (file)
@@ -267,9 +267,10 @@ gh_fetch_repos() {
 }
 
 gh_clone() {
-    gh_user_type="$1"
-    gh_user_name="$2"
-    gh_dir="${DIR_GITHUB}/${gh_user_name}"
+    local -r gh_user_type="$1"
+    local -r gh_user_name="$2"
+
+    local -r gh_dir="${DIR_GITHUB}/${gh_user_name}"
     mkdir -p "$gh_dir"
     cd "$gh_dir" || kill -INT $$
     gh_fetch_repos "$gh_user_type" "$gh_user_name" \
@@ -317,7 +318,7 @@ EOF
 
 work_log() {
     mkdir -p "$DIR_WORK_LOG"
-    file_work_log_today="${DIR_WORK_LOG}/$(date +%F).md"
+    local -r file_work_log_today="${DIR_WORK_LOG}/$(date +%F).md"
     if [ ! -f "$file_work_log_today" ]
     then
         work_log_template > "$file_work_log_today"
@@ -353,10 +354,12 @@ bt_devs() {
 }
 
 run() {
-    stderr="$(mktemp)"
+    local -r stderr="$(mktemp)"
+
+    local code urgency
+
     $@ 2> >(tee "$stderr")
     code="$?"
-    urgency=''
     case "$code" in
         0) urgency='normal';;
         *) urgency='critical'
@@ -377,8 +380,8 @@ bar_gauge() {
 
             printf "["
             for (i=1; i<=width; i++) {
-                c = i <= u ? "|" : " "
-                printf "%c", c
+                c = i <= u ? "|" : "-"
+                printf "%s", c
             }
             printf "]\n"
         }
@@ -396,6 +399,10 @@ motd() {
 
     echo
 
+    printf 'tmux sessions: %d\n' "$(tmux ls 2> /dev/null | wc -l)"
+
+    echo
+
     printf 'mem  '
     free \
     | awk '$1 == "Mem:" {total=$2; used=$3; print used, total}' \
@@ -437,6 +444,49 @@ motd() {
         ;;
     esac
 
+    echo
+
+    (ifconfig; iwconfig) 2> /dev/null \
+    | awk '
+        /^[^ ]/ {
+            device = $1
+            sub(":$", "", device)
+            if ($4 ~ "ESSID:") {
+                _essid = $4
+                sub("^ESSID:\"", "", _essid)
+                sub("\"$", "", _essid)
+                essid[device] = _essid
+            }
+            next
+        }
+
+        /^ / && $1 == "inet" {
+            address[device] = $2
+            next
+        }
+
+        /^ +Link Quality=[0-9]+\/[0-9]+ +Signal level=/ {
+            split($2, lq_parts_eq, "=")
+            split(lq_parts_eq[2], lq_parts_slash, "/")
+            cur = lq_parts_slash[1]
+            max = lq_parts_slash[2]
+            link[device] = cur / max * 100
+            next
+        }
+
+        END {
+            for (device in address)
+                if (device != "lo") {
+                    l = link[device]
+                    e = essid[device]
+                    l = l ? sprintf("%.0f%%", l) : "--"
+                    e = e ? e : "--"
+                    print device, address[device], e, l
+                }
+        }
+        ' \
+    | column -t
+
     #echo
     # TODO: netstat summary
     # WARN: ensure: $USER ALL=(ALL) NOPASSWD:/bin/netstat
This page took 0.028439 seconds and 4 git commands to generate.