diff options
| author | jason | 2023-10-11 16:36:13 -0600 |
|---|---|---|
| committer | jason | 2023-10-11 16:36:13 -0600 |
| commit | 84243142511d1b89911d005be328746fcb87af75 (patch) | |
| tree | b5945094e2775cbcf050b329bc9ed1170fc9a09f /termbar.example | |
| parent | 067dc98e377610ceb9fac84222dd2051a7973d75 (diff) | |
| download | dotfiles-84243142511d1b89911d005be328746fcb87af75.tar.gz dotfiles-84243142511d1b89911d005be328746fcb87af75.zip | |
add termbar example
Diffstat (limited to 'termbar.example')
| -rwxr-xr-x | termbar.example | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/termbar.example b/termbar.example new file mode 100755 index 0000000..27015c8 --- /dev/null +++ b/termbar.example | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | |||
| 3 | ## Debug | ||
| 4 | # set -x | ||
| 5 | |||
| 6 | # These will keep termbar running, but at the cost of leaving processes open | ||
| 7 | # when X dies. Helpful to use when tweaking | ||
| 8 | #trap 'exec $0' HUP # Restart itself | ||
| 9 | #trap 'tput cnorm; exit 1' INT QUIT TERM | ||
| 10 | |||
| 11 | clock() { | ||
| 12 | CLOCK=$(date '+%a %d %b %H:%M:%S') | ||
| 13 | } | ||
| 14 | |||
| 15 | workspace_id() { | ||
| 16 | WORKSPACE_ID=$(xprop -root 32c '\t$0' _NET_CURRENT_DESKTOP | cut -f 2) | ||
| 17 | } | ||
| 18 | |||
| 19 | convert_to_hours() { | ||
| 20 | h=$((${1}/60)) | ||
| 21 | m=$((${1}%60)) | ||
| 22 | |||
| 23 | printf "%02d:%02d" $h $m | ||
| 24 | } | ||
| 25 | bat() { | ||
| 26 | BAT_PCT=$(apm -l) | ||
| 27 | BAT_TIME=$(convert_to_hours $(apm -m)) | ||
| 28 | # ↯ ⋇ | ||
| 29 | |||
| 30 | if [ $(sysctl hw.sensors.acpiac0.indicator0 | grep -c On) -eq "1" ]; then | ||
| 31 | AC_STATUS=PWR | ||
| 32 | else | ||
| 33 | AC_STATUS=BAT | ||
| 34 | fi | ||
| 35 | |||
| 36 | } | ||
| 37 | |||
| 38 | mem() { | ||
| 39 | MEM=$(top -n | grep Memory | awk {'print $3'}) | ||
| 40 | } | ||
| 41 | |||
| 42 | cpu() { | ||
| 43 | _CPU_SPEED=$(sysctl hw.cpuspeed | cut -d "=" -f 2) | ||
| 44 | CPU_SPEED=$(bc -l -e scale=1 -e ${_CPU_SPEED}/1000 -e quit | awk '{printf "%.1f", $0}') | ||
| 45 | CPU_TEMP=$(sysctl hw.sensors.cpu0.temp0 | cut -d "=" -f 2 | cut -d "." -f 1) | ||
| 46 | } | ||
| 47 | |||
| 48 | vol() { | ||
| 49 | _VOL=$(sndioctl output.level | cut -d "=" -f 2) | ||
| 50 | VOL=$(bc -l -e scale=1 -e ${_VOL}*100 -e quit | awk '{printf "%.1f\n", $0}') | ||
| 51 | } | ||
| 52 | |||
| 53 | while true; do | ||
| 54 | clock | ||
| 55 | workspace_id | ||
| 56 | bat | ||
| 57 | cpu | ||
| 58 | mem | ||
| 59 | vol | ||
| 60 | |||
| 61 | # Overwrites the input | ||
| 62 | clear | ||
| 63 | #tput cup 1 0 # tput sometimes leaves trailing numbers | ||
| 64 | printf "[${WORKSPACE_ID}] %132.110s CPU: ${CPU_SPEED}Ghz ${CPU_TEMP}C | MEM: ${MEM} | ${AC_STATUS} ${BAT_PCT}%% (${BAT_TIME}) | VOL: ${VOL}%% | ${CLOCK}" | ||
| 65 | |||
| 66 | sleep 5 | ||
| 67 | done | ||