-
-
Save bggolding/a28f338f9cca97a1c4c430fda0eb8997 to your computer and use it in GitHub Desktop.
QuickLook for macOS shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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