# simple shortcuts
export MY_DEV_PATH=~/development
export MY_EDITOR=mate
edbp () {
ed $MY_DEV_PATH/bash-profile;
}
reload () {
# Forces a reload of both the .bashrc and .profile files in the current bash session
source ~/.bashrc;
source ~/.profile;
echo '.bashrc and .profile reloaded!';
}
ed () {
if [ "$#" -lt 1 ]; then
echo "Usage: ed \"editor args + directory or filename\""
return;
fi
$MY_EDITOR $*;
}
#-----------------------------------------------------> RAILS DEV
export DEV_RAILS=$MY_DEV_PATH/rails;
cdr (){
cd $DEV_RAILS/$1;
}
# ls rails apps or give path in the rails directory
lsr (){
ls -l $DEV_RAILS/$1;
}
# Rails run server
rss (){
if [ "$#" -lt 0 ]; then
# just run script/server on local directory
./script/server
else
cd $DEV_RAILS/$1
./script/server
fi
}
edr(){
if [ "$#" -lt 1 ]; then
echo "Usage: edr rails-app";
echo "This launches the rails app supplied in your favorite editor."
return;
fi
cd $DEV_RAILS/$1
ed .
}
#-----------------------------------------------------> FLASH DEV
export DEV_FLASH=$MY_DEV_PATH/flash;
cdfl (){
cd $DEV_FLASH/$1;
}
edfl (){
if [ "$#" -lt 1 ]; then
echo "Usage: edfl \"flash app name\""
return;
fi
if [ -d $DEV_FLASH/$1 ]; then
open -ga "Adobe Flash CS4" $DEV_FLASH/$1/$1".fla";
ed $DEV_FLASH/$1;
else
echo $1 "does not exist in " $DEV_FLASH;
return;
fi
}
lsfl () {
ls -l $DEV_FLASH;
}
#-----------------------------------------------------> PYTHON Functions and Overrides
export IPYTHON_PATH=/usr/local/bin/ipython;
export LOCAL_PYTHON_PATH=~/python;
export LOCAL_PYTHON_SRC_PATH=$LOCAL_PYTHON_PATH/src;
export LOCAL_PYTHON_SITE_PACKAGES=$LOCAL_PYTHON_PATH/site-packages;
py () {
if command -v ipython >/dev/null; then
ipython $*;
else
echo "ipython is not installed using default python shell";
ppy;
fi
}
ppy () { python $*; }
#override ipython for faster launch & exits
ipython () {
$IPYTHON_PATH -noconfirm -nobanner $*;
}
cdpys () {
cd $LOCAL_PYTHON_SRC_PATH;
}
lslsp () {
ls -l $LOCAL_PYTHON_SITE_PACKAGES;
}
#-----------------------------------------------------> django Environment Variables
export DJANGO_APP_PREFIX="django-";
export DEV_DJANGO=$MY_DEV_PATH/django;
export DEV_DJANGO_APPS=$DEV_DJANGO/apps;
export DEV_DJANGO_SITES=$DEV_DJANGO/sites;
dj () {
# list all django commands here incase i forget them :)
echo "=== DJANGO COMMANDS ========================";
echo ""
echo "=== DJANGO SITES ========================";
echo ""
echo "=== DJANGO APPS ========================";
}
#django dev
cddj () { cd $DEV_DJANGO/$*;}
#django runserver
drs () { ./manage.py runserver $*; }
#django shellplus requires django_extensions
dsh () {
./manage.py shell_plus || (echo "Using Default Django shell instead!" && dshb);
}
dshb () {
./manage.py shell;
}
dsdb () { ./manage.py syncdb; }
dre () {
if [ "$#" -lt 1 ]; then
echo "Usage: djre \"django app name\""
return;
fi
./manage.py reset $1;
}
# django app functions
cdda () { cd $DEV_DJANGO_APPS/$*; }
lsda () { ls $* $DEV_DJANGO_APPS; }
edda () {
if [ "$#" -lt 1 ]; then
echo "Usage: edda django-app app";
echo "This launches each django app supplied as arguments in your favorite editor."
return;
fi
for a in $*; do
if [ -d $DEV_DJANGO_APPS/$DJANGO_APP_PREFIX$a ]; then
ed $DEV_DJANGO_APPS/$DJANGO_APP_PREFIX$a;
elif [ -d $DEV_DJANGO_APPS/$a ]; then
# old not migrated apps
# TODO remove once all apps have been ported
ed $DEV_DJANGO_APPS/$a;
else
echo "neither '"$DJANGO_APP_PREFIX$a "' or '" $a "' exist in " $DEV_DJANGO_APPS;
fi
done
}
mkda () {
if [ "$#" -lt 1 ]; then
echo "Usage: djmka \"django app name\""
return;
fi
# define path
new_app_path=$DEV_DJANGO_APPS/$DJANGO_APP_PREFIX$1;
if [ -d $new_app_path ]; then
echo $DJANGO_APP_PREFIX$1 " already exists";
fi
# TODO add python import test against existing apps on pythonpath
# make default folders
mkdir -p $new_app_path"/examples" $new_app_path"/docs" $new_app_path"/tests";
pushd $new_app_path;
# create default files
touch AUTHORS && echo "django-"$1" == TODO" > AUTHORS;
touch README && echo "django-"$1" == TODO" > README;
touch INSTALL && echo "django-"$1" == TODO" > INSTALL;
touch setup.py && echo "django-"$1" == TODO" > setup.py;
touch LICENSE && echo "django-"$1" == TODO" > LICENSE;
# create app
django-admin.py startapp $1;
# setup initial repo
git init -q && git add . && git commit -q -m "Initial Commit";
# add app to python path requires pylink/plink
pylink $1 $1;
popd;
}
rmda () {
if [ "$#" -lt 1 ]; then
echo "Usage: rmda \"django app name\" e.g. rmda people";
echo -n "This will remove '"$DJANGO_APP_PREFIX"people' from the django app folder";
echo " and the symlink from site-packages.";
return;
fi
# check to see if app exists with or without django-prefix
if [ -d $DEV_DJANGO_APPS/$DJANGO_APP_PREFIX$1 ]; then
apppath=$DEV_DJANGO_APPS/$DJANGO_APP_PREFIX$1;
elif [ -d $DEV_DJANGO_APPS/$1 ]; then
# old not migrated apps
# TODO remove once all apps have been ported
apppath=$DEV_DJANGO_APPS/$1;
else
echo "neither '"$DJANGO_APP_PREFIX$1 "' or '" $1 "' exist in " $DEV_DJANGO_APPS;
return;
fi
# ask for confirmation
echo "Are you sure you wish to delete django app: ";
echo ">> $apppath";
echo -n "Yes/No? ";
read answer;
answer="`echo $answer|tr '[:upper:]' '[:lower:]'`";
if [ "$answer" = "yes" ] || [ "$answer" = "y" ]; then
# unlink from python path
pyunlink $1;
# recursively delete app from django apps folder
rm -rfv $apppath;
echo "Django App '$apppath' successfully removed"
return;
elif [ "$answer" = "no" ] || [ "$answer" = "n" ]; then
echo "Remove django App $apppath stopped";
return;
else
echo "Nothing happend Incorrect answer";
fi
}
cdds () { cd $DEV_DJANGO_SITES/$*; }
lsds () { ls $* $DEV_DJANGO_SITES; }
edds () {
if [ "$#" -lt 1 ]; then
echo "Usage: edds \"django site name\" e.g. edds newspaper.com"
echo ">> This changes to the selected folder and launches it in your favorite editor 'Textmate'"
return;
fi
cd $DEV_DJANGO_SITES/$1;
ed .;
}
mkds () {
if [ "$#" -lt 1 ]; then
echo "Usage: mkds \"django project name\""
return;
fi
pushd $DEV_DJANGO_SITES;
django-admin.py startproject $1;
popd;
}