Skip to content

Instantly share code, notes, and snippets.

@erikh
Created July 2, 2012 20:30
Show Gist options
  • Save erikh/8eec236f59c88e98d8b3 to your computer and use it in GitHub Desktop.
Save erikh/8eec236f59c88e98d8b3 to your computer and use it in GitHub Desktop.
# vim: ft=sh
# basic shell variables
set -o vi
export EDITOR=vim
export VISUAL=$EDITOR
export PROMPT="%(0?..[fail:%?])%(1j.[jobs:%j].)[%h] %n@%m %2~%# "
# directory aliases
config=$HOME/config
hosts=~config/bash/hosts
# completion!
autoload -U compinit
compinit
# shell options
setopt PUSHD_SILENT
unsetopt BG_NICE
unsetopt EXTENDED_GLOB
# aliases
alias ls='ls -aFC'
alias pu="builtin pushd"
alias p="builtin popd"
alias d="builtin dirs -v"
alias h="builtin history"
alias be="bundle exec"
alias t="tmux attach"
alias c="cd;clear"
alias ov="open -a MacVim"
# functions
uptime_penis() {
uptime | perl -ne "/(\d+) d/;print 8,q(=)x\$1,\"D\n\""
}
# load our profiles based on the machine type
case $(uname -s)
in
FreeBSD)
. ~/config/bash/bsd/profile
;;
Linux)
. ~/config/bash/linux/profile
;;
Darwin)
. ~/config/bash/mac/profile
;;
CYGWIN_NT-5.1)
. ~/config/bash/windows/profile
;;
esac
# path setup
export PATH="/usr/local/bin:/usr/local/sbin:/bin:/usr/bin:/sbin:/usr/sbin"
if [[ -d /var/lib/gems/1.8/bin ]]
then
export PATH="/var/lib/gems/1.8/bin:$PATH"
fi
if [[ -d $HOME/bin ]]
then
export PATH="$HOME/bin:$PATH"
fi
if [[ -d /usr/local/mysql ]]
then
export PATH="/usr/local/mysql/bin:$PATH"
fi
if [[ -d /opt/local ]]
then
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
fi
# load profiles based on the hostname
hostname=$(hostname | cut -d . -f 1)
if [[ -f ~/config/bash/hosts/$hostname ]]
then
. ~/config/bash/hosts/$hostname
fi
function edit_perl() {
$EDITOR (bin|lib|t)/**/*.(pm|pl|PL|t)
}
function edit_ruby() {
$EDITOR (bin|lib|test)/**/(*|*.rb)
}
# prompts
# XXX the first linux case will need to be hacked up eventually to accomodate other console terms.
case $TERM in
linux)
;;
*)
export RPROMPT="[%T]"
precmd() {
if [ "x$rvm_env_string" != "x" ]
then
export RPROMPT="[r: $rvm_env_string][%T]"
elif [ "x$rvm_ruby_string" != "x" ]
then
export RPROMPT="[r: $rvm_ruby_string][%T]"
elif [ -x $HOME/bin/rbfu ]
then
export RPROMPT="[r: ${RBFU_ENV}][%T]"
fi
case $TERM in
screen)
print -Pn "\ek$PROMPT\e\\"
;;
vt100)
;;
*)
print -Pn "\e]0;$PROMPT\e\\"
;;
esac
}
preexec() {
case $TERM in
screen)
print -Pn "\ek$1\e\\"
;;
vt100)
;;
*)
print -Pn "\e]0;$1\e\\"
;;
esac
}
;;
esac
# https://github.com/hmans/rbfu
DEFAULT_RUBY=1.9.3-p194
re() {
if [ "x$1" != "x" ]
then
source ${HOME}/bin/rbfu @$1
RBFU_ENV=$1
fi
}
rl() {
for i in ${HOME}/.rbfu/rubies/*
do
echo $(basename $i)
done
}
rb_build() {
ruby-build $1 ${HOME}/.rbfu/rubies/$1
rbfu @$1 gem install bundler
}
rb_remove() {
if [ "x$1" = "x" ]
then
echo "Please supply an argument"
else
rm -r ${HOME}/.rbfu/rubies/$1
fi
}
if [[ -x ${HOME}/bin/rbfu ]]
then
eval "$(rbfu --init)"
if [ -d ${HOME}/.rbfu/rubies/${DEFAULT_RUBY} ]
then
source ${HOME}/bin/rbfu @${DEFAULT_RUBY}
RBFU_ENV=${DEFAULT_RUBY}
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment