Skip to content

Instantly share code, notes, and snippets.

@benclark
Created June 1, 2013 01:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benclark/5688975 to your computer and use it in GitHub Desktop.
Save benclark/5688975 to your computer and use it in GitHub Desktop.
My .profile
alias now='/bin/date +%s'
# Convert a timestamp
unixtime() {
php -r 'if (isset($argv[1]) && is_numeric($argv[1])) print date(DATE_RSS, $argv[1]) . "\n";' $1
}
# Local VM config
export localvmname="Debian32"
# Find out if the local VM is running
get_runningvms() {
local runningvms=$(/usr/bin/VBoxManage list runningvms | grep "$localvmname")
[ -n "$runningvms" ] && echo " •"
}
alias debstart='/usr/bin/VBoxManage startvm "$localvmname" --type headless'
alias debstop='/usr/bin/VBoxManage controlvm "$localvmname" acpipowerbutton'
# Go to a specified git repo in $HOME/Sites
repo() {
local reponame=$1
local jumpto_type=$2
local jumpto_which=$3
local basedir="$HOME/Sites/$reponame"
local cd_to
if [ -z $reponame ]; then
echo "usage: repo reponame [type [which]]"
return
fi
if [ -d "$basedir/repo/docroot" ]; then
cd_to="$basedir/repo/docroot"
elif [ -d "$basedir/repo" ]; then
cd_to="$basedir/repo"
elif [ -d "$basedir/trunk" ]; then
cd_to="$basedir/trunk"
elif [ -d "$basedir" ]; then
cd_to="$basedir"
else
echo "Invalid repo."
return
fi
if [ ! -z $jumpto_type ]; then
if [ -d "$cd_to/sites/all/$jumpto_type" ]; then
if [ ! -z $jumpto_which ]; then
if [ -d "$cd_to/sites/all/$jumpto_type/$jumpto_which" ]; then
cd "$cd_to/sites/all/$jumpto_type/$jumpto_which"
else
echo "Invalid which."
return
fi
else
cd "$cd_to/sites/all/$jumpto_type"
fi
else
echo "Invalid type."
return
fi
else
cd "$cd_to"
fi
}
# Load a specified project in Sublime Text 2
proj() {
local projname=$1
local basedir="$HOME/Dropbox/Projects"
if [ -f "$basedir/$projname.sublime-project" ]; then
/usr/local/bin/subl "$basedir/$projname.sublime-project"
fi
}
# Go to a specified Dropbox directory
dropbox() {
local subdir=$1
local basedir="$HOME/Dropbox"
if [ -d "$basedir/$subdir" ]; then
cd "$basedir/$subdir"
elif [ -d "$basedir" ]; then
cd "$basedir"
fi
}
# Get the current git branch (for the prompt)
get_git_branch() {
local br=$(git branch 2> /dev/null | grep "*" | sed 's/* //g')
[ -n "$br" ] && echo " [$br]"
}
# Update prompt
export PS1='\h:\w \u$(get_git_branch)$(get_runningvms)\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment