[TxMt] preview in localhost

Allan Odgaard throw-away-1 at macromates.com
Thu Oct 6 10:19:45 UTC 2005


On 06/10/2005, at 11.24, salvo wrote:

> sometimes I test anything (like html page and perl scripts) writing  
> directly on Desktop, first to pass them in the correct localhost  
> web site folders, so I've set Apache to handle also $USER/desktop  
> as localhost directory.
> I try to put in bundle editor, html this line:
>
> open `echo $TM_FILEPATH | sed "s|.*/$USER/Sites/\(.*\)|http:// 
> localhost/~$USER/desktop/\1|"`

You probably want:

    open "`echo $TM_FILEPATH | sed "s|.*/$USER/Desktop/\(.*\)|http:// 
localhost/~$USER/desktop/\1|"`"

Which makes a file path of e.g. /Users/duff/Desktop/test.html into  
http://localhost/~duff/desktop/test.html

You can also use the shells ability to chop off a prefix ($HOME  
points to your home folder), e.g.:
    open "http://localhost/~$USER${TM_FILEPATH#$HOME}"

If you do spell Desktop in different case (lowercase for the URL):
    open "http://localhost/~$USER/desktop${TM_FILEPATH#$HOME/Desktop}"

Btw: instead of opening the URL, you can also set the commands output  
to HTML and then let it redirect to the URL, so you'll view the page  
inside TextMate:
    echo "<meta http-equiv='Refresh' content='0;URL=http://localhost/~ 
$USER${TM_FILEPATH#$HOME}'>"

I recently blogged about both shell variable substitutions and HTML  
output capabilities:
    http://macromates.com/blog/archives/2005/09/28/html-output-for- 
commands/
    http://macromates.com/blog/archives/2005/09/26/shell-variables/




More information about the textmate mailing list