From aa7266e92c36ce7b8c552268f33dcbae75e54cd7 Mon Sep 17 00:00:00 2001 From: Gopher Date: Tue, 18 Mar 2025 17:13:53 +0530 Subject: [PATCH] Add scripts --- bin/backlight.sh | 22 +++++++++++++++++++ bin/search.sh | 24 +++++++++++++++++++++ bin/volume.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100755 bin/backlight.sh create mode 100755 bin/search.sh create mode 100755 bin/volume.sh diff --git a/bin/backlight.sh b/bin/backlight.sh new file mode 100755 index 0000000..3d7e4a4 --- /dev/null +++ b/bin/backlight.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# Use brightnessctl to naturally adjust laptop screen brightness and send a notification + +currentbrightness=$(brightnessctl -e4 -m | awk -F, '{print substr($4, 0, length($4)-1)}') +if [ "$currentbrightness" -lt 30 ] && [ "$1" = "down" ]; then exit 1; fi + +send_notification() { + brightness=$(brightnessctl -e4 -m | awk -F, '{print substr($4, 0, length($4)-1)}') + dunstify -a "Backlight" -u critical -h int:value:"$brightness" -i "brightness" "Brightness" -t 1000 +} + +case $1 in + up) + brightnessctl -e4 set 1%+ + send_notification "$1" + ;; + down) + brightnessctl -e4 set 1%- + send_notification "$1" + ;; +esac diff --git a/bin/search.sh b/bin/search.sh new file mode 100755 index 0000000..2a47533 --- /dev/null +++ b/bin/search.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +ENGINE="$1" +shift +QUERY="$*" + +ENCODED_QUERY=$(echo "$QUERY" | sed 's/ /+/g') + +case "$ENGINE" in + yt) + xdg-open "https://www.youtube.com/results?search_query=$ENCODED_QUERY" + ;; + wikipedia) + xdg-open "https://en.wikipedia.org/wiki/Special:Search?search=$ENCODED_QUERY" + ;; + duckduckgo) + xdg-open "https://duckduckgo.com/?q=$ENCODED_QUERY" + ;; + *) + QUERY="$ENGINE $QUERY" + ENCODED_QUERY=$(echo "$QUERY" | sed 's/ /+/g') + xdg-open "https://www.google.com/search?q=$ENCODED_QUERY" + ;; +esac diff --git a/bin/volume.sh b/bin/volume.sh new file mode 100755 index 0000000..01093a5 --- /dev/null +++ b/bin/volume.sh @@ -0,0 +1,55 @@ +#!/bin/sh + + +case $1 in + up) + wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 + wpctl set-volume -l 2.0 @DEFAULT_AUDIO_SINK@ 2%+ + ;; + down) + wpctl set-mute @DEFAULT_AUDIO_SINK@ 0 + wpctl set-volume -l 2.0 @DEFAULT_AUDIO_SINK@ 2%- + ;; + mute) + wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle + ;; + *) + echo "Usage: $0 {up|down|mute}" + exit 1 + ;; +esac + +VOLUME=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{print int($2 * 100)}') + +NORMALIZED_VOLUME=$((VOLUME / 2)) + +send_notification() { + # if [ "$1" = "mute" ]; then + # ICON='' # Mute icon + # MSG="Muted" + # elif [ "$NORMALIZED_VOLUME" -lt 50 ]; then + # ICON='' # Low volume icon + # MSG="Volume: $NORMALIZED_VOLUME%" + # elif [ "$NORMALIZED_VOLUME" -lt 90 ]; then + # ICON='' # Medium volume icon + # MSG="Volume: $NORMALIZED_VOLUME%" + # else + # ICON='' # High volume icon + # MSG="Volume: $NORMALIZED_VOLUME%" + # fi + + dunstify -u normal -h "int:value:$NORMALIZED_VOLUME" -a "Volume" "Volume" -t 2000 +} + +case $1 in + mute) + if wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep -q "MUTED"; then + send_notification mute + else + send_notification + fi + ;; + *) + send_notification + ;; +esac \ No newline at end of file