[TxMt] Specifying a 'funky' file path

Gavin Kistner gavin at refinery.com
Fri Mar 3 16:18:39 UTC 2006


I am (almost done) writing an HTML output  script for my Lua bundle  
which (among other things) provides TextMate links for syntax error  
codes.

I put one of my files in a path with a space in the name, and it took  
me a fair amount of experimenting to figure out how TextMate and Lua  
independently wanted to see the URL.

The raw path as supplied in the argument list is:
/Users/gavinkistner/Desktop/pork butt/bling/tmp.lua

To pass that to Lua, I needed to escape the space char:
file_path = Pathname.new( ARGV[0].gsub( %r{([^\w/.])}, '\\\\\1' ) )
#=> /Users/gavinkistner/Desktop/pork\ butt/bling/tmp.lua

To create the parameter for the TextMate URL, I needed to NOT have  
that escaping. If I perform HTML escaping (for valid HTML) the space  
may not be represented as a '+' char, but must be a %20.

WORK:
<a href='txmt://open?url=file:///Users/gavinkistner/Desktop/pork butt/ 
orxit.lua&line=6'>
<a href='txmt://open?url=file%3A%2F%2F%2FUsers%2Fgavinkistner% 
2FDesktop%2Fpork%20butt%2Forxit.lua&line=6'>

DON'T WORK:
<a href='txmt://open?url=file:///Users/gavinkistner/Desktop/pork\  
butt/orxit.lua&line=6'>
<a href='txmt://open?url=file%3A%2F%2F%2FUsers%2Fgavinkistner% 
2FDesktop%2Fpork+butt%2Forxit.lua&line=6'>

The Ruby code to create the valid URL param:
htmlpath = CGI.escape( "file://" + File.expand_path( path+file,  
file_dir ).gsub( /\\(.)/, '\\1' ) ).gsub('+','%20')


As a more pathological case, I renamed the folder in Finder to "pork  
\ % / butt"
The "/" in the name is apparently a ":" on the file system:
gavinkistner$ cd pork\ \\\ %\ \:\ butt/
gavinkistner$ pwd
/Users/gavinkistner/Desktop/pork \ % : butt

My code produces:
<a href='txmt://open?url=file%3A%2F%2F%2FUsers%2Fgavinkistner% 
2FDesktop%2Fpork%20%5C%20%25%20%3A%20butt%2Forxit.lua&line=6'>
and it works. Yay! :)





More information about the textmate mailing list