feat: Update startup script to display a welcome message and run commands based on the time of day

This commit is contained in:
2024-08-27 21:32:11 +02:00
parent f46a7fdabf
commit 443b6c5dfe
6 changed files with 38 additions and 4 deletions

2
bin/actions/startup-runner.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
x-terminal-emulator -e $HOME/dotfiles/bin/actions/startup.sh $@

View File

@ -11,6 +11,24 @@ countdown() {
} }
run_startup_scripts() { run_startup_scripts() {
logo continue
echo ""
local time_of_day
# Time of day (morning, afternoon, evening, night)
case $(date +%H) in
0[0-9]|1[0-1])
time_of_day="morning"
;;
1[2-7])
time_of_day="afternoon"
;;
1[8-9]|2[0-3])
time_of_day="evening"
;;
esac
printfe "%s" "cyan" "Welcome and good $time_of_day $(whoami)!"
echo ""
# Initialize array to hold commands # Initialize array to hold commands
local startup_commands=() local startup_commands=()
@ -37,10 +55,25 @@ run_startup_scripts() {
printfe "%s" "green" "'... (" printfe "%s" "green" "'... ("
printfe "%s" "blue" "$command" printfe "%s" "blue" "$command"
printfe "%s\n" "green" ")" printfe "%s\n" "green" ")"
# Check if a screen with the same name already exists, if so log it and don't run the command
if screen -list | grep -q $command_key; then
printfe "%s" "red" " - Screen session already exists: "
printfe "%s" "blue" "$command_key"
printfe "%s\n" "red" ""
continue
fi
# Run the command in a new screen session named after the command_key # Run the command in a new screen session named after the command_key
screen -dmS $command_key zsh -c "eval $command" screen -dmS $command_key zsh -c "eval $command"
# Check if command is ok, if not log that it failed
if [ $? -ne 0 ]; then
printfe "%s" "red" " - Command failed: "
printfe "%s" "blue" "$command"
printfe "%s\n" "red" ""
fi
# Wait for the delay between commands # Wait for the delay between commands
sleep $(echo "scale=2; $delay_between_ms / 1000" | bc) sleep $(echo "scale=2; $delay_between_ms / 1000" | bc)
done done

View File

@ -73,8 +73,7 @@ case $1 in
secrets $@ secrets $@
;; ;;
"startup") "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) $HOME/dotfiles/bin/actions/startup-runner.sh $@
x-terminal-emulator -e $HOME/dotfiles/bin/actions/startup.sh $@
;; ;;
"term") "term")
$HOME/dotfiles/bin/actions/term.sh $@ $HOME/dotfiles/bin/actions/term.sh $@

0
bin/helpers/git.sh Normal file → Executable file
View File

View File

@ -79,7 +79,7 @@ config:
# Commands to run after login # Commands to run after login
startup: startup:
delay: 5 delay: 1
delay_between_ms: 500 delay_between_ms: 500
commands: commands:
1password: 1password 1password: 1password

2
config/dotf-autostart.desktop Normal file → Executable file
View File

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