aboutsummaryrefslogtreecommitdiffstats
path: root/polybar/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'polybar/scripts')
-rwxr-xr-xpolybar/scripts/check-all-updates.sh21
-rwxr-xr-xpolybar/scripts/pavolume.sh201
2 files changed, 222 insertions, 0 deletions
diff --git a/polybar/scripts/check-all-updates.sh b/polybar/scripts/check-all-updates.sh
new file mode 100755
index 0000000..dda6212
--- /dev/null
+++ b/polybar/scripts/check-all-updates.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+#source https://github.com/x70b1/polybar-scripts
+
+# Count official repo updates
+if ! updates_arch=$(checkupdates 2> /dev/null | wc -l ); then
+ updates_arch=0
+fi
+
+# Count AUR updates using yay
+if ! updates_aur=$(yay -Qu --quiet 2> /dev/null | wc -l ); then
+ updates_aur=0
+fi
+
+# Total updates
+updates=$(("$updates_arch" + "$updates_aur"))
+
+if [ "$updates" -gt 0 ]; then
+ echo " $updates"
+else
+ echo "0"
+fi
diff --git a/polybar/scripts/pavolume.sh b/polybar/scripts/pavolume.sh
new file mode 100755
index 0000000..0fd4df5
--- /dev/null
+++ b/polybar/scripts/pavolume.sh
@@ -0,0 +1,201 @@
+#!/usr/bin/env bash
+
+# finds the active sink for pulse audio and increments the volume. useful when you have multiple audio outputs and have a key bound to vol-up and down
+
+osd='no'
+inc='2'
+capvol='no'
+maxvol='200'
+autosync='yes'
+
+# Muted status
+# yes: muted
+# no : not muted
+curStatus="no"
+active_sink=""
+limit=$((100 - inc))
+maxlimit=$((maxvol - inc))
+
+reloadSink() {
+ active_sink=$(pacmd list-sinks | awk '/* index:/{print $3}')
+}
+
+function volUp {
+
+ getCurVol
+
+ if [ "$capvol" = 'yes' ]
+ then
+ if [ "$curVol" -le 100 ] && [ "$curVol" -ge "$limit" ]
+ then
+ pactl set-sink-volume "$active_sink" -- 100%
+ elif [ "$curVol" -lt "$limit" ]
+ then
+ pactl set-sink-volume "$active_sink" -- "+$inc%"
+ fi
+ elif [ "$curVol" -le "$maxvol" ] && [ "$curVol" -ge "$maxlimit" ]
+ then
+ pactl set-sink-volume "$active_sink" "$maxvol%"
+ elif [ "$curVol" -lt "$maxlimit" ]
+ then
+ pactl set-sink-volume "$active_sink" "+$inc%"
+ fi
+
+ getCurVol
+
+ if [ ${osd} = 'yes' ]
+ then
+ qdbus org.kde.kded /modules/kosd showVolume "$curVol" 0
+ fi
+
+ if [ ${autosync} = 'yes' ]
+ then
+ volSync
+ fi
+}
+
+function volDown {
+
+ pactl set-sink-volume "$active_sink" "-$inc%"
+ getCurVol
+
+ if [ ${osd} = 'yes' ]
+ then
+ qdbus org.kde.kded /modules/kosd showVolume "$curVol" 0
+ fi
+
+ if [ ${autosync} = 'yes' ]
+ then
+ volSync
+ fi
+
+}
+
+function getSinkInputs {
+ input_array=$(pacmd list-sink-inputs | grep -B 4 "sink: $1 " | awk '/index:/{print $2}')
+}
+
+function volSync {
+ getSinkInputs "$active_sink"
+ getCurVol
+
+ for each in $input_array
+ do
+ pactl set-sink-input-volume "$each" "$curVol%"
+ done
+}
+
+function getCurVol {
+ curVol=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | grep 'volume:' | grep -E -v 'base volume:' | awk -F : '{print $3}' | grep -o -P '.{0,3}%'| sed s/.$// | tr -d ' ')
+}
+
+function volMute {
+ case "$1" in
+ mute)
+ pactl set-sink-mute "$active_sink" 1
+ curVol=0
+ status=1
+ ;;
+ unmute)
+ pactl set-sink-mute "$active_sink" 0
+ getCurVol
+ status=0
+ ;;
+ esac
+
+ if [ ${osd} = 'yes' ]
+ then
+ qdbus org.kde.kded /modules/kosd showVolume ${curVol} ${status}
+ fi
+
+}
+
+function volMuteStatus {
+ curStatus=$(pacmd list-sinks | grep -A 15 "index: $active_sink$" | awk '/muted/{ print $2}')
+}
+
+# Prints output for bar
+# Listens for events for fast update speed
+function listen {
+ firstrun=0
+
+ pactl subscribe 2>/dev/null | {
+ while true; do
+ {
+ # If this is the first time just continue
+ # and print the current state
+ # Otherwise wait for events
+ # This is to prevent the module being empty until
+ # an event occurs
+ if [ $firstrun -eq 0 ]
+ then
+ firstrun=1
+ else
+ read -r event || break
+ if ! echo "$event" | grep -e "on card" -e "on sink"
+ then
+ # Avoid double events
+ continue
+ fi
+ fi
+ } &>/dev/null
+ output
+ done
+ }
+}
+
+function output() {
+ reloadSink
+ getCurVol
+ volMuteStatus
+ if [ "${curStatus}" = 'yes' ]
+ then
+ echo "ﱝ mute"
+ else
+ if [ $curVol -gt 70 ]; then
+ echo "$curVol%"
+ elif [ $curVol -gt 30 ]; then
+ echo "$curVol%"
+ else
+ echo "$curVol%"
+ fi
+ fi
+} #}}}
+
+reloadSink
+case "$1" in
+ --up)
+ volUp
+ ;;
+ --down)
+ volDown
+ ;;
+ --togmute)
+ volMuteStatus
+ if [ "$curStatus" = 'yes' ]
+ then
+ volMute unmute
+ else
+ volMute mute
+ fi
+ ;;
+ --mute)
+ volMute mute
+ ;;
+ --unmute)
+ volMute unmute
+ ;;
+ --sync)
+ volSync
+ ;;
+ --listen)
+ # Listen for changes and immediately create new output for the bar
+ # This is faster than having the script on an interval
+ listen
+ ;;
+ *)
+ # By default print output for bar
+ output
+ ;;
+esac
+