Created
June 12, 2009 13:51
-
-
Save caius/128644 to your computer and use it in GitHub Desktop.
A few bash functions I use to save typing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Runs `git push` before `cap deploy` | |
# Otherwise just passes through to `cap` | |
function cap { | |
CAP="`which cap`" | |
if [[ "$1" == "deploy" || "$2" == "deploy" ]]; then | |
git push && $CAP $* | |
else | |
$CAP $* | |
fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## My magical git function ## | |
# Adds various checks to `git` as detailed below: | |
# * Makes sure you've run your specs/features before pushing | |
# * Asks for confirmation before committing on master | |
function git { | |
GIT="`which git`" | |
CONTINUE=true | |
# git push | |
# Checks if there are spec/ or features/ folders and | |
# questions the user if they have been run if they exist. | |
if [[ "$1" == "push" ]]; then | |
# Check if spec/ exists | |
if [[ -e spec ]]; then | |
CONTINUE=false # fail by default | |
# Ask the user | |
echo -n "Have you run your specs? [Y/n]" | |
read a | |
if [[ $a == "Y" || $a == "y" || $a == "" ]]; then | |
CONTINUE=true | |
fi | |
fi | |
# Check if features/ exists | |
if [[ -e features ]]; then | |
CONTINUE=false # fail by default | |
# Ask the user | |
echo -n "Have you run your features? [Y/n]" | |
read a | |
if [[ $a == "Y" || $a == "y" || $a == "" ]]; then | |
CONTINUE=true | |
fi | |
fi | |
# git commit | |
# Checks if we're on the master branch and | |
# double-checks with the user if they are | |
elif [[ "$1" == "commit" || "$1" == "vi" || "$1" == "via" || "$1" == "viaa" ]]; then | |
# Check the branch we're on | |
if [[ `parse_git_branch` == "(master)" ]]; then | |
CONTINUE=false # fail by default on master | |
# We're on master! Make sure we want to commit here | |
echo "= WARNING: Committing on master =" | |
echo -n "Continue? [y/N]" | |
read a | |
if [[ $a == "y" || $a == "Y" || $a == "yes" ]]; then | |
# They must really want to commit on master | |
CONTINUE=true | |
else | |
echo "Not committing." | |
fi | |
fi | |
fi | |
# Run the command if we've been told to. | |
# The default is to run the command so this only | |
# fires if a check has disabled it. | |
if [[ $CONTINUE == true ]]; then | |
$GIT $* | |
fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ss # => ./script/server | |
# ss 3001 # => ./script/server -p 3001 | |
# ss test # => ./script/server -e test | |
# ss test 3001 # => ./script/server -e test -p 3001 | |
function ss { | |
if [[ -z "$1" ]]; then | |
ruby script/server | |
elif [[ -z "$2" ]]; then | |
# Is it a port or an env? | |
if [[ "$1" =~ [0-9]+ ]]; then | |
# Its a port | |
ruby script/server -p $1 | |
else # its an env name | |
ruby script/server -e $1 | |
fi | |
else | |
ruby script/server -e $1 -p $2 | |
fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Opens and navigates to a disk image | |
# If the disk image is already mounted, just cd to it | |
# Otherwise, mount it first. If it mounts, cd to it; else print error msg. | |
# | |
# Edit LOCATION= to set where your disk images are stored. It assumes ~ by default. | |
# Currently looks for .sparseimage and .sparsebundle only. | |
# And assumes that they mount in /Volumes/{something}. Therefore it'll most likely only work on OS X. | |
# | |
# USAGE: `open_and_cd_to_disk_image Projects` | |
# | |
function open_and_cd_to_disk_image { | |
LOCATION="$HOME" | |
if [ ! -d "/Volumes/$1" ]; then | |
# We need to search various types of disk image extensions | |
FILE="$LOCATION/$1" | |
FOUND=false | |
if [[ -e "$FILE.sparsebundle" ]]; then | |
FILE="$FILE.sparsebundle" | |
FOUND=true | |
elif [[ -e "$FILE.sparseimage" ]]; then | |
FILE="$FILE.sparseimage" | |
FOUND=true | |
fi | |
# If we found anything, then open it | |
if [[ $FOUND == true ]]; then | |
open -W "$FILE" | |
fi | |
fi | |
if [ -d "/Volumes/$1" ]; then | |
cd "/Volumes/$1/" | |
else | |
echo "Doesn't look like $1 got mounted." | |
fi | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Switch to REE before running `rake spec` | |
# Disable switch with `rake spec -n` | |
function rake () { | |
RAKE="`which rake`" | |
if [[ "$1" == "spec" ]]; then | |
if [[ "$2" == "--no-switch" || "$2" == "-n" ]]; then | |
$RAKE spec | |
else | |
rvm use ree | |
$RAKE spec | |
rvm use default | |
fi | |
else | |
$RAKE $* | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment