From 6e4a15d79352ca2707a3b0d81d158228a7d14704 Mon Sep 17 00:00:00 2001 From: 0scar Date: Thu, 3 Jun 2021 23:33:31 +0200 Subject: Add/move statusbar scripts --- .local/bin/statusbar/batinfo | 33 +++++++++++++++++++++++++++++++++ .local/bin/statusbar/checkupdates | 15 +++++++++++++++ .local/bin/statusbar/cpuinfo | 30 ++++++++++++++++++++++++++++++ .local/bin/statusbar/meminfo | 13 +++++++++++++ .local/bin/statusbar/netinfo | 34 ++++++++++++++++++++++++++++++++++ .local/bin/statusbar/timeinfo | 15 +++++++++++++++ .local/bin/statusbar/volinfo | 13 +++++++++++++ .scripts/batinfo | 33 --------------------------------- .scripts/checkupdates | 15 --------------- .scripts/cpuinfo | 30 ------------------------------ .scripts/meminfo | 13 ------------- .scripts/netinfo | 34 ---------------------------------- 12 files changed, 153 insertions(+), 125 deletions(-) create mode 100755 .local/bin/statusbar/batinfo create mode 100755 .local/bin/statusbar/checkupdates create mode 100755 .local/bin/statusbar/cpuinfo create mode 100755 .local/bin/statusbar/meminfo create mode 100755 .local/bin/statusbar/netinfo create mode 100755 .local/bin/statusbar/timeinfo create mode 100755 .local/bin/statusbar/volinfo delete mode 100755 .scripts/batinfo delete mode 100755 .scripts/checkupdates delete mode 100755 .scripts/cpuinfo delete mode 100755 .scripts/meminfo delete mode 100755 .scripts/netinfo diff --git a/.local/bin/statusbar/batinfo b/.local/bin/statusbar/batinfo new file mode 100755 index 0000000..1719181 --- /dev/null +++ b/.local/bin/statusbar/batinfo @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +set -e + +status="$(acpi -abi)" # get battery and adapter info + +case $BLOCK_BUTTON in + 1) notify-send -t $((15 * 1000)) --urgency=low "Battery status" "$status" ;; + 4) brightnessctl -q s 10%+ ;; + 5) brightnessctl -q s 10%- ;; +esac + +power=$(echo "${status}" | awk '/Battery [0-9]+: [A-Z]/{s+=$4;c++}; END{printf "%.1f%%", s/c}') + +icon='?' +if [[ -z $(echo $status | sed -n '/on-line/p') ]]; then + case "${power%.*}" in + 100 | 9[0-9]) icon='\uf578' ;; + 8[0-9]) icon='\uf581';; + 7[0-9]) icon='\uf580';; + 6[0-9]) icon='\uf57f';; + 5[0-9]) icon='\uf57e';; + 4[0-9]) icon='\uf57d';; + 3[0-9]) icon='\uf57c';; + 2[0-9]) icon='\uf57b';; + 1[0-9]) icon='\uf57a';; + [0-9]) icon='\uf579';; + esac +else + icon='\uf583' +fi + +echo -e "$icon $power" diff --git a/.local/bin/statusbar/checkupdates b/.local/bin/statusbar/checkupdates new file mode 100755 index 0000000..5a95974 --- /dev/null +++ b/.local/bin/statusbar/checkupdates @@ -0,0 +1,15 @@ +#!/usr/bin/env sh +set -e + +updates=$(pacman -Qu | sed '/\[ignored\]$/d') + +case $BLOCK_BUTTON in + 1) ;& # fallthrough + 3) if [ -n "${updates}" ]; then + notify-send -t $((1000 * 20)) "Available updates" "$updates" + else + notify-send "Available updates" "No available updates" + fi;; +esac + +[ -n "$updates" ] && echo $(echo "${updates}" | wc -l) || exit 0 diff --git a/.local/bin/statusbar/cpuinfo b/.local/bin/statusbar/cpuinfo new file mode 100755 index 0000000..f46121b --- /dev/null +++ b/.local/bin/statusbar/cpuinfo @@ -0,0 +1,30 @@ +#!/usr/bin/env sh +set -e + +case $BLOCK_BUTTON in + 1) notify-send --urgency=low \ + "Process status" \ + "$(ps -eo pid,pcpu,size,comm \ + | sort -rnk 3 \ + | awk '{printf "% 8s% 8s% 8s ", $1, $2, $3; + $1="";$2="";$3=""; + print $0; c++} + c>10 {exit}')" + ;; + 3) notify-send --urgency=low \ + "Process status" \ + "$(ps -eo pid,pcpu,size,cmd \ + | sort -rnk 3 \ + | cut -b -45 \ + | awk '{printf "% 8s% 8s% 8s ", $1, $2, $3; + $1="";$2="";$3=""; + print $0; c++} + c>10 {exit}')" + ;; +esac + +# Load +sed -Ee 's/^([0-9]+\.[0-9]+) .*/[\1  /g' /proc/loadavg | tr -d '\n' + +# Thermals +awk '{s+=$1}END{printf "%.1f°]", s / (1000*NR)}' /sys/class/thermal/thermal_zone*/temp diff --git a/.local/bin/statusbar/meminfo b/.local/bin/statusbar/meminfo new file mode 100755 index 0000000..2b31b97 --- /dev/null +++ b/.local/bin/statusbar/meminfo @@ -0,0 +1,13 @@ +#!/usr/bin/env sh +set -e + +case $BLOCK_BUTTON in + 1) notify-send --urgency=low \ + "Memory status" \ + "$(free -h | \ + awk '/total/ {printf "%15s%10s%10s\n", $1, $2, $3} + /Mem|Swap/{printf "%-5s%10s%10s%10s\n", $1, $2, $3, $4}')" + ;; +esac + +free -h | awk '/Mem/{print "[" $3 " RAM " $2 "]" }' diff --git a/.local/bin/statusbar/netinfo b/.local/bin/statusbar/netinfo new file mode 100755 index 0000000..d59ef05 --- /dev/null +++ b/.local/bin/statusbar/netinfo @@ -0,0 +1,34 @@ +#!/usr/bin/env sh + +netstatus="$(awk '{ + n = split(FILENAME, a, "/") + printf("%-15s %s\n", a[n-1], $1) + }' /sys/class/net/[ew]*/operstate | sort -k 2)" + +function add_connected_address() { + TMPIFS=$IFS + IFS=' +' + for line in $netstatus; do + device=$(echo $line | awk '{print $1}') + address=$(ip addr show $device | sed -En 's/inet ([0-9\.]+).*/\1/p') + # Append Wifi AP if connected + [ -n "$address" ] && address=$address" ("$(iwgetid -r)")" + echo $line $address + done + IFS=$TMPIFS +} + +ARG=${1:-$BLOCK_BUTTON} + +case $ARG in + 1) notify-send --urgency=low "Internet connection" "$(add_connected_address)" ;; +esac + +if [ -z "$(echo -e "${netstatus}" | sed -En '/up$/p' | tr -d '\n')" ]; then + echo -en '\x0c' +else + echo -n "${netstatus}" | sed -En 's/^(w[^ ]+).*up//p;s/^(e[^ ]+).*up/\x0d/p' +fi + +echo -en '\x0b' diff --git a/.local/bin/statusbar/timeinfo b/.local/bin/statusbar/timeinfo new file mode 100755 index 0000000..a091f84 --- /dev/null +++ b/.local/bin/statusbar/timeinfo @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +ARG=${1:-$BLOCK_BUTTON} + +case $ARG in + 1) notify-send --urgency=low \ + "Calendar" \ + "$(cal -w -m)" + ;; + 3) notify-send --urgency=low \ + "Weather" \ + "$(weather)" + ;; + esac +date +'%F %R' diff --git a/.local/bin/statusbar/volinfo b/.local/bin/statusbar/volinfo new file mode 100755 index 0000000..fd09b13 --- /dev/null +++ b/.local/bin/statusbar/volinfo @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +ARG=${1:-$BLOCK_BUTTON} + +case $ARG in + 1) pamixer -t && sigdwmblocks 4;; + 4) pamixer -i 1 && sigdwmblocks 4;; + 5) pamixer -d 1 && sigdwmblocks 4;; +esac + +VOL=$(pamixer --get-volume) + +pamixer --get-mute >/dev/null && echo -ne "\x0c\ufa80${VOL}\x0b" || echo -ne "\ufa7d${VOL}" diff --git a/.scripts/batinfo b/.scripts/batinfo deleted file mode 100755 index 1719181..0000000 --- a/.scripts/batinfo +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env sh - -set -e - -status="$(acpi -abi)" # get battery and adapter info - -case $BLOCK_BUTTON in - 1) notify-send -t $((15 * 1000)) --urgency=low "Battery status" "$status" ;; - 4) brightnessctl -q s 10%+ ;; - 5) brightnessctl -q s 10%- ;; -esac - -power=$(echo "${status}" | awk '/Battery [0-9]+: [A-Z]/{s+=$4;c++}; END{printf "%.1f%%", s/c}') - -icon='?' -if [[ -z $(echo $status | sed -n '/on-line/p') ]]; then - case "${power%.*}" in - 100 | 9[0-9]) icon='\uf578' ;; - 8[0-9]) icon='\uf581';; - 7[0-9]) icon='\uf580';; - 6[0-9]) icon='\uf57f';; - 5[0-9]) icon='\uf57e';; - 4[0-9]) icon='\uf57d';; - 3[0-9]) icon='\uf57c';; - 2[0-9]) icon='\uf57b';; - 1[0-9]) icon='\uf57a';; - [0-9]) icon='\uf579';; - esac -else - icon='\uf583' -fi - -echo -e "$icon $power" diff --git a/.scripts/checkupdates b/.scripts/checkupdates deleted file mode 100755 index 5a95974..0000000 --- a/.scripts/checkupdates +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env sh -set -e - -updates=$(pacman -Qu | sed '/\[ignored\]$/d') - -case $BLOCK_BUTTON in - 1) ;& # fallthrough - 3) if [ -n "${updates}" ]; then - notify-send -t $((1000 * 20)) "Available updates" "$updates" - else - notify-send "Available updates" "No available updates" - fi;; -esac - -[ -n "$updates" ] && echo $(echo "${updates}" | wc -l) || exit 0 diff --git a/.scripts/cpuinfo b/.scripts/cpuinfo deleted file mode 100755 index f46121b..0000000 --- a/.scripts/cpuinfo +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env sh -set -e - -case $BLOCK_BUTTON in - 1) notify-send --urgency=low \ - "Process status" \ - "$(ps -eo pid,pcpu,size,comm \ - | sort -rnk 3 \ - | awk '{printf "% 8s% 8s% 8s ", $1, $2, $3; - $1="";$2="";$3=""; - print $0; c++} - c>10 {exit}')" - ;; - 3) notify-send --urgency=low \ - "Process status" \ - "$(ps -eo pid,pcpu,size,cmd \ - | sort -rnk 3 \ - | cut -b -45 \ - | awk '{printf "% 8s% 8s% 8s ", $1, $2, $3; - $1="";$2="";$3=""; - print $0; c++} - c>10 {exit}')" - ;; -esac - -# Load -sed -Ee 's/^([0-9]+\.[0-9]+) .*/[\1  /g' /proc/loadavg | tr -d '\n' - -# Thermals -awk '{s+=$1}END{printf "%.1f°]", s / (1000*NR)}' /sys/class/thermal/thermal_zone*/temp diff --git a/.scripts/meminfo b/.scripts/meminfo deleted file mode 100755 index 2b31b97..0000000 --- a/.scripts/meminfo +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env sh -set -e - -case $BLOCK_BUTTON in - 1) notify-send --urgency=low \ - "Memory status" \ - "$(free -h | \ - awk '/total/ {printf "%15s%10s%10s\n", $1, $2, $3} - /Mem|Swap/{printf "%-5s%10s%10s%10s\n", $1, $2, $3, $4}')" - ;; -esac - -free -h | awk '/Mem/{print "[" $3 " RAM " $2 "]" }' diff --git a/.scripts/netinfo b/.scripts/netinfo deleted file mode 100755 index ceb79f7..0000000 --- a/.scripts/netinfo +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env sh - -netstatus="$(awk '{ - n = split(FILENAME, a, "/") - printf("%-15s %s\n", a[n-1], $1) - }' /sys/class/net/[ew]*/operstate | sort -k 2)" - -function add_connected_address() { - TMPIFS=$IFS - IFS=' -' - for line in $netstatus; do - device=$(echo $line | awk '{print $1}') - address=$(ip addr show $device | sed -En 's/inet ([0-9\.]+).*/\1/p') - # Append Wifi AP if connected - [ -n "$address" ] && address=$address" ("$(iwgetid -r)")" - echo $line $address - done - IFS=$TMPIFS -} - -case $BLOCK_BUTTON in - 1) notify-send --urgency=low "Internet connection" "$(add_connected_address)" ;; -esac - -#echo "$(echo -e "$netstatus" | sed -En '/up$/p')" -#echo ====== - -if [ -z "$(echo -e "${netstatus}" | sed -En '/up$/p' | tr -d '\n')" ]; then - echo -n '' -else - echo -n "${netstatus}" | sed -En 's/^(w[^ ]+).*up//p;s/^(e[^ ]+).*up//p' -fi - -- cgit v1.3