a bunch of stuff, including upgrade to wayland and ndi streaming to imac

This commit is contained in:
Sebastian Moser
2025-01-12 18:50:01 +01:00
parent cfd9bfccbd
commit 40f190de88
29 changed files with 1813 additions and 55 deletions

79
scripts/batteryscript.sh Executable file
View File

@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# Settings
battery_percent_MODULUS=5 # How many percent difference are required for another update
INTERVAL=5 # The interval at which to check the battery percentage
ALERT_SCRIPT="sudo /home/mia/Scripts/keyboard_alert.sh"
# Battery Levels
BAT_RECOMMENDED_UPPER_LIMIT=80
BAT_RECOMMENDED_LOWER_LIMIT=40
BAT_SLIGHTLY_LOW=30
BAT_LOW=20
BAT_VERY_LOW=10
BAT_HIB=5
force_notification=0
last_battery_percent=0
get_percentage()
{
echo $(cat /sys/bus/acpi/drivers/battery/*/power_supply/BAT?/capacity)
}
countdown()
{
for i in $(seq 1 10);
do
if [[ $(cat /sys/bus/acpi/drivers/battery/*/power_supply/BAT?/status) = "Charging" ]]; then
return
fi
sleep 1
notify-send $((10-$i)) -u critical
done
systemctl hibernate
}
while true;
do
sleep $INTERVAL
battery_percent=$(get_percentage)
if [[ $battery_percent -eq $last_battery_percent ]]; then
continue
fi
if [[ $(( battery_percent % $battery_percent_MODULUS )) -ne 0 && $force_notification -ne 1 ]]; then
continue
fi
# Is battery charging?
if [[ $(cat /sys/bus/acpi/drivers/battery/*/power_supply/BAT?/status) = "Charging" ]]; then
if [[ $battery_percent -ge $BAT_RECOMMENDED_UPPER_LIMIT ]]; then
notify-send "Im full!" -u low
$ALERT_SCRIPT
fi
# Is battery discharging?
else
if [[ $battery_percent -le $BAT_HIB ]]; then
notify-send "Self destructing in T Minus 10 Seconds..." -u critical &&
countdown
elif [[ $battery_percent -le $BAT_VERY_LOW ]]; then
notify-send "I beg you, I'm about to die!" -u critical &&
$ALERT_SCRIPT 5
elif [[ $battery_percent -le $BAT_LOW ]]; then
notify-send "Can you please plug me in aleady? I'm dying!" -u normal &&
$ALERT_SCRIPT 2
elif [[ $battery_percent -le $BAT_SLIGHTLY_LOW ]]; then
notify-send "I'd need a recharge about now pwp" -u normal &&
$ALERT_SCRIPT 1
elif [[ $battery_percent -le $BAT_RECOMMENDED_LOWER_LIMIT ]]; then
notify-send "Please plug me in pwp" -u low
fi
fi
last_battery_percent=$battery_percent
done

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
export XDG_RUNTIME_DIR="/run/user/$(id -u $SENDER_USER)"
export WAYLAND_DISPLAY="wayland-0"
ALERT_SCRIPT="sudo ./keyboard_alert.sh 2"
status=$1
if [[ $status -eq 0 ]]; then
dunstctl close-all
notify-send "No mommy put it back pwp" -u low
$ALERT_SCRIPT
else
dunstctl close-all
notify-send "Thank you for plugging me mommy ~" -u low
$ALERT_SCRIPT
fi

16
scripts/colorscript.sh Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
while true; do
sudo ectool led battery red
sleep 0.2
sudo ectool led battery green
sleep 0.2
sudo ectool led battery blue
sleep 0.2
sudo ectool led battery yellow
sleep 0.2
sudo ectool led battery white
sleep 0.2
sudo ectool led battery amber
sleep 0.2
done

5
scripts/get_power_usage.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
power=$(cat /sys/class/power_supply/BAT1/current_now /sys/class/power_supply/BAT1/voltage_now | xargs | awk '{ printf "%.1f\n", $1 * $2 / 1e12 }')
echo $power

12
scripts/idlescript Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env bash
swayidle -w -d \
timeout 15 'bash -c "~/.config/nixos/scripts/keyboard_fade_brightness.sh 4 0 0.05"' \
resume 'bash -c "brightnessctl -d framework_laptop::kbd_backlight set 4"' \
timeout 170 'bash -c "brightnessctl g > /tmp/current_brightness && brightnessctl -e s 30%-"' \
resume 'bash -c "if [ -f /tmp/current_brightness ]; then brightnessctl set $(cat /tmp/current_brightness); fi"' \
timeout 180 '/home/mia/Scripts/lockscript' \
timeout 200 'swaymsg "output * dpms off"' \
resume 'swaymsg "output * dpms on"' \
after-resume 'swaymsg "output * dpms on"' \
before-sleep '/home/mia/Scripts/lockscript'

31
scripts/keyboard_alert.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/usr/bin/env bash
CURRENT_LIGHT=$(sudo ectool pwmgetkblight | cut -d' ' -f 5)
echo $CURRENT_LIGHT >> /home/mia/Scripts/output.txt
if [[ $CURRENT_LIGHT -eq "" ]]
then
CURRENT_LIGHT=0
fi
if [[ $CURRENT_LIGHT -eq 0 ]];
then
FIRST_LIGHT_VALUE=100
SECOND_LIGHT_VALUE=0
else
FIRST_LIGHT_VALUE=$CURRENT_LIGHT
SECOND_LIGHT_VALUE=0
fi
count=0
while [[ $count -lt $1 ]];
do
sudo ectool pwmsetkblight $FIRST_LIGHT_VALUE
sleep 0.13
sudo ectool pwmsetkblight $SECOND_LIGHT_VALUE
sleep 0.13
((count=count+1))
done
sudo ectool pwmsetkblight $CURRENT_LIGHT

8
scripts/lockscript Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env bash
path="/home/mia/Pictures/Screenshots/screen.png"
grim "$path" &&
corrupter -add 0 -bheight 20 -stdabber 10 -boffset 50 "$path" "$path" &&
swaylock -c /home/mia/.config/swaylock/config &&
swaymsg "output * dpms on"

1
scripts/screenshot.sh Executable file
View File

@@ -0,0 +1 @@
flameshot gui -r | wl-copy

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
# Get the PID of the focused window
PID=$(swaymsg -t get_tree | jq -r '.. | select(.focused? == true).pid')
FOCUSED_WIN_ID=$(swaymsg -t get_tree | jq -r '.. | select(.focused? == true).id')
# Check if the process is frozen
STATE=$(ps -o state= -p $PID)
if [[ "$STATE" == *T* ]]; then
# If the process is frozen, unfreeze it and reset border color
kill -CONT $PID
swaymsg [con_id=$FOCUSED_WIN_ID] border pixel 2
else
# If the process is running, freeze it and change border color
kill -STOP $PID
swaymsg [con_id=$FOCUSED_WIN_ID] border pixel 10
fi

103
scripts/waybar-timer.sh Executable file
View File

@@ -0,0 +1,103 @@
#!/usr/bin/env bash
### AUTHOR: Johann Birnick (github: jbirnick)
### PROJECT REPO: https://github.com/jbirnick/waybar-timer
## FUNCTIONS
now () { date --utc +%s; }
killTimer () { rm -rf /tmp/waybar-timer ; }
timerSet () { [ -e /tmp/waybar-timer/ ] ; }
timerPaused () { [ -f /tmp/waybar-timer/paused ] ; }
timerExpiry () { cat /tmp/waybar-timer/expiry ; }
timerAction () { cat /tmp/waybar-timer/action ; }
secondsLeftWhenPaused () { cat /tmp/waybar-timer/paused ; }
minutesLeftWhenPaused () { echo $(( ( $(secondsLeftWhenPaused) + 59 ) / 60 )) ; }
secondsLeft () { echo $(( $(timerExpiry) - $(now) )) ; }
minutesLeft () { echo $(( ( $(secondsLeft) + 59 ) / 60 )) ; }
printExpiryTime () { notify-send -u low -r 12345 "Timer expires at $( date -d "$(secondsLeft) sec" +%H:%M)" ;}
printPaused () { notify-send -u low -r 12345 "Timer paused" ; }
removePrinting () { notify-send -C 12345 ; }
updateTail () {
# check whether timer is expired
if timerSet
then
if { timerPaused && [ $(minutesLeftWhenPaused) -le 0 ] ; } || { ! timerPaused && [ $(minutesLeft) -le 0 ] ; }
then
eval $(timerAction)
killTimer
removePrinting
fi
fi
# update output
if timerSet
then
if timerPaused
then
echo "{\"text\": \"$(minutesLeftWhenPaused)\", \"alt\": \"paused\", \"tooltip\": \"Timer paused\", \"class\": \"timer\" }"
else
echo "{\"text\": \"$(minutesLeft)\", \"alt\": \"running\", \"tooltip\": \"Timer expires at $( date -d "$(secondsLeft) sec" +%H:%M)\", \"class\": \"timer\" }"
fi
else
echo "{\"text\": \"0\", \"alt\": \"standby\", \"tooltip\": \"No timer set\", \"class\": \"timer\" }"
fi
}
## MAIN CODE
case $1 in
updateandprint)
updateTail
;;
new)
killTimer
mkdir /tmp/waybar-timer
echo "$(( $(now) + 60*${2} ))" > /tmp/waybar-timer/expiry
echo "${3}" > /tmp/waybar-timer/action
printExpiryTime
;;
increase)
if timerSet
then
if timerPaused
then
echo "$(( $(secondsLeftWhenPaused) + ${2} ))" > /tmp/waybar-timer/paused
else
echo "$(( $(timerExpiry) + ${2} ))" > /tmp/waybar-timer/expiry
printExpiryTime
fi
else
exit 1
fi
;;
cancel)
killTimer
removePrinting
;;
togglepause)
if timerSet
then
if timerPaused
then
echo "$(( $(now) + $(secondsLeftWhenPaused) ))" > /tmp/waybar-timer/expiry
rm -f /tmp/waybar-timer/paused
printExpiryTime
else
secondsLeft > /tmp/waybar-timer/paused
rm -f /tmp/waybar-timer/expiry
printPaused
fi
else
exit 1
fi
;;
*)
echo "Please read the manual at https://github.com/jbirnick/waybar-timer ."
;;
esac