summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0scar <qgt268@alumni.ku.dk>2021-06-10 08:15:24 +0000
committer0scar <qgt268@alumni.ku.dk>2021-06-10 08:15:24 +0000
commit2ee4672b82bddf7e78aff7a2ef212f495debadac (patch)
tree9ce6557e5cd666dddbb4e26c377c75451cc0df6f
parentcd9049c5033f2c403bfdae1e997790d67523d1ba (diff)
Update statusbar scripts
-rwxr-xr-x.local/bin/statusbar/batinfo34
-rwxr-xr-x.local/bin/statusbar/bluetoothinfo33
-rwxr-xr-x.local/bin/statusbar/checkupdates24
-rwxr-xr-x.local/bin/statusbar/cpuinfo56
-rwxr-xr-x.local/bin/statusbar/is_docker_running7
-rwxr-xr-x.local/bin/statusbar/meminfo24
-rwxr-xr-x.local/bin/statusbar/netinfo18
-rwxr-xr-x.local/bin/statusbar/timeinfo21
-rwxr-xr-x.local/bin/statusbar/volinfo6
9 files changed, 143 insertions, 80 deletions
diff --git a/.local/bin/statusbar/batinfo b/.local/bin/statusbar/batinfo
index 1719181..317e52d 100755
--- a/.local/bin/statusbar/batinfo
+++ b/.local/bin/statusbar/batinfo
@@ -1,11 +1,13 @@
-#!/usr/bin/env sh
+#!/usr/bin/env bash
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" ;;
+ARG=${1:-$BLOCK_BUTTON}
+
+case $ARG in
+ 1) notify-send -t $((15 * 1000)) --urgency=low "Battery status" "$status" ;;
4) brightnessctl -q s 10%+ ;;
5) brightnessctl -q s 10%- ;;
esac
@@ -14,20 +16,20 @@ power=$(echo "${status}" | awk '/Battery [0-9]+: [A-Z]/{s+=$4;c++}; END{printf "
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
+ 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'
+ icon='\uf583'
fi
echo -e "$icon $power"
diff --git a/.local/bin/statusbar/bluetoothinfo b/.local/bin/statusbar/bluetoothinfo
new file mode 100755
index 0000000..708f51e
--- /dev/null
+++ b/.local/bin/statusbar/bluetoothinfo
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+declare -a states
+
+ARG=${1:-$BLOCK_BUTTON}
+
+# Get state and exit if its soft/hard blocked
+for A in $(rfkill -o TYPE,SOFT,HARD | awk '/bluetooth/{print $2 "\n" $3}'); do
+ [ $A == "blocked" ] && exit 0
+done
+
+DAEMONSTATUS="$(systemctl is-active bluetooth.service)"
+if [ "$DAEMONSTATUS" == "inactive" ]; then
+ echo -en '\x0c\uf5b1\x0b'
+ case $ARG in
+ 1) systemctl start bluetooth.service;;
+ esac
+else
+ CONNECTED="$(bluetoothctl info | awk '/Name/{$1=""; print $0}')"
+ if [ -z "${CONNECTED}" ]; then
+ # Not connected
+ echo -ne '\x0f\uf5b0\x0b'
+ case $ARG in
+ 1) notify-send 'Bluetooth status' "Disconnected\n$(bluetoothctl paired-devices)"
+ esac
+ else
+ echo -ne '\x0d\uf5ae\x0b'
+ case $ARG in
+ 1) notify-send 'Bluetooth status' "Connected to ${CONNECTED}";;
+ 3) bluetoothctl disconnect
+ esac
+ fi
+fi
diff --git a/.local/bin/statusbar/checkupdates b/.local/bin/statusbar/checkupdates
index 5a95974..dfcec84 100755
--- a/.local/bin/statusbar/checkupdates
+++ b/.local/bin/statusbar/checkupdates
@@ -1,15 +1,21 @@
-#!/usr/bin/env sh
+#!/usr/bin/env bash
set -e
updates=$(pacman -Qu | sed '/\[ignored\]$/d')
+COUNT=$(echo -n "${updates}" | wc -l)
-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;;
+ARG=${1:-$BLOCK_BUTTON}
+
+case $ARG in
+ 1) if [ -n "${updates}" ]; then
+ notify-send -t $((1000 * 20)) "Available updates (${COUNT})" "$updates"
+ else
+ notify-send "Available updates" "No available updates"
+ fi;;
esac
-[ -n "$updates" ] && echo $(echo "${updates}" | wc -l) || exit 0
+[ -z "${updates}" ] && exit
+
+[[ "${updates}" =~ .*linux.* ]] && echo -ne '\x0d' || echo -ne '\x0e'
+[ "$COUNT" -gt 0 ] && echo -ne "$COUNT" || exit 0
+echo -ne '\x0b'
diff --git a/.local/bin/statusbar/cpuinfo b/.local/bin/statusbar/cpuinfo
index f46121b..de53f22 100755
--- a/.local/bin/statusbar/cpuinfo
+++ b/.local/bin/statusbar/cpuinfo
@@ -1,30 +1,38 @@
-#!/usr/bin/env sh
+#!/usr/bin/env bash
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}')"
- ;;
+ARG=${1:-$BLOCK_BUTTON}
+
+case $ARG 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
+# Thermals
+# "Never cat something into awk", yeah, but it won't function properly if it
+# encounters a missing `/temp`-file.
+TEMP=$(cat /sys/class/thermal/thermal_zone*/temp 2>/dev/null | awk '{s+=$1}END{printf "%.1f", s / (1000*NR)}' )
+TEMP=`(( $(echo "$TEMP > 45" | bc -l) )) && echo -en "\x0c${TEMP}\x0b" || echo -en "$TEMP"`
+
# Load
-sed -Ee 's/^([0-9]+\.[0-9]+) .*/[\1  /g' /proc/loadavg | tr -d '\n'
+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
+
+echo -en "[${LOAD} \x0f\x0b ${TEMP}°]"
diff --git a/.local/bin/statusbar/is_docker_running b/.local/bin/statusbar/is_docker_running
new file mode 100755
index 0000000..e281fe7
--- /dev/null
+++ b/.local/bin/statusbar/is_docker_running
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+ARG="${1:-$BLOCK_BUTTON}"
+
+[ ! -z "${BLOCK_BUTTON}" ] && notify-send 'Running containers' "$(docker ps --format '{{.Names}}')" && exit
+
+systemctl is-active docker >/dev/null && echo -en "\uf308$(docker ps -q | wc -l)"
diff --git a/.local/bin/statusbar/meminfo b/.local/bin/statusbar/meminfo
index 2b31b97..1be4c65 100755
--- a/.local/bin/statusbar/meminfo
+++ b/.local/bin/statusbar/meminfo
@@ -1,13 +1,19 @@
-#!/usr/bin/env sh
+#!/usr/bin/env bash
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}')"
- ;;
+# For compatability with older dwmblocks
+ARG=${1:-$BLOCK_BUTTON}
+
+case $ARG 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 "]" }'
+MEM=( $(free -h | awk '/Mem/{print $3 " " $2}') )
+#USAGE=`(( $(echo "${MEM[0]::-2} > 17" | bc -l) )) && echo "\x0c${MEM[0]}\x0b" || echo "${MEM[0]}"`
+
+echo -e "[${MEM[0]} \x11\x0b ${MEM[1]}]"
diff --git a/.local/bin/statusbar/netinfo b/.local/bin/statusbar/netinfo
index d59ef05..62c3619 100755
--- a/.local/bin/statusbar/netinfo
+++ b/.local/bin/statusbar/netinfo
@@ -1,4 +1,4 @@
-#!/usr/bin/env sh
+#!/usr/bin/env bash
netstatus="$(awk '{
n = split(FILENAME, a, "/")
@@ -6,29 +6,31 @@ netstatus="$(awk '{
}' /sys/class/net/[ew]*/operstate | sort -k 2)"
function add_connected_address() {
- TMPIFS=$IFS
+ 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
+ AP_NAME="$(iwgetid -r)"
+ [ -n "${address}" ] && [ -n "${AP_NAME}" ] && address="${address} (${AP_NAME})"
+ echo "${line} ${address}"
done
- IFS=$TMPIFS
+ IFS="${TMPIFS}"
}
ARG=${1:-$BLOCK_BUTTON}
case $ARG in
- 1) notify-send --urgency=low "Internet connection" "$(add_connected_address)" ;;
+ 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'
+ echo -en '\x0c\uf701'
else
- echo -n "${netstatus}" | sed -En 's/^(w[^ ]+).*up//p;s/^(e[^ ]+).*up/\x0d/p'
+ echo -en '\x0d'
+ echo -en $(echo -n "${netstatus}" | sed -En 's/^(w[^ ]+).*up/\\uf1eb/p;s/^(e[^ ]+).*up/\\uf700/p')
fi
echo -en '\x0b'
diff --git a/.local/bin/statusbar/timeinfo b/.local/bin/statusbar/timeinfo
index a091f84..fcfc1bd 100755
--- a/.local/bin/statusbar/timeinfo
+++ b/.local/bin/statusbar/timeinfo
@@ -1,15 +1,16 @@
-#!/usr/bin/env sh
+#!/usr/bin/env bash
ARG=${1:-$BLOCK_BUTTON}
case $ARG in
- 1) notify-send --urgency=low \
- "Calendar" \
- "$(cal -w -m)"
- ;;
- 3) notify-send --urgency=low \
- "Weather" \
- "$(weather)"
- ;;
- esac
+ 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
index fd09b13..71d40ad 100755
--- a/.local/bin/statusbar/volinfo
+++ b/.local/bin/statusbar/volinfo
@@ -1,11 +1,9 @@
-#!/usr/bin/env sh
+#!/usr/bin/env bash
ARG=${1:-$BLOCK_BUTTON}
case $ARG in
- 1) pamixer -t && sigdwmblocks 4;;
- 4) pamixer -i 1 && sigdwmblocks 4;;
- 5) pamixer -d 1 && sigdwmblocks 4;;
+ 1) pamixer -t && sigdwmblocks 6;;
esac
VOL=$(pamixer --get-volume)