So I happened to notice that when I use the Shell Script bundles "Open Terminal" that my project environment variables don't appear.
According to this tech note:
http://developer.apple.com/technotes/tn2002/tn2065.html
osascript (which is what the "Open Terminal" command uses to tell Terminal.app to open a window) passes its environment along, which contains the project variables.
Is this a limitation of using "do script" instead of "do shell script"?
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.
Thoughts?
j.
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.
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.