Skip to content

Instantly share code, notes, and snippets.

@voostindie
Created August 22, 2014 16:04
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 voostindie/4d57d7b7729431026a32 to your computer and use it in GitHub Desktop.
Save voostindie/4d57d7b7729431026a32 to your computer and use it in GitHub Desktop.
TextMate 2 command to rename the current file in place, using a shortcut (Ctrl + Cmd + R)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -wKU
require "#{ENV['TM_SUPPORT_PATH']}/lib/ui"
require "#{ENV['TM_SUPPORT_PATH']}/lib/textmate"
filename = TextMate::UI.request_string(
:title =&gt; "Rename File",
:prompt =&gt; "To:",
:default =&gt; ENV["TM_FILENAME"]
)
exit if filename == nil
filepath = ENV["TM_FILEPATH"].gsub(ENV["TM_FILENAME"], filename)
File.rename(ENV["TM_FILEPATH"], filepath)
TextMate.rescan_project
TextMate.go_to :file =&gt; filepath</string>
<key>input</key>
<string>none</string>
<key>inputFormat</key>
<string>text</string>
<key>keyEquivalent</key>
<string>^@r</string>
<key>name</key>
<string>Rename file</string>
<key>outputCaret</key>
<string>afterOutput</string>
<key>outputFormat</key>
<string>text</string>
<key>outputLocation</key>
<string>discard</string>
<key>uuid</key>
<string>70EBE8F1-50FF-4C67-B379-9F5B71A2266E</string>
<key>version</key>
<integer>2</integer>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment