Skip to content
Browse files

Minor change in ssh copy command and added rails_dev.sh to quickly st…

…art Rails development environments on OSX
  • Loading branch information...
1 parent 3513c21 commit 19cade8a22b4bc5531e1054d0534034a592dbc34 @sborsje sborsje committed Aug 1, 2009
Showing with 98 additions and 23 deletions.
  1. +1 −0 .gitignore
  2. +5 −2 files/.bashrc
  3. +0 −21 files/.dotfiles_lib/bash/project_aliases.sh
  4. +92 −0 files/.dotfiles_lib/bin/rails_dev.sh
View
1 .gitignore
@@ -1,2 +1,3 @@
files/.vim/tmp/backup
files/.vim/tmp/swap
+files/.vim/.netrwhist
View
7 files/.bashrc
@@ -97,9 +97,9 @@ alias rdm='rake db:migrate'
alias rdmt='rake db:migrate RAILS_ENV=test'
# SSH
-if [ -f '~/.ssh/id_rsa.pub' ]; then
+if [ -f "$HOME/.ssh/id_rsa.pub" ]; then
function add_ssh_key_to_host {
- cat ~/.ssh/id_rsa.pub | ssh $1 'cat >> ~/.ssh/authorized_keys'
+ cat $HOME/.ssh/id_rsa.pub | ssh $1 'cat >> ~/.ssh/authorized_keys'
}
fi
@@ -172,6 +172,9 @@ for PARENT_DIR in ${PROJECT_PARENT_DIRS[@]} ; do
fi
if [ -d "$PARENT_DIR/$PROJECT_DIR" ]; then
alias "$PROJECT_DIR"="cd $PARENT_DIR/$PROJECT_DIR"
+ if [ -f "$PARENT_DIR/$PROJECT_DIR/config/boot.rb" ]; then
+ alias "dev$PROJECT_DIR"="rails_dev.sh $PARENT_DIR/$PROJECT_DIR"
+ fi
fi
done
fi
View
21 files/.dotfiles_lib/bash/project_aliases.sh
@@ -1,21 +0,0 @@
-# In ~/.bash_profile define a PROJECT_PARENT_DIRS array and source this script. e.g.
-# PROJECT_PARENT_DIRS[0]="$HOME/src"
-# PROJECT_PARENT_DIRS[1]="$HOME/work"
-# source ~/.project_aliases.sh
-
-if [ -z "${PROJECT_PARENT_DIRS[*]}" ]; then
- echo "Define a PROJECT_PARENT_DIRS array in ~/.bash_profile"
-fi
-
-for PARENT_DIR in ${PROJECT_PARENT_DIRS[@]} ; do
- if [ -d "$PARENT_DIR" ]; then
- for PROJECT_DIR in $(/bin/ls $PARENT_DIR); do
- if [ ! -z `which $PROJECT_DIR` ]; then
- continue # don't set alias if there is something already a command on the path with the same name
- fi
- if [ -d "$PARENT_DIR/$PROJECT_DIR" ]; then
- alias "$PROJECT_DIR"="cd $PARENT_DIR/$PROJECT_DIR"
- fi
- done
- fi
-done
View
92 files/.dotfiles_lib/bin/rails_dev.sh
@@ -0,0 +1,92 @@
+#!/bin/sh
+#
+# Bash/AppleScript to automagically setup Rails development environment.
+# This script opens a terminal windows, maximizes it and opens 4 tabs with:
+# - autospec
+# - tail -f development.log
+# - script/console
+# - mvim in the project folder
+#
+# Run this script with the project path as argument, ea:
+# rails_dev.sh ~/Work/project
+
+# check args
+case "$#" in
+ 1)
+ if [ ! -d $1 ]
+ then
+ echo "ERROR: $1 is not a valid directory"
+ exit 0
+ fi
+
+ if [ ! -f "$1/config/boot.rb" ]
+ then
+ echo "ERROR: $1 is not a valid Rails directory (config/boot.rb missing)"
+ exit 0
+ fi
+
+ arg="$(cd $1; pwd -P)";export arg
+ ;;
+ *)
+ echo "Usage: $0 <rails project dir>" >&2
+ exit 2
+ ;;
+esac
+
+# redirect stdin
+exec <"$0" || exit
+
+# find the start of the AppleScript
+found=0
+while read v; do
+ case "$v" in --*)
+ # file offset at start of AppleScript
+ found=1; break
+ ;;
+ esac
+done
+
+case "$found" in
+ 0)
+ echo 'shebang: AppleScript not found' >&2
+ exit 128
+ ;;
+esac
+
+# run the AppleScript
+exec /usr/bin/osascript -; exit
+
+-- AppleScript starts here
+set projectPath to system attribute "arg"
+
+set Dimensions to (do shell script "system_profiler SPDisplaysDataType | grep Resolution | awk '{print $2, $4}'")
+set displayWidth to word 1 of Dimensions
+set displayHeight to word 2 of Dimensions
+
+tell application "Terminal"
+ activate
+
+ -- Open new terminal window
+ tell application "System Events" to tell process "Terminal" to keystroke "n" using command down
+
+ -- Maximize
+ set bounds of the front window to {0, 0, displayWidth, displayHeight}
+
+ -- autospec
+ do script with command "cd " & projectPath & " && autospec" in selected tab of the front window
+
+ -- development log
+ tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
+ delay 0.3
+ do script with command "cd " & projectPath & " && tail -f log/development.log" in selected tab of the front window
+
+ -- script/console
+ tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
+ delay 0.3
+ do script with command "cd " & projectPath & " && script/console" in selected tab of the front window
+
+ -- MacVim
+ tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
+ delay 0.3
+ do script with command "cd " & projectPath & " && mvim" in selected tab of the front window
+end tell

0 comments on commit 19cade8

Please sign in to comment.
Something went wrong with that request. Please try again.