feat: simplify vol, light and am
This commit is contained in:
parent
57243c81fa
commit
47c176f3bc
@ -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,8 +17,7 @@ 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
|
COLUMNS=1
|
||||||
@ -42,7 +36,4 @@ function main() {
|
|||||||
fi
|
fi
|
||||||
break
|
break
|
||||||
done || exit
|
done || exit
|
||||||
done
|
done
|
||||||
}
|
|
||||||
|
|
||||||
main "$@"
|
|
||||||
|
@ -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,21 +20,19 @@ 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
|
||||||
|
|
||||||
@ -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%"
|
||||||
|
@ -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
|
|
||||||
if [ "$MUTE" = 1 ]; then
|
|
||||||
wpctl set-mute "$SINK" 0
|
|
||||||
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
|
|
||||||
else
|
|
||||||
wpctl set-mute "$SINK" 1
|
|
||||||
$NOTIFY -i audio-volume-muted -h string:synchronous:vol "Mute"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
case "${1:0:1}" in
|
|
||||||
'')
|
|
||||||
echo "$CUR"; exit
|
|
||||||
;;
|
|
||||||
'+'|'-')
|
|
||||||
CUR="$((CUR - CUR % $1 + $1))"
|
CUR="$((CUR - CUR % $1 + $1))"
|
||||||
[ "$CUR" -lt 0 ] && CUR=0
|
[ "$CUR" -lt 0 ] && CUR=0
|
||||||
[ "$CUR" -gt 150 ] && CUR=150
|
[ "$CUR" -gt 150 ] && CUR=150
|
||||||
;;
|
else
|
||||||
*)
|
|
||||||
CUR="$1"
|
CUR="$1"
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
wpctl set-volume "$SINK" "$CUR%"
|
|
||||||
if [ "$MUTE" = 1 ]; then
|
|
||||||
wpctl set-mute "$SINK" 0
|
|
||||||
fi
|
fi
|
||||||
$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
|
wpctl set-volume "$SINK" "$CUR%"
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
[ -n "$MUTE" ] && wpctl set-mute "$SINK" 0
|
||||||
|
"${NOTIFY[@]}" -h string:synchronous:vol -h int:value:"$CUR" "$CUR%"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# update sbar
|
# update sbar
|
||||||
|
Loading…
Reference in New Issue
Block a user