Files
.dotfiles/stow_me/scripts/app_close_and_restart.sh
T
glennigen 2d8321a530 Refaktorer shutdown/genstart scripts: bekræftelse først, nedtælling til sidst
- Flyt Y/n bekræftelse til toppen, inden programmer lukkes
- Afslut med det samme ved 'n' i stedet for at køre alt først
- Erstat slutprompt med 3-sekunders nedtælling (Ctrl+C for at afbryde)
- Oversæt alle kommentarer og beskeder fra dansk til engelsk
2026-05-23 23:32:01 +02:00

76 lines
1.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Function for Flatpak apps
close_flatpak() {
local app="$1"
flatpak kill "$app"
for i in $(seq 1 5); do
sleep 1
if ! pgrep -f "$app" > /dev/null; then
echo "$app closed (attempt $i)"
return
fi
echo "$app still running, retrying ($i/5)..."
flatpak kill "$app"
done
echo "$app force closing (KILL)..."
pkill -KILL -f "$app"
pkill -KILL -f bwrap 2>/dev/null # kill sandbox container
}
# Function for native apps
close_app() {
local app="$1"
pkill -TERM -f "$app"
for i in $(seq 1 5); do
sleep 1
if ! pgrep -f "$app" > /dev/null; then
echo "$app closed (attempt $i)"
return
fi
echo "$app still running, retrying ($i/5)..."
pkill -TERM -f "$app"
done
echo "$app force closing (KILL)..."
pkill -KILL -f "$app"
}
# Prompt
read -r -p "Close all programs and reboot? [Y/n]: " response
response="${response:-Y}"
if [[ ! "$response" =~ ^[Yy]$ ]]; then
echo "Cancelled."
exit 0
fi
# Close apps
close_flatpak "com.discordapp.Discord"
close_flatpak "io.github.lullabyX.sone"
close_flatpak "rocks.shy.VacuumTube"
close_app "firefox"
# Close Steam
if pgrep -f steam > /dev/null; then
steam -shutdown
for i in $(seq 1 5); do
sleep 1
if ! pgrep -f steam > /dev/null; then
echo "Steam closed (attempt $i)"
break
fi
echo "Steam still running ($i/5)..."
done
pkill -KILL -f steam 2>/dev/null
else
echo "Steam not running, skipping..."
fi
# Countdown Ctrl+C to cancel
echo "All programs closed. Rebooting in:"
for i in 3 2 1; do
echo " $i..."
sleep 1
done
sudo shutdown -r now