This is a lazy request.
Hoping towards moving more of my information into text files, I would like a way of directly launching resources from URLs in a text file. Imagine that I copy a bit of email that includes a web URL or a mailto link to an inbox.txt file. When I go through inbox.txt, I would like to just hit a key combination when the cursor is on the URL and have it send to my browser or my mail program.
emacs-wiki/planner does this well (it even highlights clickable URLs). Outside TextMate, one can also use ICeCoffEE (http://web.sabi.net/nriley/software/), but that doesn't work in TextMate.
So, how hard would it be for someone to write a command thingy to make such functionality available in TextMate? I suppose one would have to identify the beginning and end of the URL that the cursor is on and send it to the system's "open" command. I don't have the time to investigate this myself.
-- Kai (http://semantics-online.org/geek)
On May 23, 2005, at 14:51, Kai von Fintel wrote:
So, how hard would it be for someone to write a command thingy to make such functionality available in TextMate?
Should be pretty easy.
You have TM_COLUMN_NUMBER as the caret position and TM_CURRENT_LINE as the contents of the current line.
Slapping together something quick in bash yeilds:
for (( i = $TM_COLUMN_NUMBER-1; i >= 0; i-- )); do res=$(perl -pe <<<${TM_CURRENT_LINE:$i} 's/^(((https?|ftp|mailto): \S+?)(?=[),.]*(\s|$)|$)|).*/$1/') if [[ -n $res ]]; then open "$res" break fi done
This will find the first URL (using a rather primitive regex) to the left of the caret. It's rather slow though.
If you're using this in plain text you can put something like this in the Plain text.plist to get these highlighted: { name = "markup.underline.link"; match = "(https?|ftp|mailto):\S+?(?=[),.]*(\s|$)|$)"; },
If you're running recent betas then you can also put “markup.underline.link” in the scope of the command, so that the key equivalent will only fire when actually on an URL (which allows you to select a key that'd normally be used for something else).
[...] I don't have the time to investigate this myself.
In that case you should put up a bounty for those whiling to spend their time solving your problems! ;)
When I go through inbox.txt, I would like to just hit a key combination when the cursor is on the URL and have it send to my browser or my mail program.
I couldn't resist the challenge of trying to hack this during a meeting.
Save: Nothing. Command:
perl -e '$line=$ENV{"TM_CURRENT_LINE"};$col=$ENV{"TM_COLUMN_NUMBER"}; $a=substr($line,0,$col);substr($line,0,$col)="";$a=reverse$a;$a=~/ (.*?)\s/g;$url1=$1;$url1=$a unless($url1);$url1=reverse$url1;$line=~/ (.*?)\s/g;$url2=$1;$url2=$line unless($url1);print"$url1$url2";' | xargs open
Input: Selected Text Output: Discard
Works for me, but requires a full URL, so http://google.com works, but not google.com. If there's interest it could be easily tweaked to add 'auto http://'...
best, Eric --- Eric Hsu, Assistant Professor of Mathematics San Francisco State University erichsu@math.sfsu.edu http://math.sfsu.edu/hsu