🔨 Bash - Itermify
Updated at 2017-02-26 14:36
I find a frequeny need to run multiple commands when I start developing a project e.g. start the server, JS code watcher, CSS compression watcher. The following bash function allows starting a new iTerm tab and running a list of commands inside it on Mac OS X.
itermify()
{
osascript \
-e 'activate application "iTerm"' \
-e 'tell application "System Events" to keystroke "t" using command down'
for ARG; do
A='tell application "System Events" to tell process "iTerm" to keystroke '
A+="\"$ARG\""
osascript \
-e 'activate application "iTerm"' \
-e "$A" \
-e 'tell application "System Events" to tell process "iTerm" to key code 52'
done
}
Some usage examples:
# Build and host this website. Opens 2 new terminal tabs.
rukruk()
{
itermify 'cd ~/ruksismith' 'bash unix_build.sh'
itermify 'cd ~/ruksismith' 'bash unix_host.sh'
}
# Running a project with multiple processes in various virtual environments
# required for development. Opens 4 new terminal tabs.
porkpork()
{
itermify 'v pork' 'python manage.py runserver'
itermify 'v pork' 'nvm use 7' 'yarn run watch-webpack'
itermify 'v pork' 'nvm use 7' 'yarn run watch-css'
itermify 'v chops' 'run-agent'
}