3

The one feature that has kept me an Eclipse user is that each time you hit save, a copy of it goes into the Eclipse local history. Then you can do a diff on local history.

Still, I'd like to use Textmate since I heard such great things about it. I know there's a feature request for a future version...but I'm wondering if someone has found a plugin, or some other way to get this functionality shoehorned into Textmate now? I know it's a longshot but never hurts to ask.

Thank you.

UPDATE! (Edited the title of the question since the previous title got no interest) I just realized that perhaps this can be a solution. Is it possible to hook the Textmate save into a git commit?

joedevon
  • 2,649
  • 4
  • 28
  • 43
  • 1
    How do you save in TextMate? One possible hack solution is to write a bundle entry that saves the file then does the commit, and then re-bind command-s to this bundle entry. But if you use File > Save to save, then this won't do you any good...if this might be helpful, lmk, and I'll write it up as an answer. – Josh Bleecher Snyder Dec 05 '10 at 19:02
  • Thanks Josh, that would be awesome! – joedevon Dec 06 '10 at 23:46
  • See also [Making git auto-commit](http://stackoverflow.com/questions/420143/making-git-auto-commit) – Robin Green Jul 05 '11 at 08:19

1 Answers1

6

What you want is this: Create a new command, set "Save" to "Current File" (this option is above the text area), "Input" to "Entire Document" and "Output" to "Show as Tool Tip". Now copy the code below into the text area and assign Command-S as the commands key-binding.

#!/usr/bin/env ruby
filename = ENV["TM_FILEPATH"].split("/").last
`git add #{ENV["TM_FILEPATH"]}`
`git commit -m "#{filename}"`

Every time you type in Command-S the file will be saved and committed to an (already existing) git repository. If the file wasn't changed, no commit will be done, because git will block the commit.

Below I have extended the command to pop up a dialog for the commit message and to give a nice warning, if no git repository was found. You should be able to figure out the rest yourself. :)

#!/usr/bin/env ruby
require ENV['TM_SUPPORT_PATH'] + '/lib/ui'

filename = ENV["TM_FILEPATH"].split("/").last
message = TextMate::UI.request_string(
    :title => "Commiting changes of #{filename}",
    :prompt => "Please enter the commit message for your changes."
)

add = `git add #{ENV["TM_FILEPATH"]} 2>&1`
commit = `git commit -m "#{message}" 2>&1`

git_answer = add + commit
unless git_answer.grep(/fatal/).empty?
  puts "Please initialize git repository first!"
end
Florian Pilz
  • 8,002
  • 4
  • 22
  • 30
  • @joedevon Is git in you $PATH-variable? (Try "echo $PATH" in a terminal.) If yes, is it loaded for all programs, i.e. not in some login-hook like the .login file? (TextMate won't use that file.) – Florian Pilz Jan 28 '11 at 07:33
  • forgot to mention I did get git into the $PATH and it's working perfectly, now adding your popup to Command-S and the non popup to Command-Shift-S. – joedevon Dec 05 '11 at 22:25