With my Gollum installation and Jekyll powered website, I often commit changes after saving a file. This two-step process can be reduced to a single step by having TextMate commit to git automatically after a file save. This is done by going to “Bundles” in the menubar, going to Bundle Editor > Edit Commands…, creating a new command to save and commit to git, and assigning it a keyboard shortcut.

Here is the command that I use:

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

I set the command to save the “Current File” and input the “Entire Document”. I assigned the key-binding to Commmand+S because I intend on committing almost every file I save. To have the command request a commit message for the commit, this command can be used, which displays a pop up dialog requesting a message:

#!/usr/bin/env ruby
filename = ENV["TM_FILEPATH"].split("/").last

require ENV['TM_SUPPORT_PATH'] + '/lib/ui'
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