Created
March 29, 2009 11:24
-
-
Save mattman/87360 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/sh | |
# cd into matching gem directory ("cd -" friendly) | |
cdgem() { | |
local gempath=$(gem env gemdir)/gems | |
if [[ $1 == "" ]]; then | |
cd $gempath | |
return | |
fi | |
local gem=$(ls $gempath | g $1 | sort | tail -1) | |
if [[ $gem != "" ]]; then | |
cd $gempath/$gem | |
fi | |
} | |
_cdgem() { | |
COMPREPLY=($(compgen -W '$(ls `gem env gemdir`/gems)' -- ${COMP_WORDS[COMP_CWORD]})) | |
return 0; | |
} | |
complete -o default -o nospace -F _cdgem cdgem; | |
# check for a rake task on the current dir | |
function rake_exists? { | |
[[ -f Rakefile && $(rake -T | g $1 | wc -l) -gt 0 ]]; return $? | |
} | |
# get current revision of a repo | |
svn_revision() { | |
svn info $@ | awk '/^Revision:/ {print $2}' | |
} | |
# print the log or 'no changes' after an update | |
svn_up_and_log() { | |
local old_rev=$(svn_revision $@) | |
local first_up=$((${old_rev} + 1)) | |
svn up -q $@ | |
if [ $(svn_revision $@) -gt ${old_rev} ]; then | |
svn log -v -rHEAD:${first_up} $@ | |
else | |
echo "No changes." | |
fi | |
} | |
# tag a directory in a command to come to it later | |
tag() { | |
alias $1='cd $PWD' | |
} | |
# alias last command | |
a() { | |
x=`history 1 | sed 's/.\{7\}//'`; | |
alias ${1}="${x}"; | |
} | |
# True if a domain name is available | |
domainavailable() { | |
if whois $1 | grep "No match for" &> /dev/null; then | |
echo "$1 is available" | |
return 0 | |
else | |
echo "$1 is not available" | |
return 1 | |
fi | |
} | |
# Check all domains passed as arguments and print those available | |
availabledomains() { | |
for f in $@; do | |
domainavailable $f &> /dev/null && echo $f; | |
done | |
} | |
# CD back to current git's project base dir | |
cdg() { | |
local cdup=$(git-rev-parse --show-cdup 2> /dev/null) | |
if [ $? == 0 ]; then | |
if [ -z "$cdup" ]; then | |
cdup=. | |
fi | |
cd $cdup/$1 | |
else | |
echo "Not in a git repository" | |
return $? | |
fi | |
} | |
# Use ruby as a calculator" | |
calc() { | |
ruby -e 'include Math; puts eval(ARGV.join(" "))' $@; | |
} | |
# send HUP to the passed named process | |
hup() { | |
kill -HUP `pidof $1`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment