Every time I do some web development there are a few things I need to do:
- Point MAMP to the correct folder and enter password (as I’m serving on port 80)
- Open the folder in Textmate
- Open two tabs in iTerm
- Run livereload in iTerm in that directory
- Run SASS pointing at CSS in a subdirectory, again in iTerm
- Open a tab in Chrome pointing at localhost
Each of these takes a few seconds to remember/type the command. Wouldn’t it be nice to speed things up?
First thing I’ve done is to point MAMP at the ~/activeSite, and never change it. To get content there I’m going to symlink the real directory to there, so I don’t have to mess around with MAMP.
Second thing is to declare a couple of bash functions. I’d recommend putting these into your ~/.bashrc file. Remember to run source ~/.bashrc after editing that file to get the new code to work.
I keep all my websites in ~/website, and all have a subdirectory called media, with subdirectory inside that called css. You’ll need to modify this to work for your set up. To run this, type editsite SITE_DIRECTORY_NAME in bash.
editsite() {
rm ~/activeSite
ln -s ~/websites/$1 ~/activeSite
osascript -e "
tell application \"iTerm\"
tell the first terminal
tell the last session
write text \"cd ~/websites/$1/\"
end tell
end tell
tell the first terminal
launch session \"Default Session\"
tell the last session
write text \"mate ~/websites/$1\"
write text \"cd ~/websites/$1\"
write text \"livereload\"
end tell
end tell
tell the first terminal
launch session \"Default Session\"
tell the last session
write text \"cd ~/websites/$1/media/\"
write text \"sass --style compressed --watch css:css\"
end tell
end tell
end tell
tell application \"Google Chrome\"
set newtab to make new tab at end of tabs of window 1
set URL of newtab to \"http://localhost/\"
activate
tell application \"System Events\" to keystroke "r" using command down # Anyone know how to do command shift down?
end tell"
}
This does pretty much what you’d expect. You could use a docstring instead of this if you wanted, but I’m happy with escaped “s.
This is all well and good, but sometimes I can’t remember what I called the directory, so here’s another function that lets me check, even if I’ve already started typing editsite.
editsites() {
cd ~/websites
ls -d */
}
This just lists the directories in my websites directory.
Any improvements, let me know!