From 52a7798bbee8ccc985fe1e9cba47de36bb8d87b6 Mon Sep 17 00:00:00 2001 From: tavo Date: Sat, 28 Dec 2024 14:36:59 -0600 Subject: [PATCH] status scripts --- X11/xinitrc | 2 +- scripts/dwm/dwmstatus | 25 +++++++++++++++++++++++++ scripts/micdown | 12 ++++++++---- scripts/micup | 12 ++++++++---- scripts/mute | 10 +++++++--- scripts/setxkbmap-next | 17 ++++++++--------- scripts/status/layoutstat | 7 ++----- scripts/status/micstat | 15 ++++++++------- scripts/status/systray | 9 +++++---- scripts/status/volstat | 14 ++++++++------ scripts/voldown | 12 ++++++++---- scripts/volup | 12 ++++++++---- 12 files changed, 96 insertions(+), 51 deletions(-) create mode 100755 scripts/dwm/dwmstatus diff --git a/X11/xinitrc b/X11/xinitrc index b853075..c156dd6 100644 --- a/X11/xinitrc +++ b/X11/xinitrc @@ -22,7 +22,7 @@ dbus-update-activation-environment --systemd --all & systemctl --user import-environment DISPLAY & xset r rate 300 70 & setxkbmap en & -dwmblocks & +STATUS_BLOCKS="tray vol mic net bat kbd time date" dwmstatus & clipmenud & dunst & picom --experimental-backends --animation-for-open-window=zoom & diff --git a/scripts/dwm/dwmstatus b/scripts/dwm/dwmstatus new file mode 100755 index 0000000..ed03249 --- /dev/null +++ b/scripts/dwm/dwmstatus @@ -0,0 +1,25 @@ +#!/bin/sh + +: "${STATUS_BLOCKS:=tray vol mic net bat kbd mem cpu time date}" +: "${STATUS_PADDING:= }" + +while true; do + blocks="" + for i in $STATUS_BLOCKS; do + case $i in + tray) blocks="$blocks$STATUS_PADDING$(systray)" ;; + vol) blocks="$blocks$STATUS_PADDING$(volstat)" ;; + mic) blocks="$blocks$STATUS_PADDING$(micstat)" ;; + net) blocks="$blocks$STATUS_PADDING$(netstat)" ;; + bat) blocks="$blocks$STATUS_PADDING$(batstat)" ;; + kbd) blocks="$blocks$STATUS_PADDING󰌌 $(layoutstat)" ;; + mem) blocks="$blocks$STATUS_PADDING $(memorystat)" ;; + cpu) blocks="$blocks$STATUS_PADDING $(cpustat)" ;; + time) blocks="$blocks$STATUS_PADDING $(date '+%I:%M%p')" ;; + date) blocks="$blocks$STATUS_PADDING $(date '+%a %Y-%m-%d')" ;; + esac + done + + xsetroot -name "$blocks" + sleep 1 +done diff --git a/scripts/micdown b/scripts/micdown index 437215f..401e910 100755 --- a/scripts/micdown +++ b/scripts/micdown @@ -1,8 +1,12 @@ #!/bin/sh # Decreases mic volume by 5% -amixer set Capture 5%- +amixer set Capture 5%- | grep -o -m 1 '[0-9]*%' -MICSTAT="$(micstat)" -notify-send -u low --replace-id=11 "$MICSTAT" 2>/dev/null -kill -45 "$(pidof dwmblocks)" 2>/dev/null +# MICSTAT="$(micstat)" +# notify-send -u low --replace-id=11 "$MICSTAT" 2>/dev/null + +DWMBLOCKS="$(pidof dwmblocks)" +if [ -n "$DWMBLOCKS" ] ; then + kill -45 "$DWMBLOCKS" 2>/dev/null +fi diff --git a/scripts/micup b/scripts/micup index 9dc8c12..1852dd4 100755 --- a/scripts/micup +++ b/scripts/micup @@ -1,8 +1,12 @@ #!/bin/sh # Increases mic volume by 5% -amixer set Capture 5%+ +amixer set Capture 5%+ | grep -o -m 1 '[0-9]*%' -MICSTAT="$(micstat)" -notify-send -u low --replace-id=11 "$MICSTAT" 2>/dev/null -kill -45 "$(pidof dwmblocks)" 2>/dev/null +# MICSTAT="$(micstat)" +# notify-send -u low --replace-id=11 "$MICSTAT" 2>/dev/null + +DWMBLOCKS="$(pidof dwmblocks)" +if [ -n "$DWMBLOCKS" ] ; then + kill -45 "$DWMBLOCKS" 2>/dev/null +fi diff --git a/scripts/mute b/scripts/mute index 6c4c6e5..35632be 100755 --- a/scripts/mute +++ b/scripts/mute @@ -3,6 +3,10 @@ amixer -q set Master toggle -VOLSTAT="$(volstat)" -notify-send -u low --replace-id=10 "$VOLSTAT" 2>/dev/null -kill -44 "$(pidof dwmblocks)" 2>/dev/null +# VOLSTAT="$(volstat)" +# notify-send -u low --replace-id=10 "$VOLSTAT" 2>/dev/null + +DWMBLOCKS="$(pidof dwmblocks)" +if [ -n "$DWMBLOCKS" ] ; then + kill -44 "$DWMBLOCKS" 2>/dev/null +fi diff --git a/scripts/setxkbmap-next b/scripts/setxkbmap-next index 9d68fad..263dd3a 100755 --- a/scripts/setxkbmap-next +++ b/scripts/setxkbmap-next @@ -4,15 +4,12 @@ # Add whatever layouts you want set -- us latam -# Get current layout, and total -current=$(setxkbmap -query | grep layout | cut -d " " -f 6) -total=$(counter=0 ; for layout in "$@" ; do : $((counter+=1)) ; done ; echo "$counter") +current=$(setxkbmap -query | awk '/layout/{ print $2 }') +total="$#" index=1 -# For each layout, find whichever is currently -# selected, and apply the next one -for layout in "$@" ; do - if [ "$layout" = "$current" ] ; then +for l in "$@" ; do + if [ "$l" = "$current" ] ; then : $((index+=1)) [ "$index" -gt "$total" ] && index=1 setxkbmap $(eval "echo \${${index}}") @@ -21,5 +18,7 @@ for layout in "$@" ; do : $((index+=1)) done -# Restart statusbar module (dwm & dwmblocks) -kill -46 "$(pidof dwmblocks)" +DWMBLOCKS="$(pidof dwmblocks)" +if [ -n "$DWMBLOCKS" ] ; then + kill -46 "$DWMBLOCKS" 2>/dev/null +fi diff --git a/scripts/status/layoutstat b/scripts/status/layoutstat index 1b2c1c5..511a6e2 100755 --- a/scripts/status/layoutstat +++ b/scripts/status/layoutstat @@ -1,10 +1,7 @@ #!/bin/sh # Get current keyboard layout -layout="$( \ - setxkbmap -query | grep layout | awk '{print $2}' | - sed 's/latam/la/' \ - )" +layout="$(setxkbmap -query | awk '/layout/{ print $2 }' | sed 's/latam/la/')" echo "$layout" -notify-send -u low --replace-id=12 "󰌌 Layout" "$layout" +# notify-send -u low --replace-id=12 "󰌌 Layout" "$layout" diff --git a/scripts/status/micstat b/scripts/status/micstat index 1480d41..664ed10 100755 --- a/scripts/status/micstat +++ b/scripts/status/micstat @@ -2,14 +2,16 @@ # Fetch current mic levels # (in current default Capture) -# Get volume levels -vol=$(amixer | grep "Capture" | grep -m 1 -o '[0-9]*[0-9]%') -vol="${vol%\%*}" # Remove percentage sign +info=$(amixer get Capture | grep -m 1 '[0-9]*%') -# If device is off (muted), notify mute, print volume otherwise -if amixer scontents | grep "Capture" | grep -q "\[off\]"; then echo "󰍭 ──────────" && exit ; fi +if [ -z "${info##*\[off\]}" ] ; then + echo "󰍭 ──────────" + exit 0 +fi + +vol="${info#*\[}" +vol="${vol%%%\]*}" -# Define bar progress with volume case 1 in $((vol >= 100)) ) bar="━━━━━━━━━━" ;; $((vol >= 90)) ) bar="━━━━━━━━━─" ;; @@ -24,5 +26,4 @@ case 1 in $((vol >= 0)) ) bar="──────────" ;; esac -# Print and notify echo "󰍬 $bar" diff --git a/scripts/status/systray b/scripts/status/systray index 7d4d355..799c1bb 100755 --- a/scripts/status/systray +++ b/scripts/status/systray @@ -1,8 +1,9 @@ #!/bin/sh systray="" -ps aux | grep -v grep | grep -q "$HOME/.config/scripts/record" && systray="$systray 󰻃" -grep -rq 'RUNNING' /proc/asound/*/*c && systray="$systray " -grep -rq 'RUNNING' /proc/asound/*/*p && systray="$systray 󰕾" +grep -rq 'RUNNING' /proc/asound/*/*c && systray="$systray " +grep -rq 'RUNNING' /proc/asound/*/*p && systray="$systray 󰕾" -[ -n "$systray" ] && echo "[$systray ]" +if [ -n "$systray" ] ; then + echo "[$systray ]" +fi diff --git a/scripts/status/volstat b/scripts/status/volstat index bd3e540..c527006 100755 --- a/scripts/status/volstat +++ b/scripts/status/volstat @@ -2,14 +2,16 @@ # Fetch current audio level # (in current default output) -# Get volume level -vol=$(amixer | grep "Playback" | grep -m 1 -o '[0-9]*[0-9]%') -vol="${vol%\%*}" # Remove percentage sign +info=$(amixer get Master | grep -m 1 '[0-9]*%') -# If device is off (muted), notify mute, print volume otherwise -if amixer scontents | grep "Playback" | grep -q "\[off\]"; then echo "󰖁 ──────────" && exit ; fi +if [ -z "${info##*\[off\]}" ] ; then + echo "󰖁 ──────────" + exit 0 +fi + +vol="${info#*\[}" +vol="${vol%%%\]*}" -# Define bar progress with volume case 1 in $((vol >= 100)) ) bar="━━━━━━━━━━" ;; $((vol >= 90)) ) bar="━━━━━━━━━─" ;; diff --git a/scripts/voldown b/scripts/voldown index cc3904d..fb5dc2b 100755 --- a/scripts/voldown +++ b/scripts/voldown @@ -1,8 +1,12 @@ #!/bin/sh # Decreases volume by 5% -amixer set Master 5%- unmute +amixer set Master 5%- unmute | grep -o -m 1 '[0-9]*%' -VOLSTAT="$(volstat)" -notify-send -u low --replace-id=10 "$VOLSTAT" 2>/dev/null -kill -44 "$(pidof dwmblocks)" 2>/dev/null +#VOLSTAT="$(volstat)" +#notify-send -u low --replace-id=10 "$VOLSTAT" 2>/dev/null + +DWMBLOCKS="$(pidof dwmblocks)" +if [ -n "$DWMBLOCKS" ] ; then + kill -44 "$DWMBLOCKS" 2>/dev/null +fi diff --git a/scripts/volup b/scripts/volup index 2a19160..493fd66 100755 --- a/scripts/volup +++ b/scripts/volup @@ -1,8 +1,12 @@ #!/bin/sh # Increases volume by 5% -amixer set Master 5%+ unmute +amixer set Master 5%+ unmute | grep -o -m 1 '[0-9]*%' -VOLSTAT="$(volstat)" -notify-send -u low --replace-id=10 "$VOLSTAT" 2>/dev/null -kill -44 "$(pidof dwmblocks)" 2>/dev/null +#VOLSTAT="$(volstat)" +#notify-send -u low --replace-id=10 "$VOLSTAT" 2>/dev/null + +DWMBLOCKS="$(pidof dwmblocks)" +if [ -n "$DWMBLOCKS" ] ; then + kill -44 "$DWMBLOCKS" 2>/dev/null +fi