Skip to content

Instantly share code, notes, and snippets.

@jbr
Created April 7, 2014 22:55
Show Gist options
  • Select an option

  • Save jbr/10071019 to your computer and use it in GitHub Desktop.

Select an option

Save jbr/10071019 to your computer and use it in GitHub Desktop.
function project {
PROJECT_BASE=~/code
PROJECT_FILE=.jbr
if [ "$1" ]; then
PROJECT=$PROJECT_BASE/$1
if [ -d $PROJECT ]; then
touch $PROJECT_BASE/$1
elif [ $1 = "-" ]; then
project `ls -t1 $PROJECT_BASE|head -n2|tail -n1`
elif [ $1 = "list" ]; then
echo
echo "Projects"
echo
ls -t1 $PROJECT_BASE
return 0
elif [ "$1" != "which" ]; then
echo "No project $1"
return 1
fi
fi
PROJECT_DIR=$PROJECT_BASE/`ls -t1 $PROJECT_BASE|head -n1`
if [ -f $PROJECT_DIR/$PROJECT_FILE ]; then
TARGET="$PROJECT_DIR/`cat $PROJECT_DIR/$PROJECT_FILE|head -n1`";
else
TARGET=$PROJECT_DIR;
fi
if [ "$1" = "which" ]; then
echo "${TARGET/$PROJECT_BASE\//}";
else
cd $TARGET;
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment