diff --git a/.local/bin/am b/.local/bin/am index 8f45406..3871eba 100755 --- a/.local/bin/am +++ b/.local/bin/am @@ -1,10 +1,5 @@ #!/bin/bash -e -# TODO -# mount all partitions by selecting disk -# usage -# support for /mnt - function get_row() { local row _col @@ -22,27 +17,23 @@ function clear_output() { done } -function main() { - while true; do - 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")" +while true; do + mapfile -t LSBLK <<< "$(lsblk -n --paths --list | grep part)" + COLUMNS=1 + select dev in "${LSBLK[@]}"; do + if [ -z "$dev" ]; then clear_output - if mount | grep -q "$name"; then - umount "$name" - else - udisksctl mount -b "$name" > /dev/null - fi break - done || exit - done -} + fi + 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 diff --git a/.local/bin/light b/.local/bin/light index ed824e1..c5851dc 100755 --- a/.local/bin/light +++ b/.local/bin/light @@ -13,7 +13,6 @@ function round() { } function get_current() { - local d="$1" local cur; cur="$(cat "$1/brightness")" local max; max="$(cat "$1/max_brightness")" @@ -21,22 +20,20 @@ function get_current() { } function set_light() { - local d="$1" - local max; max="$(cat "$d/max_brightness")" + local max; max="$(cat "$1/max_brightness")" - echo "$((CUR * max / 100))" > "$d/brightness" + echo "$((CUR * max / 100))" > "$1/brightness" } -NOTIFY='notify-send -t 1000 -a changeBrightness -u low' -NOTIFYVOL="$NOTIFY -i audio-volume-high" +NOTIFY=(notify-send -t 1000 -a "$(basename "$0")" -u low) DIRS=(/sys/class/backlight/*) CUR="$(get_current "${DIRS[0]}")" case "${1:0:1}" in - '') echo "$CUR"; exit ;; - '+'|'-') CUR="$(round $((CUR + "$1")) "$1")" ;; - *) CUR="$1" ;; + '') echo "$CUR"; exit ;; + '+'|'-') CUR="$(round $((CUR + $1)) "$1")" ;; + *) CUR="$1" ;; esac [ "$CUR" -lt 0 ] && CUR=0 @@ -46,4 +43,4 @@ for d in "${DIRS[@]}"; do set_light "$d" done -$NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%" +"${NOTIFY[@]}" -h string:synchronous:light -h int:value:"$CUR" "$CUR%" diff --git a/.local/bin/vol b/.local/bin/vol index 66bb7ea..6f89851 100755 --- a/.local/bin/vol +++ b/.local/bin/vol @@ -1,42 +1,34 @@ #!/bin/bash -e -NOTIFY='notify-send -t 1000 -a changeVolume -u low' -NOTIFYVOL="$NOTIFY -i audio-volume-high" - SINK='@DEFAULT_AUDIO_SINK@' -WPCUR="$(wpctl get-volume "$SINK")" -CUR="$((10#$(tr -dc '0-9' <<< "$WPCUR")))" +NOTIFY=(notify-send -t 1000 -a "$(basename "$0")" -u low) -grep -q MUTED <<< "$WPCUR" && MUTE=1 || MUTE=0 - -if [ "$1" == 'm' ]; then - if [ "$MUTE" = 1 ]; then - wpctl set-mute "$SINK" 0 - $NOTIFYVOL -h string:synchronous:vol -h int:value:"$CUR" "$CUR%" +function update_vol() { + if [[ "$1" =~ ^(-|\+)* ]]; then + CUR="$((CUR - CUR % $1 + $1))" + [ "$CUR" -lt 0 ] && CUR=0 + [ "$CUR" -gt 150 ] && CUR=150 else - wpctl set-mute "$SINK" 1 - $NOTIFY -i audio-volume-muted -h string:synchronous:vol "Mute" + CUR="$1" 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%" - 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 - $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 # update sbar