Created
April 17, 2013 05:55
-
-
Save barn/5402075 to your computer and use it in GitHub Desktop.
Add this to your muttrc to enable OSX quicklook of files in the attach menu in mutt. That's right, view shit with the spacebar! Requires, I imagine, ruby 1.9.x as your ruby. Not tested on 1.8.7, but presumed not to work.
This file contains hidden or 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
#!/usr/bin/env ruby | |
# | |
# Put something god awful in your muttrc like: | |
# macro attach <space> "<enter-command>unset wait_key<enter><shell-escape>rm -f $HOME/.quicky<enter><save-entry><kill-line>$HOME/.quicky<enter><shell-escape>quicky.rb $HOME/.quicky<enter><enter-command>set wait_key<enter>" "Open with quicklook" | |
# | |
require 'tmpdir' | |
if ARGV.empty? | |
puts "need a filename" | |
exit 1 | |
end | |
file = ARGV[0] | |
if ! File.exists? file | |
puts "Canny find #{file}" | |
exit 2 | |
end | |
sowhatisit = %x{ file -I "#{file}" }.chomp | |
# Now regexp out: | |
# .quicky: text/html; charset=us-ascii | |
# Desktop/Screen Shot 2013-03-24 at 21.32.57.png: image/png; charset=binary | |
regex = /(?<filename>[\w\/\.-]+):\s(?<class>\w+)\/(?<type>\w+);\scharset=(?<charset>[\w\-]+)/ | |
m = sowhatisit.match regex | |
# lazy? | |
if m.nil? | |
# This probably means the filename has something weird in it. | |
require 'rubygems' | |
require 'awesome_print' | |
ap sowhatisit | |
raise | |
end | |
Dir.mktmpdir do |dir| | |
newfilename = "#{dir}/#{File.basename file}.#{m[:type]}" | |
# use the directory... | |
FileUtils.cp file, newfilename | |
system %{qlmanage -p "#{newfilename}" >/dev/null} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment