Skip to content

Instantly share code, notes, and snippets.

@bggolding
Forked from chockenberry/ql.sh
Last active July 26, 2022 05:13
Show Gist options
  • Save bggolding/a28f338f9cca97a1c4c430fda0eb8997 to your computer and use it in GitHub Desktop.
Save bggolding/a28f338f9cca97a1c4c430fda0eb8997 to your computer and use it in GitHub Desktop.
QuickLook for macOS shell
#!/bin/sh
# usage:
# ql /tmp/file.jpg
# cat /tmp/file.jpg | ql
# cal -h | ql
if [ $# = 0 ]; then
TMP="/tmp/ql.$$.stdin"
trap 'rm -rf "$TMP" "$TEMP"' 0 1 2 15
cat >"$TMP"
mime_type=$(file --brief --mime-type "$TMP")
extension=$(grep "$mime_type" /etc/apache2/mime.types | awk '{print $2;}')
if [ -z $extension ]; then
qlmanage -p "$TMP" 1>/dev/null 2>&1
else
FILE="/tmp/ql.$$.$extension"
mv /tmp/ql.stdin "$FILE"
qlmanage -p "$FILE" 1>/dev/null 1>&2
fi
else
qlmanage -p "$@" 2>/dev/null 1>/dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment