In my .bashrc
:
function rnew { $HOME/.dotfiles/railsnewapp.sh $1; }
Essentially, I call rnew
from any directory, and it creates a directory in ~/code/appname
, installs Rails into it, and then I want the pwd
to become ~/code/appname
.
In ~/.dotfiles/railsnewapp.sh
:
#! /bin/bash
appname=$1
appdirectory="$HOME/code/$appname"
if [ -d $appdirectory ]; then
echo $appdirectory already exists. Not creating Rails app $appname.
else
mkdir $appdirectory
cd $appdirectory
if [ `pwd` == $appdirectory ]; then
echo "rvm use 1.8.7@$appname" >> "$appdirectory/.rvmrc"
rvm gemset create $appname
cd ..
rails new $appname -m $HOME/code/config/base_template.rb -T -J
cd $appdirectory
if [ `pwd` == $appdirectory ]; then
git init .
else
echo Could not create git repo in $appdirectory. Could not switch to that directory.
fi
else
echo Could not switch to directory $appdirectory. No creating Rails app $appname.
fi
fi
######## how to switch to $appdirectory here so that
######## when the `rnew` function completes and I'm back at the
######## terminal and the `pwd` is $appdirectory?
Ps. I do not want to do a cd
in rnew
. As you can see in the script, I am making sure that the app is created in the correct directory and other checks related to directory, so I don't think I can call the script from rnew
for a directory that is yet to be created?