I have a website that has certain JavaScript code snippets, such as Google Analytics, that need to be present only in the production environment and not the development environment. I needed an easy way to keep this separation, regardless of framework or lack of one. I wrote the repta tool to perform a global search and replace of a “tag” across all the project files as one of the steps during the deployment of the website. Check out the project page.
Repta Project Released
July 12th, 2009A ‘cd’ Command for Git Projects
January 20th, 2009I often find myself in a project directory and one of two things usually happens. The first is that I would like to go directly to the top level directory of the project. The second is that I would like to go outside of the project directory and get back very quickly. Though not sophisticated, I came up with this simple shell script called cd-to-project-root.
#!/bin/sh pushd . > /dev/null until [ -d .git ] || [ `pwd` = '/' ]; do cd ..; done if [ `pwd` = '/' ]; then # try to go to a project directory if [ -z $PREV_PROJECT_ROOT ]; then popd > /dev/null echo "Project directory not found."; else cd $PREV_PROJECT_ROOT fi else # at a project directory export PREV_PROJECT_ROOT=`pwd` fi
I saved this in my “~/bin” directory and made an alias to it called cdp. It’s important to source the script, otherwise the shell variables will not retain their values when the script terminates.
alias cdp=". cd-to-project-root"
This allows me to type cdp to set the project directory, which is under git version control. Anytime I want to get back to the project directory, I type cdp.