[TxMt] How to execute a shell script within TextMate?

Marius Hofert m_hofert at web.de
Wed May 5 11:27:20 UTC 2010


Dear TextMate experts,

I would like to execute the shell script myscript.sh from within TextMate. The script myscript.sh takes a file name as argument and does something with the file (it indents the file correctly; for this, it calls emacs in batch mode). So if I use 
sh myscript.sh myfile.R
the script works perfectly fine, i.e., it indents the source code contained in myfile.R. I would like to have textmate do this for me on the file I am working on when I use a certain key combination. 

Using the Bundle Editor, I created a new command "tidy" with key equivalent "shift+command+T". As the actual command, I put in:
sh /path_to_my_script/myscript.sh "$TM_FILENAME"

Unfortunately, this does not work. I set "Input" to "Entire Document" and "Output" to "Replace Document" (currently I obtain an empty document after "shift+command+T"). 

How can I trigger the shell script, such that the current content of myfile.R is replaced by the (quietly generated) output of myscript.sh?

Below is the script

Many thanks in advance,

Marius


#!/bin/sh
function usage () {
printf "Indent R file with Emacs ESS package.\n"
printf "Usage: $0 FILE\n"
exit 1
}
f=$1
shift
if test "x$f" = x -o "x$f" = "x-h"; then
usage
fi
emacs -batch \
-eval '(load "/usr/local/share/emacs/site-lisp/ess-5.8/lisp/ess-site")' \
-f R-mode \
-eval '(untabify (point-min) (point-max))' \
-eval '(insert-file "'${f}'")' \
-eval '(set-visited-file-name "'"${f}"'")' \
-eval '(indent-region (point-min) (point-max) nil)' \
-f save-buffer \
2>/dev/null




More information about the textmate mailing list