Use "Name:" field if it is available
[khatus.git] / bin / khatus_show
index f008d19..537475b 100755 (executable)
@@ -342,15 +342,45 @@ mpd_state=$(
         '
 )
 
-mpd_current_file=$(
+mpd_current=$(
     echo 'currentsong' \
     | nc 127.0.0.1 6600 \
     | awk -v max_chars=10 '
-        /^file:/ {
-            file = $2
-            for (i=3; i<=NF; i++) {file = file " " $i}
-            last = split(file, parts, "/")
-            print substr(parts[last], 1, max_chars)
+        /^OK/ {
+            next
+        }
+
+        {
+            key = $1
+            val = $2
+            for (i=3; i<=NF; i++) {val = val " " $i}
+            data[key] = val
+        }
+
+        END {
+            if (data["Name:"]) {
+                out = data["Name:"]
+            } else {
+                file = data["file:"]
+                last = split(file, parts, "/")
+                out = parts[last]
+            }
+            printf("%s", substr(out, 1, max_chars))
+        }
+        '
+)
+
+graphics_card=$(
+    nvidia-smi \
+        --format=csv,noheader,nounits \
+        --query-gpu=memory.total,memory.used,temperature.gpu \
+    | awk -F ',' '
+        {
+            mem_total = $1;
+            mem_used  = $2;
+            temp      = $3;
+            mem_used_percent = (100 * mem_used) / mem_total;
+            printf("[%d%% %dC]", mem_used_percent, temp);
         }
         '
 )
@@ -360,6 +390,9 @@ echo \
  E$energy\
  \
  \
+ G=$graphics_card\
+ \
+ \
  M$memory\
  \
  \
@@ -383,7 +416,7 @@ echo \
  \
  V=$volume\
  \
- [$mpd_state $mpd_current_file]\
+ [$mpd_state $mpd_current]\
  \
  $signal_last_msg_age\
  \
This page took 0.038654 seconds and 4 git commands to generate.