Exactly how is your development environment configured?

Exactly how is your development environment configured? I solved this problem with a simple script....

Object Partners

Along with Grails we are seeing a resurgence of the shell and the command line. And if there is anything experienced unix users hate, it’s asking a newbie how their environment is configured and getting a blank stare in return. Well I solved this problem years ago with a simple shell script — it’s time to resurrect printconfig. A call to printconfig shows the path and a subset of the shell’s environment variables. For example:

yaal.local[525]> printconfig
HOME		/Users/amiller
ANT_HOME	/Users/amiller/devtools/ant/current -> ant-1.7.1
CATALINA_HOME	/Users/amiller/devtools/tomcat/current -> tomcat-6.0.16
EMACS_HOME	/Users/amiller/devtools/emacs/carbon-emacs-22.3.1_2009.07.25.app
GRAILS_HOME	/Users/amiller/devtools/grails/current -> grails-1.2.0
GROOVY_HOME	/Users/amiller/devtools/groovy/current -> groovy-1.6.7
IVY_HOME	/Users/amiller/devtools/ivy/current -> ivy-2.1.0
JAVA_HOME	/Users/amiller/devtools/jdk/current -> jdk-1.6.0
JBOSS_HOME	/Users/amiller/devtools/jboss-4.0.5
MAVEN_HOME	/Users/amiller/devtools/maven/current -> maven-2.0.9
TOMCAT_HOME	/Users/amiller/devtools/tomcat/current -> tomcat-6.0.16
ANT_OPTS	-Xmx128m
JAVA_OPTS	-Xmx512m
MAVEN_OPTS	-Xmx2100m -Xms512m
PATH=.
     /Users/amiller/bin
     /Users/amiller/devtools/ant/current/bin
     /Users/amiller/devtools/emacs/carbon-emacs-22.3.1_2009.07.25.app/bin
     /Users/amiller/devtools/grails/current/bin
     /Users/amiller/devtools/groovy/current/bin
     /Users/amiller/devtools/jdk/current/bin
  ...

(See my post on Fast path switching between projects for an explanation of the “current” path elements.)

Call printconfig from the last line in your .profile and your new user shells will always show the environment as it is configured. Try it next time you’re debugging a shell’s environment and let me know what you think.

The printconfig script:

#!/bin/sh
#
\# Echo some config info at shell startup time
\# (useful when debugging the shell environment.)
#
\# Preserve the intentionally HARD_TABS when editing!
#
echo "HOME		$HOME"  

for home_var in `printenv | grep _HOME | sort`; do
    home_var_name=`echo $home_var | awk -F= '{ print $1 }'`
    home_var_value=`echo $home_var | awk -F= '{ print $2 }'`
    if [ -h $home_var_value ]; then
        # echo out what symbolic links are pointing to...
        echo "$home_var_name	`ls -l $home_var_value | awk '{ printf "%s -> %sn", $9, $11 }'`"
        #                   ^ hard tab
    else
        echo "$home_var_name	$home_var_value"
        #                   ^ hard tab
    fi
done  

printenv | grep _OPTS | sort | sed 's/=/	/'
\#                                       ^ hard tab  

echo "PATH=$PATH" | sed 's/:/
     /g'

Share this Post

Related Blog Posts

JVM

Fast path switching between projects

December 29th, 2009

Really fast and easy to try different versions of things that are wired into the command line path. For example, switching grails versions is as simple as...

Object Partners
JVM

Simplifying JPA Testing with Springs PersistenceUnitPostProcessor

December 11th, 2009

At my current client, we are writing an application that is deployed as an ear into Websphere. One of the goals of the project is to write out-of-container tests so that we dont have to build and deploy over and over again. Two of the tools we are using in this application is JPA for the ORM and Spring. Initially, we had two persistance.xml files, one for production and one for testing. Some of the differences were that the production version used a transaction type of JTA and the test version used resource local. There were a few other property differences, but otherwise they needed to be identical. At first this was ok, but as our list of classes and properties grew it became a maintenance hassle.

Object Partners
JVM

Write Readable Tests with Mockito

December 4th, 2009

A good mocking framework is a must have in any Java developers toolset. Mocking frameworks greatly reduce the amount of code needed to effectively mock dependent interfaces and/or classes. Over the past several years EasyMock has been my mocking…

David Reines

About the author