Skip to content

Instantly share code, notes, and snippets.

@chockenberry
Last active March 4, 2024 23:40
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chockenberry/13c15466417b88e40f23e58df8091dac to your computer and use it in GitHub Desktop.
Save chockenberry/13c15466417b88e40f23e58df8091dac 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 [ -z "$*" ]; then
cat > /tmp/ql.stdin
mime_type=$(file --brief --mime-type /tmp/ql.stdin)
extension=$(grep "$mime_type" /etc/apache2/mime.types | awk '{ print $2 }')
if [ -z $extension ]; then
qlmanage -p /tmp/ql.stdin 2>/dev/null 1>/dev/null
rm /tmp/ql.stdin
else
file=/tmp/ql.$extension
mv /tmp/ql.stdin $file
qlmanage -p $file 2>/dev/null 1>/dev/null
rm $file
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