06.09.06
Global TextMate Bookmarking
Inspired by a recent discussion on the TextMate list, I was inspired to create a “proof of concept” set of “global bookmarking” commands for TextMate. There are three commands in this set. The first one saves a bookmark to the current line on a global file, which I have named /Users/haris/testing.magic, but which you will probably have to rename (in all three bundles), unless you have done me the honor of using my name for your computer user’s name. Here is the code of the “save bookmark” command:
#!/usr/bin/env ruby
filename = "/Users/haris/testing.magic"
currentFile = ENV['TM_FILEPATH'].to_s
line = ENV['TM_LINE_NUMBER'].to_s
link = "txmt://open?url=file://#{File.expand_path(currentFile)}&line=#{line}"
File.open(filename, "a") do |f|
f.puts link
end
Set its input to nothing, its output to discard, and you are good to go.
The second command takes you to the last bookmark. It’s code is:
#!/bin/sh
filename="/Users/haris/testing.magic"
lastlink=`tail -n1 $filename`
open $lastlink
with the same input and output as the previous one. The third command offers you a list of all bookmarks, so that you can click on them. Currently the output is not pretty but anyway:
#!/usr/bin/env ruby
filename = "/Users/haris/testing.magic"
links = []
File.open(filename, "r") do |f|
links = f.readlines
end
puts "<div><ul>"
for link in links do
a = link.chomp
puts "<li><a href=\"#{a}\">#{a}</a></li>"
puts "</ul></div>"
end
Set its output to HTML and its input to nothing.
There you have it! Global TextMate bookmarking, plain and simple! Arguably a bit too global, but it’s a start. You might want to also create a command to clear the bookmarks, and work harder for project specific bookmarks.
Later