[TxMt] Re: open terminal and environment

Jay Soffian jay-txmt at soffian.org
Fri May 25 01:01:51 UTC 2007


On May 24, 2007, at 8:50 PM, Jay Soffian wrote:

> Not perfect as it slams everything into the environment, not just  
> the project variables; As well, its escaping of the environment  
> variable values is naive. And it assumes tcsh. But it's a start.

Final (sure...) version attached with aforementioned items resolved.

============================================
if [[ -d $TM_SELECTED_FILE ]]; then
    TM_PATH="$TM_SELECTED_FILE"
elif [[ -f $TM_SELECTED_FILE ]]; then
    TM_PATH="`dirname "$TM_SELECTED_FILE"`"
else
    TM_PATH="`dirname "$TM_FILEPATH"`"
fi

tmpfile=`mktemp -t tmvars`
case $SHELL in
   */tcsh)
     env | grep -v '^TM_' \
     | sed 's/\([^A-Za-z0-9_=]\)/\\\1/g; s/\([^=]*\)=\(.*\)/if (! $? 
\1) setenv \1 \2/' \
     > $tmpfile
     ;;
   */bash)
     env | grep -v '^TM_' \
     | sed 's/\([^A-Za-z0-9_=]\)/\\\1/g; s/\([^=]*\)=\(.*\)/ 
[[ "\1" ]] || export \1=\2/' \
     > $tmpfile
     ;;
   *)
     > $tmpfile
     ;;
esac

osascript <<EOF
    tell application "Terminal"
       activate
       do script "cd '$TM_PATH'; source $tmpfile; rm -f $tmpfile;  
clear; pwd"
    end tell
EOF
============================================

zsh users might wish to confirm that the bash syntax works (I think  
it does...) and then modify the case statement to suit.

Thoughts?

j.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Open Terminal.tmCommand
Type: application/octet-stream
Size: 1358 bytes
Desc: not available
URL: <http://lists.macromates.com/textmate/attachments/20070524/f75658c5/attachment.tmCommand>


More information about the textmate mailing list