Last active
March 4, 2024 23:40
-
-
Save chockenberry/13c15466417b88e40f23e58df8091dac 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 [ -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