Skip to content

Instantly share code, notes, and snippets.

@jpouellet
Last active December 28, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpouellet/7541059 to your computer and use it in GitHub Desktop.
Save jpouellet/7541059 to your computer and use it in GitHub Desktop.
Uses OS X's "Quick Look" as a pseudo-pager.
#!/bin/bash
# It'd be nice to allow users to pipe stuff into this and have it displayed.
# I had it working, but then I added the press-any-key-to-close functionality
# because clicking the X was annoying, and that consumes stdin.
#
# Ideally this would cause the window manager to focus on the quicklook window,
# which would be responsable for closing itself, but qlmanage seems to not be
# capable of doing that (at least as of 10.6.8).
#
# Perhaps a solution would be to use osascript to launch quicklook instead of
# going through the command line interface which according to the man page
# (and the title of the resulting quicklook qindow) appears to just be for
# debugging, but that might create issues with correctly returning focus to
# the terminal afterwards.
if [ -z "$*" ]; then
echo "Usage: $(basename "$0") <file> ..." > /dev/stderr
exit
fi
cleanup() {
kill $QL_PID
exit
}
trap cleanup USR1
qlmanage -p "$@" &>/dev/null &
QL_PID=$!
{
read -s -n 1
kill -USR1 $$
} < /dev/stdin &
SUB_PID=$!
wait $QL_PID
kill $SUB_PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment