diff --git a/bin/actions/startup.sh b/bin/actions/startup.sh new file mode 100755 index 0000000..b62cb1d --- /dev/null +++ b/bin/actions/startup.sh @@ -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 diff --git a/bin/dotf b/bin/dotf index abb47cb..dd2badd 100755 --- a/bin/dotf +++ b/bin/dotf @@ -72,10 +72,14 @@ case $1 in "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 $@ ;; - hotkey-daemon) + "hotkey-daemon") bash -c "swhks & pkexec swhkd -c ~/.config/swhkdrc" & ;; *) diff --git a/config/config.yaml b/config/config.yaml index fd72e45..e4357fc 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -49,6 +49,11 @@ config: source: ~/dotfiles/config/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 user_groups: menno: @@ -74,13 +79,18 @@ config: # Commands to run after login startup: - - spotify - - vesktop - - dotf hotkey-daemon - - brave-browser - - steam - - 1password - - flatpak run org.telegram.desktop + delay: 5 + delay_between_ms: 500 + commands: + 1password: 1password + hotkey-deamon: dotf hotkey-daemon + # Might want to run steam in flatpak at some point: flatpak run com.valvesoftware.Steam + # 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: diff --git a/config/dotf-autostart.desktop b/config/dotf-autostart.desktop new file mode 100644 index 0000000..3d499b5 --- /dev/null +++ b/config/dotf-autostart.desktop @@ -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