Skip to content

Instantly share code, notes, and snippets.

@markusfisch
Last active April 8, 2020 00:06
Show Gist options
  • Save markusfisch/0e16b603dfc9096433b7c8313fc9f5fc to your computer and use it in GitHub Desktop.
Save markusfisch/0e16b603dfc9096433b7c8313fc9f5fc to your computer and use it in GitHub Desktop.
Play nethack while you wait for some process (like a looong build)

Play nethack while you wait for some process

Like a looong build.

Prerequisites

Obviousely you need to have nethack.

Less obviousely, you also need tmux because I use tmux. Sorry ;)

Usage

Just put play-nethack-while somewhere in your PATH and make it executable ($ chmod a+x /usr/local/bin/play-nethack-while).

Then, when you're about to start that dull, long running process that makes you think of Maud, do:

$ play-nethack-while make release

If nethack is already running in your tmux session, play-nethack-while will now just switch to this window. If not, nethack will be started in a new window.

As soon as the long running process has finished, play-nethack-while will automatically switch back to the last used window (what's supposed to be the one you started the long running process in) and you can resume with whatever you need to do.

#!/usr/bin/env bash
[ "$TMUX" ] || exit $?
LOG="/tmp/${0##*/}.$$"
"$@" &> "$LOG" &
PID=$!
WINDOW=$(tmux lsw | grep -F nethack | cut -d ':' -f 1)
if ((WINDOW))
then
tmux selectw -t "$WINDOW"
else
tmux neww nethack
fi
wait "$PID"
tmux last
cat "$LOG"
rm -f "$LOG"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment