Skip to content

Instantly share code, notes, and snippets.

@mcasimir
Created May 19, 2012 10:18
Show Gist options
  • Save mcasimir/2730364 to your computer and use it in GitHub Desktop.
Save mcasimir/2730364 to your computer and use it in GitHub Desktop.
Create and open file bundle for Textmate 2
#!/usr/bin/env ruby -wKU
# Create and open file bundle for Textmate 2
# Key equivalent: @N
$: << ENV['TM_SUPPORT_PATH'] + '/lib'
require "ui"
filename = TextMate::UI.request_string(:title => "Create and open file",
:prompt => "Enter the file name",
:button1 => "Create")
if filename
selected_file, project_dir = ENV.values_at('TM_SELECTED_FILE', 'TM_PROJECT_DIRECTORY')
base_dir = selected_file ? (File.directory?(selected_file) ? selected_file : File.dirname(selected_file)) : project_dir
target = File.join(base_dir, filename)
`touch #{target}`
`mate #{target}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment