Skip to content

Instantly share code, notes, and snippets.

@rmtbb
Created February 1, 2025 19:47
Show Gist options
  • Save rmtbb/0b0850dbf67bbc04eca7f1ff56af4cea to your computer and use it in GitHub Desktop.
Save rmtbb/0b0850dbf67bbc04eca7f1ff56af4cea to your computer and use it in GitHub Desktop.
stayup: a fun one-liner tool that does more than just keep your Mac awake using `caffeinate -d -u`. It adds a bit of personality by displaying two synchronized, animated ASCII eyes
caffeinate -d -u & pid=$!; trap "kill $pid" EXIT; blink=$(( $(date +%s) + 10 + RANDOM % 21 )); nextdir=$(date +%s); px=$((RANDOM % 3)); py=$((RANDOM % 3)); while sleep 0.5; do now=$(date +%s); if [ $now -ge $nextdir ]; then px=$((RANDOM % 3)); py=$((RANDOM % 3)); nextdir=$((now + 2 + RANDOM % 3)); fi; if [ $now -ge $blink ]; then clear; echo -e " +-------+ +-------+"; echo -e " |-------| |-------|"; echo -e " |-------| |-------|"; echo -e " |-------| |-------|"; echo -e " +-------+ +-------+"; echo -e "\nStay up till you wake up\nPress Control + C to exit"; sleep 0.2; blink=$(( $(date +%s) + 10 + RANDOM % 21 )); fi; clear; echo -e " +-------+ +-------+"; for r in 0 1 2; do row=""; for c in 0 1 2; do if [ $r -eq $py ] && [ $c -eq $px ]; then row="${row}\033[107m\033[30m@\033[0m"; else row="${row}\033[107m \033[0m"; fi; done; echo -e " | ${row} | | ${row} |"; done; echo -e " +-------+ +-------+"; echo -e "\nStay up till you wake up\nPress Control + C to exit"; done
@rmtbb
Copy link
Author

rmtbb commented Feb 1, 2025

stayup is a fun one-liner tool that does more than just keep your Mac awake using caffeinate -d -u. It adds a bit of personality by displaying two synchronized, animated ASCII eyes that:

stayup in action

  • Keep your computer awake:
    Utilizes macOS’s built-in caffeinate command with the -d -u options.

  • Animate synchronized eyes:
    Both eyes always look in the same random direction. The pupils update every few seconds, giving the impression of changing gaze.

  • Blink periodically:
    The eyes blink every 10–30 seconds for a brief 0.2-second "closed" display.

  • Display helpful messages:
    At the bottom of the animation, you'll see:
    Stay up till you wake up Press Control + C to exit

This tool is made by Remote BB and is perfect if you’re looking for something more entertaining than just running caffeinate -d -u.


How to Use

  1. Open your Terminal.

  2. Copy and paste the following one-liner into your Terminal:

caffeinate -d -u & pid=$!; trap "kill $pid" EXIT; blink=$(( $(date +%s) + 10 + RANDOM % 21 )); nextdir=$(date +%s); px=$((RANDOM % 3)); py=$((RANDOM % 3)); while sleep 0.5; do now=$(date +%s); if [ $now -ge $nextdir ]; then px=$((RANDOM % 3)); py=$((RANDOM % 3)); nextdir=$((now + 2 + RANDOM % 3)); fi; if [ $now -ge $blink ]; then clear; echo -e "  +-------+   +-------+"; echo -e "  |-------|   |-------|"; echo -e "  |-------|   |-------|"; echo -e "  |-------|   |-------|"; echo -e "  +-------+   +-------+"; echo -e "\nStay up till you wake up\nPress Control + C to exit"; sleep 0.2; blink=$(( $(date +%s) + 10 + RANDOM % 21 )); fi; clear; echo -e "  +-------+   +-------+"; for r in 0 1 2; do row=""; for c in 0 1 2; do if [ $r -eq $py ] && [ $c -eq $px ]; then row="${row}\033[107m\033[30m@\033[0m"; else row="${row}\033[107m \033[0m"; fi; done; echo -e "  |  ${row}  |   |  ${row}  |"; done; echo -e "  +-------+   +-------+"; echo -e "\nStay up till you wake up\nPress Control + C to exit"; done

Enjoy the Animation!
Once executed, stayup will keep your Mac awake while you enjoy the animated ASCII eyes. The synchronized eyes will randomly change their gaze direction and blink at intervals, while the messages at the bottom remind you to stay awake and how to exit.

To Exit:
Simply press Control + C in your Terminal.

Requirements
macOS with the caffeinate command available.
Bash shell (or a compatible shell that supports the syntax used).

Set stayup as a standalone command for quick use

  1. Create the Script File
    Open your Terminal and create a new file named stayup in a directory that's in your PATH (for example, /usr/local/bin):
sudo nano /usr/local/bin/stayup
  1. Paste the One-Liner into the File
    In the text editor that opens, paste the following code:
caffeinate -d -u & pid=$!; trap "kill $pid" EXIT; blink=$(( $(date +%s) + 10 + RANDOM % 21 )); nextdir=$(date +%s); px=$((RANDOM % 3)); py=$((RANDOM % 3)); while sleep 0.5; do now=$(date +%s); if [ $now -ge $nextdir ]; then px=$((RANDOM % 3)); py=$((RANDOM % 3)); nextdir=$((now + 2 + RANDOM % 3)); fi; if [ $now -ge $blink ]; then clear; echo -e "  +-------+   +-------+"; echo -e "  |-------|   |-------|"; echo -e "  |-------|   |-------|"; echo -e "  |-------|   |-------|"; echo -e "  +-------+   +-------+"; echo -e "\nStay up till you wake up\nPress Control + C to exit"; sleep 0.2; blink=$(( $(date +%s) + 10 + RANDOM % 21 )); fi; clear; echo -e "  +-------+   +-------+"; for r in 0 1 2; do row=""; for c in 0 1 2; do if [ $r -eq $py ] && [ $c -eq $px ]; then row="${row}\033[107m\033[30m@\033[0m"; else row="${row}\033[107m \033[0m"; fi; done; echo -e "  |  ${row}  |   |  ${row}  |"; done; echo -e "  +-------+   +-------+"; echo -e "\nStay up till you wake up\nPress Control + C to exit"; done

If you’re using nano, press Ctrl + X, then Y to confirm, and Enter to save the file.

  1. Make the Script Executable
    In Terminal, run:
sudo chmod +x /usr/local/bin/stayup
  1. Run the Command
    Now you can simply type:
stayup

The one-liner will execute, keeping your Mac awake while showing the animated ASCII eyes. To exit, just press Control + C.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment