Skip to content

Instantly share code, notes, and snippets.

@avalanche123
Created December 9, 2014 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avalanche123/619a70d72d3c5b8b2d8d to your computer and use it in GitHub Desktop.
Save avalanche123/619a70d72d3c5b8b2d8d to your computer and use it in GitHub Desktop.
TextMate2 CopyWithStyle action
#!/bin/bash
source "$TM_SUPPORT_PATH/lib/bash_init.sh" # might not be necessary
read -r -d '' code <<-'EOF'
require "jcode" if RUBY_VERSION < '1.9'
app_path = ENV["TM_SUPPORT_PATH"]
require "#{app_path}/../../../TextMate.tmbundle/Support/lib/doctohtml.rb"
require "#{app_path}/lib/progress.rb"
unit = ENV.has_key?('TM_SELECTED_TEXT') ? 'selection' : 'document'
TextMate.call_with_progress(:message => "Creating HTML version of #{unit}...") do
print document_to_html( STDIN.read, :include_css => true )
end
EOF
ruby18 -e "$code" | textutil -format html -convert rtf -stdin -stdout | pbcopy
echo 'Done!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment