Skip to content

Instantly share code, notes, and snippets.

@barn
Created April 17, 2013 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save barn/5402075 to your computer and use it in GitHub Desktop.
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.
#!/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