On May 24, 2007, at 8:11 PM, Jay Soffian wrote:
The only work around I can think of is to explicitly set the environment variables inside the "do script" (possibly exporting all the variables to a temporary file and then sourcing that file inside the "do script"). That seems icky for a variety of reasons.
Well, I realize it's bad form to reply to one's own message, but I came up with the following for tcsh users:
================================================== 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` env | grep -v '^TM_' | sed 's/=(.*)/ "\1"/;s/^/setenv /' > $tmpfile
osascript <<EOF tell application "Terminal" activate do script "cd '$TM_PATH'; source $tmpfile; rm -f $tmpfile; clear; pwd" end tell EOF ==================================================
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.
If this seems generally useful, I'll fix it up to determine tcsh vs bash and handle proper escaping. Dunno about how to determine project environment variables though. Maybe something like:
VAR="${VAR:-$VAR}"
which will only set the environment variable to the new value if it's not already set, as least for bash. I don't think lame tcsh has such a convenient construct (yes, I really need to switch shells, been meaning to for years now).
j.