feat: Add startup script to run commands on system startup

This commit is contained in:
Menno van Leeuwen 2024-08-27 21:19:26 +02:00
parent 63a1948551
commit f46a7fdabf
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE
4 changed files with 90 additions and 9 deletions

60
bin/actions/startup.sh Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env zsh
source $HOME/dotfiles/bin/helpers/functions.sh
countdown() {
for i in $(seq $1 -1 1); do
printfe "%s" "green" " - Waiting for $i seconds... "
echo -en "\r"
sleep 1
done
}
run_startup_scripts() {
# Initialize array to hold commands
local startup_commands=()
# Read each command key and add it to the array
while IFS= read -r command; do
startup_commands+=("$command")
done < <(cat $HOME/dotfiles/config/config.yaml | shyaml keys config.startup.commands)
# Read delay and delay_between_ms values from YAML
local delay=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.startup.delay)
local delay_between_ms=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.startup.delay_between_ms)
printfe "%s\n" "cyan" "Running startup commands... (delay: $delay s, delay_between: $delay_between_ms ms)"
# Wait for the initial delay
countdown $delay
# Execute each command in a new screen window
for command_key in "${startup_commands[@]}"; do
local command=$(cat $HOME/dotfiles/config/config.yaml | shyaml get-value config.startup.commands.$command_key)
printfe "%s" "green" " - Running '"
printfe "%s" "blue" "$command_key"
printfe "%s" "green" "'... ("
printfe "%s" "blue" "$command"
printfe "%s\n" "green" ")"
# Run the command in a new screen session named after the command_key
screen -dmS $command_key zsh -c "eval $command"
# Wait for the delay between commands
sleep $(echo "scale=2; $delay_between_ms / 1000" | bc)
done
}
# Check if we're in a graphical session
if [[ -z "$DISPLAY" && "$XDG_SESSION_TYPE" != "x11" && "$XDG_SESSION_TYPE" != "wayland" ]]; then
echo "Not in a graphical session. Exiting."
exit 0
fi
run_startup_scripts
# Show message to press any key to close the terminal window
printfe "%s" "green" "Press any key to close this window..."
read -s -n 1
exit 0

View File

@ -72,10 +72,14 @@ case $1 in
"secrets") "secrets")
secrets $@ secrets $@
;; ;;
term) "startup")
# Run $HOME/dotfiles/bin/actions/startup.sh $@ in a new terminal window (Use the default terminal emulator x-terminal-emulator) (Ensure the terminal closes after the script is done)
x-terminal-emulator -e $HOME/dotfiles/bin/actions/startup.sh $@
;;
"term")
$HOME/dotfiles/bin/actions/term.sh $@ $HOME/dotfiles/bin/actions/term.sh $@
;; ;;
hotkey-daemon) "hotkey-daemon")
bash -c "swhks & pkexec swhkd -c ~/.config/swhkdrc" & bash -c "swhks & pkexec swhkd -c ~/.config/swhkdrc" &
;; ;;
*) *)

View File

@ -49,6 +49,11 @@ config:
source: ~/dotfiles/config/alacritty.toml source: ~/dotfiles/config/alacritty.toml
target: ~/.config/alacritty/alacritty.toml target: ~/.config/alacritty/alacritty.toml
# Autostart desktop file
autostart:
source: ~/dotfiles/config/dotf-autostart.desktop
target: ~/.config/autostart/dotf-autostart.desktop
# What groups users should be added # What groups users should be added
user_groups: user_groups:
menno: menno:
@ -74,13 +79,18 @@ config:
# Commands to run after login # Commands to run after login
startup: startup:
- spotify delay: 5
- vesktop delay_between_ms: 500
- dotf hotkey-daemon commands:
- brave-browser 1password: 1password
- steam hotkey-deamon: dotf hotkey-daemon
- 1password # Might want to run steam in flatpak at some point: flatpak run com.valvesoftware.Steam
- flatpak run org.telegram.desktop # Not possible at this point due to avorion needing workshop mods symlinked
steam: steam
trayscale: flatpak run dev.deedles.Trayscale
spotify: flatpak run com.spotify.Client
vesktop: flatpak run dev.vencord.Vesktop
telegram: flatpak run org.telegram.desktop
# Fonts to install (Mostly tested with Nerd Fonts) # Fonts to install (Mostly tested with Nerd Fonts)
fonts: fonts:

View File

@ -0,0 +1,7 @@
[Desktop Entry]
Type=Application
Name=Startup Script
Exec=~/dotfiles/bin/actions/startup.sh
X-GNOME-Autostart-enabled=true
NoDisplay=false
Comment=Run startup script when logging into Cinnamon