feat: simplify vol, light and am

This commit is contained in:
ange 2024-04-25 15:43:28 +02:00
parent 57243c81fa
commit 47c176f3bc
Signed by: ange
GPG Key ID: 9E0C4157BB7BEB1D
3 changed files with 46 additions and 66 deletions

View File

@ -1,10 +1,5 @@
#!/bin/bash -e #!/bin/bash -e
# TODO
# mount all partitions by selecting disk
# usage
# support for /mnt
function get_row() { function get_row() {
local row _col local row _col
@ -22,27 +17,23 @@ function clear_output() {
done done
} }
function main() { while true; do
while true; do mapfile -t LSBLK <<< "$(lsblk -n --paths --list | grep part)"
mapfile -t LSBLK <<< "$(lsblk -n --paths --list | grep part)"
COLUMNS=1
select dev in "${LSBLK[@]}"; do
if [ -z "$dev" ]; then
clear_output
break
fi
name="$(awk '{print $1}' <<< "$dev")"
COLUMNS=1
select dev in "${LSBLK[@]}"; do
if [ -z "$dev" ]; then
clear_output clear_output
if mount | grep -q "$name"; then
umount "$name"
else
udisksctl mount -b "$name" > /dev/null
fi
break break
done || exit fi
done name="$(awk '{print $1}' <<< "$dev")"
}
main "$@" clear_output
if mount | grep -q "$name"; then
umount "$name"
else
udisksctl mount -b "$name" > /dev/null
fi
break
done || exit
done

View File

@ -13,7 +13,6 @@ function round() {
} }
function get_current() { function get_current() {
local d="$1"
local cur; cur="$(cat "$1/brightness")" local cur; cur="$(cat "$1/brightness")"
local max; max="$(cat "$1/max_brightness")" local max; max="$(cat "$1/max_brightness")"
@ -21,22 +20,20 @@ function get_current() {
} }
function set_light() { function set_light() {
local d="$1" local max; max="$(cat "$1/max_brightness")"
local max; max="$(cat "$d/max_brightness")"
echo "$((CUR * max / 100))" > "$d/brightness" echo "$((CUR * max / 100))" > "$1/brightness"
} }
NOTIFY='notify-send -t 1000 -a changeBrightness -u low' NOTIFY=(notify-send -t 1000 -a "$(basename "$0")" -u low)
NOTIFYVOL="$NOTIFY -i audio-volume-high"
DIRS=(/sys/class/backlight/*) DIRS=(/sys/class/backlight/*)
CUR="$(get_current "${DIRS[0]}")" CUR="$(get_current "${DIRS[0]}")"
case "${1:0:1}" in case "${1:0:1}" in
'') echo "$CUR"; exit ;; '') echo "$CUR"; exit ;;
'+'|'-') CUR="$(round $((CUR + "$1")) "$1")" ;; '+'|'-') CUR="$(round $((CUR + $1)) "$1")" ;;
*) CUR="$1" ;; *) CUR="$1" ;;
esac esac
[ "$CUR" -lt 0 ] && CUR=0 [ "$CUR" -lt 0 ] && CUR=0
@ -46,4 +43,4 @@ for d in "${DIRS[@]}"; do
set_light "$d" set_light "$d"
done done
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%" "${NOTIFY[@]}" -h string:synchronous:light -h int:value:"$CUR" "$CUR%"

View File

@ -1,42 +1,34 @@
#!/bin/bash -e #!/bin/bash -e
NOTIFY='notify-send -t 1000 -a changeVolume -u low'
NOTIFYVOL="$NOTIFY -i audio-volume-high"
SINK='@DEFAULT_AUDIO_SINK@' SINK='@DEFAULT_AUDIO_SINK@'
WPCUR="$(wpctl get-volume "$SINK")" NOTIFY=(notify-send -t 1000 -a "$(basename "$0")" -u low)
CUR="$((10#$(tr -dc '0-9' <<< "$WPCUR")))"
grep -q MUTED <<< "$WPCUR" && MUTE=1 || MUTE=0 function update_vol() {
if [[ "$1" =~ ^(-|\+)* ]]; then
if [ "$1" == 'm' ]; then CUR="$((CUR - CUR % $1 + $1))"
if [ "$MUTE" = 1 ]; then [ "$CUR" -lt 0 ] && CUR=0
wpctl set-mute "$SINK" 0 [ "$CUR" -gt 150 ] && CUR=150
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
else else
wpctl set-mute "$SINK" 1 CUR="$1"
$NOTIFY -i audio-volume-muted -h string:synchronous:vol "Mute"
fi fi
else
case "${1:0:1}" in
'')
echo "$CUR"; exit
;;
'+'|'-')
CUR="$((CUR - CUR % $1 + $1))"
[ "$CUR" -lt 0 ] && CUR=0
[ "$CUR" -gt 150 ] && CUR=150
;;
*)
CUR="$1"
;;
esac
wpctl set-volume "$SINK" "$CUR%" wpctl set-volume "$SINK" "$CUR%"
if [ "$MUTE" = 1 ]; then }
wpctl set-mute "$SINK" 0
read -r _ CUR MUTE < <(wpctl get-volume "$SINK")
CUR="${CUR/#0/}"; CUR="${CUR/#./}"
if [ -z "$1" ]; then
echo "$CUR"
exit
elif [ "$1" == 'm' ] && [ -z "$MUTE" ]; then
wpctl set-mute "$SINK" 1
"${NOTIFY[@]}" -i audio-volume-muted -h string:synchronous:vol "Mute"
else
if [[ "$1" =~ [0-9] ]]; then
update_vol "$1"
fi fi
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%" [ -n "$MUTE" ] && wpctl set-mute "$SINK" 0
"${NOTIFY[@]}" -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
fi fi
# update sbar # update sbar