Settings

Theme

snow_mac

Karma
1,047
Created
15 years ago

About

# Keep the terminal awake by simulating a Shift+Up Arrow key press every 30 seconds # Useful for preventing sleep during long tasks like downloads or builds # Usage: coffee [-m minutes] # -m minutes : run for specified number of minutes, then stop # If no -m option is given, runs indefinitely coffee() { if [ -f ~/.bash_history ]; then sed -i.bak '/^coffee/d' ~/.bash_history fi if [ -f ~/.zsh_history ]; then sed -i.bak '/coffee/d' ~/.zsh_history fi history -d $(history 1 | awk '{print $1}') 2>/dev/null

  local duration=0

  if [[ "$1" == "-m" && -n "$2" ]]; then
    duration=$(($2 * 60))
  fi

  local count=0
  while true; do
    # shift arrow key down
    # osascript -e 'tell application "System Events" to key code 126 using {shift down}'
    # F-13 
    osascript -e 'tell application "System Events" to key code 105'
    sleep 30

    count=$((count + 30))
    if [[ $duration -gt 0 ]]; then
      if [[ $count -ge $duration ]]; then
        break
      fi
    fi

    # Print elapsed time every 60 seconds
    if (( count % 60 == 0 )); then
        echo -ne "\r$((count/60)) minutes elapsed\n"
    fi
  done
}

Recent Submissions

  1. 1. I Asked 4 AI Models to Research the Parasite Cleanse Hype (christiantech.substack.com)
  2. 2. Ask HN: How to stay relevant in the age of AI?
  3. 3. Tech is changing- where are we going? (adambourg.com)
  4. 4. Ask HN: Who's been hired through Hacker News?
  5. 5. Colorado family cleaning up after 6th vehicle in 6 years crashes into property (9news.com)

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection