Created
January 9, 2015 19:02
-
-
Save AndyDangerous/d78ca82169161bdac55f to your computer and use it in GitHub Desktop.
.bash_profile
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
# Environment Variables | |
# Not this time... | |
# Take you to the dir of a file in a gem. e.g. `2gem rspec` | |
2gem () { | |
cd "$(dirname $(gem which $1))" | |
} | |
# Gives you a middle finger prompt because I was only born with two | |
# GODDAMMIT! It doesn't exist yet | |
# ALIASES | |
# random things I use all the time | |
alias be="bundle exec" | |
alias dbprep="rake db:drop db:create db:migrate db:seed db:test:prepare" | |
# path | |
alias cdp="cd ~/projects/personal/" | |
alias cdb="cd ~/projects/personal/cobackcountry" | |
alias cfr="cd ~/projects/rails/feed_engine/feed_engine_rails" | |
alias cfe="cd ~/projects/rails/feed_engine/feed_engine_ember" | |
alias cdr="cd ~/projects/rails/" | |
alias ..="cd .." | |
alias ...="cd ../.." | |
alias ....="cd ../../.." | |
alias .....="cd ../../../.." | |
alias ......="cd ../../../../.." | |
# fancy ls command | |
# -l long format | |
# -F / after dirs, * after exe, @ after symlink | |
# -G colorize | |
# -g suppress owner | |
# -o suppress group | |
# -h humanize sizes | |
# -q print nongraphic chars as question marks | |
alias l="ls -lFGgohq" | |
# git | |
alias gsh="git s" # git show with my custom options (see gitconfig) | |
alias gs="git status" | |
alias gd="git d" # git diff with my custom options | |
alias go="colour-stderr-red git checkout" | |
alias gb="git branch" | |
alias ga="git add" | |
alias gcm="git commit -m" | |
alias gpom="git pull origin master" | |
alias gpo="git push origin" | |
alias ghero="git push origin master | git push heroku master" | |
alias gh="git hist" | |
#git diff but prettier | |
alias gd="git log --pretty=oneline" | |
# PROMPT | |
# give the fullpaths of files passed in argv or piped through stdin | |
function fullpath { | |
ruby -e ' | |
$stdin.each_line { |path| puts File.expand_path path } if ARGV.empty? | |
ARGV.each { |path| puts File.expand_path path } unless ARGV.empty? | |
' "$@" | |
} | |
# Prompt | |
function parse_git_branch { | |
branch=`git rev-parse --abbrev-ref HEAD 2>/dev/null` | |
if [ "HEAD" = "$branch" ]; then | |
echo "(no branch)" | |
else | |
echo "$branch" | |
fi | |
} | |
function prompt_segment { | |
# for colours: http://en.wikipedia.org/wiki/ANSI_escape_code#Colors | |
# change the 30 to change the text | |
# change the 45 to change the background | |
if [[ ! -z "$1" ]]; then | |
echo "\[\033[${2:-30};46m\]${1}\[\033[0m\]" | |
fi | |
} | |
function build_mah_prompt { | |
# time | |
ps1="$(prompt_segment " \@ ")" | |
# cwd | |
ps1="${ps1} $(prompt_segment " \w ")" | |
# git branch | |
git_branch=`parse_git_branch` | |
if [[ ! -z "$git_branch" ]] | |
then | |
ps1="${ps1} $(prompt_segment " $git_branch " 35)" | |
fi | |
# next line | |
ps1="${ps1}\n\$ " | |
# set prompt output | |
# PS1="$ps1" | |
PS1="$ps1" | |
} | |
PROMPT_COMMAND='build_mah_prompt' | |
# This is absolutely disgusting, but I can't find a better way to do it. It will colourize the | |
# standarderr red (but will print on stdout, and stdout on stderr) | |
function colour-red { | |
ruby -e '$stderr.print "\e[31m", $stdin.read, "\e[0m"' | |
} | |
function colour-stderr-red { | |
( $* 3>&1 1>&2- 2>&3- ) | colour-red | |
} | |
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile | |
# Ruby versions (I don't have rvm installed, so can't check to make sure it works, but I think it should. | |
# If you try it, and it works for you, consider letting me know. If not, I wouldn't mind a pull request :) | |
function which_ruby { | |
if type rvm >/dev/null 2>&1; then | |
echo rvm | |
elif type rbenv >/dev/null 2>&1; then | |
echo rbenv | |
else | |
echo Cannot determine Ruby version >&2 | |
exit 1 | |
fi | |
} | |
function switch_ruby_version { | |
case "$(which_ruby)" in | |
rvm) | |
rvm use "$(rvm list strings | grep -i "$1" | tail -1)" >/dev/null;; | |
rbenv) | |
rbenv shell "$(rbenv versions --bare | grep -i "$1" | tail -1)" >/dev/null;; | |
*) | |
echo "Don't know how to switch ruby versions in $which_ruby" 1>&2 | |
return 1;; | |
esac | |
} | |
alias rrbx=" switch_ruby_version rbx true && ruby -v" | |
alias rmac=" switch_ruby_version macruby true && ruby -v" | |
alias rjav=" switch_ruby_version jruby true && ruby -v" | |
alias r186=" switch_ruby_version 1.8.6 true && ruby -v" | |
alias r187=" switch_ruby_version 1.8.7 true && ruby -v" | |
alias r191=" switch_ruby_version 1.9.1 true && ruby -v" | |
alias r192=" switch_ruby_version 1.9.2 true && ruby -v" | |
alias r193=" switch_ruby_version 1.9.3 true && ruby -v" | |
alias r2=" switch_ruby_version 2.0 true && ruby -v" | |
export PATH=/usr/local/bin:$PATH | |
export PATH=/usr/local/bin:$PATH | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment