Created
April 24, 2010 04:22
-
-
Save jarodl/377461 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/bash | |
# A basically sane bash environment. | |
# | |
# Ryan Tomayko <http://tomayko.com/about> (with help from the internets). | |
# setup some basic variables | |
: ${HOME=~} | |
: ${LOGNAME=$(id -un)} | |
: ${UNAME=$(uname)} | |
# ---------------------------------------------------------------------- | |
# CONFIGURATION | |
# ---------------------------------------------------------------------- | |
# complete hostnames from | |
: ${HOSTFILE=~/.ssh/known_hosts} | |
# readline inputrc | |
: ${INPUTRC=~/.inputrc} | |
# alias | |
alias gitrm='git ls-files --deleted | xargs git rm' | |
alias hack='cd ~/Documents/Repositories/' | |
alias work='cd ~/Sites/' | |
alias home='cd ~/' | |
alias sc='./script/console' | |
alias sg='./script/generate' | |
alias ss='./script/server' | |
alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs' | |
# ---------------------------------------------------------------------- | |
# SHELL OPTIONS | |
# ---------------------------------------------------------------------- | |
# bring in system bashrc | |
test -r /etc/bashrc && | |
. /etc/bashrc | |
# notify of bg job completion immediately | |
set -o notify | |
# shell opts. see bash(1) for details | |
shopt -s cdspell >/dev/null 2>&1 | |
shopt -s extglob >/dev/null 2>&1 | |
shopt -s histappend >/dev/null 2>&1 | |
shopt -s hostcomplete >/dev/null 2>&1 | |
shopt -s interactive_comments >/dev/null 2>&1 | |
shopt -u mailwarn >/dev/null 2>&1 | |
shopt -s no_empty_cmd_completion >/dev/null 2>&1 | |
# disable core dumps | |
ulimit -S -c 0 | |
# default umask | |
umask 0022 | |
# ---------------------------------------------------------------------- | |
# PATH | |
# ---------------------------------------------------------------------- | |
# we want the various sbins on the path along with /usr/local/bin | |
PATH="$PATH:/usr/local/sbin:/usr/sbin:/sbin" | |
PATH="/usr/local/bin:$PATH" | |
# put ~/bin on PATH if you have it | |
test -d "$HOME/bin" && | |
PATH="$HOME/bin:$PATH" | |
# load rubygems | |
export RUBYOPT=rubygems | |
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/scala/scala-2.7.5.final/bin:$PATH" | |
# ---------------------------------------------------------------------- | |
# ENVIRONMENT CONFIGURATION | |
# ---------------------------------------------------------------------- | |
# detect interactive shell | |
case "$-" in | |
*i*) INTERACTIVE=1 ;; | |
*) unset INTERACTIVE ;; | |
esac | |
# detect login shell | |
case "$0" in | |
-*) LOGIN=1 ;; | |
*) unset LOGIN ;; | |
esac | |
# enable en_US locale w/ utf-8 encodings if not already configured | |
: ${LANG:="en_US.UTF-8"} | |
: ${LANGUAGE:="en"} | |
: ${LC_CTYPE:="en_US.UTF-8"} | |
: ${LC_ALL:="en_US.UTF-8"} | |
export LANG LANGUAGE LC_CTYPE LC_ALL | |
# always use PASSIVE mode ftp | |
: ${FTP_PASSIVE:=1} | |
export FTP_PASSIVE | |
# ignore backups, CVS directories, python bytecode, vim swap files | |
FIGNORE="~:CVS:#:.pyc:.swp:.swa:apache-solr-*" | |
HISTCONTROL=ignoreboth | |
# ---------------------------------------------------------------------- | |
# PAGER / EDITOR | |
# ---------------------------------------------------------------------- | |
# See what we have to work with ... | |
HAVE_VIM=$(command -v vim) | |
HAVE_GVIM=$(command -v gvim) | |
# EDITOR | |
EDITOR="mvim" | |
CVSEDITOR="mvim" | |
SVN_EDITOR="mvim" | |
export EDITOR CVSEDITOR SVN_EDITOR | |
# PAGER | |
if test -n "$(command -v less)" ; then | |
PAGER="less -FirSwX" | |
MANPAGER="less -FiRswX" | |
else | |
PAGER=more | |
MANPAGER="$PAGER" | |
fi | |
export PAGER MANPAGER | |
# ---------------------------------------------------------------------- | |
# PROMPT | |
# ---------------------------------------------------------------------- | |
RED="\[\033[0;31m\]" | |
BROWN="\[\033[0;33m\]" | |
GREY="\[\033[0;97m\]" | |
BLUE="\[\033[0;34m\]" | |
CYAN="\[\033[0;36m\]" | |
GREEN="\[\033[0;32m\]" | |
PS_CLEAR="\[\033[0m\]" | |
SCREEN_ESC="\[\033k\033\134\]" | |
if [ "$LOGNAME" = "root" ]; then | |
COLOR1="${RED}" | |
COLOR2="${GREEN}" | |
P="#" | |
elif hostname | grep -q 'github\.com'; then | |
GITHUB=yep | |
COLOR1="\[\e[0;94m\]" | |
COLOR2="\[\e[0;92m\]" | |
P="\$" | |
else | |
COLOR1="${BLUE}" | |
COLOR2="${GREEN}" | |
P="\$" | |
fi | |
prompt_simple() { | |
unset PROMPT_COMMAND | |
PS1="[\u@\h:\w]\$ " | |
PS2="> " | |
} | |
prompt_compact() { | |
unset PROMPT_COMMAND | |
PS1="${COLOR1}${P}${PS_CLEAR} " | |
PS2="> " | |
} | |
prompt_color() { | |
PS1="${CYAN}[${COLOR1}\u${RED}@${COLOR2}\h${RED}:${CYAN}\W${RED}]${COLOR2}$P${PS_CLEAR} " | |
PS2="\[[33;1m\]continue \[[0m[1m\]> " | |
} | |
# ---------------------------------------------------------------------- | |
# MACOS X / DARWIN SPECIFIC | |
# ---------------------------------------------------------------------- | |
if [ "$UNAME" = Darwin ]; then | |
# put ports on the paths if /opt/local exists | |
test -x /opt/local && { | |
PORTS=/opt/local | |
# setup the PATH and MANPATH | |
PATH="$PORTS/bin:$PORTS/sbin:$PATH" | |
MANPATH="$PORTS/share/man:$MANPATH" | |
# nice little port alias | |
alias port="sudo nice -n +18 $PORTS/bin/port" | |
} | |
test -x /usr/pkg && { | |
PATH="/usr/pkg/sbin:/usr/pkg/bin:$PATH" | |
MANPATH="/usr/pkg/share/man:$MANPATH" | |
} | |
# setup java environment. puke. | |
RHINO_HOME="/usr/share/java" | |
JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Home" | |
ANT_HOME="/Developer/Java/Ant" | |
export ANT_HOME JAVA_HOME RHINO_HOME | |
# hold jruby's hand | |
test -d /opt/jruby && | |
JRUBY_HOME="/opt/jruby" | |
export JRUBY_HOME | |
fi | |
# ---------------------------------------------------------------------- | |
# ALIASES / FUNCTIONS | |
# ---------------------------------------------------------------------- | |
# git functions | |
alias glog="git log --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative" | |
alias gi='git init && touch README.md' | |
alias gc='git clone' | |
# setting up a directory for design | |
alias mksite='touch index.html && mkdir css js images | mate index.html' | |
# disk usage with human sizes and minimal depth | |
alias du1='du -h --max-depth=1' | |
alias fn='find . -name' | |
alias hi='history | tail -20' | |
# nginx startup and kill | |
alias start_nginx='sudo /opt/nginx/sbin/nginx' | |
alias stop_nginx='sudo kill `cat /opt/nginx/logs/nginx.pid `' | |
alias restart_nginx='stop_nginx; start_nginx' | |
# Django | |
alias dj='django-admin.py startproject' | |
alias djapp='python manage.py startapp' | |
alias djstart='python manage.py runserver' | |
alias djshell='python manage.py shell' | |
# javascript | |
alias rhino='java -jar /usr/share/java/js.jar' | |
# ---------------------------------------------------------------------- | |
# BASH COMPLETION | |
# ---------------------------------------------------------------------- | |
if test -z "$BASH_COMPLETION" ; then | |
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.} | |
if [ "$PS1" ] && [ $bmajor -gt 1 ] ; then | |
# search for a bash_completion file to source | |
for f in /usr/pkg/etc/back_completion \ | |
/usr/local/etc/bash_completion \ | |
/opt/local/etc/bash_completion \ | |
/etc/bash_completion \ | |
~/.bash_completion ; | |
do | |
test -f $f && { | |
. $f | |
break | |
} | |
done | |
fi | |
unset bash bmajor bminor | |
fi | |
# override and disable tilde expansion | |
_expand() { | |
return 0 | |
} | |
# ---------------------------------------------------------------------- | |
# LS AND DIRCOLORS | |
# ---------------------------------------------------------------------- | |
# we always pass these to ls(1) | |
LS_COMMON="-hBG" | |
# if the dircolors utility is available, set that up to | |
dircolors="$(type -P gdircolors dircolors | head -1)" | |
test -n "$dircolors" && { | |
COLORS="$HOME/.dircolors" | |
test -e "/etc/DIR_COLORS.$TERM" && COLORS="/etc/DIR_COLORS.$TERM" | |
test -e "$HOME/.dircolors" && COLORS="$HOME/.dircolors" | |
test ! -e "$COLORS" && COLORS= | |
eval `$dircolors --sh $COLORS` | |
} | |
unset dircolors | |
# setup the main ls alias if we've established common args | |
test -n "$LS_COMMON" && | |
alias ls="command ls $LS_COMMON" | |
# these use the ls aliases above | |
alias ll="ls -l" | |
alias l.="ls -d .*" | |
# -------------------------------------------------------------------- | |
# MISC COMMANDS | |
# -------------------------------------------------------------------- | |
# push SSH public key to another box | |
push_ssh_cert() { | |
local _host | |
test -f ~/.ssh/id_dsa.pub || ssh-keygen -t dsa | |
for _host in "$@"; | |
do | |
echo $_host | |
ssh $_host 'cat >> ~/.ssh/authorized_keys' < ~/.ssh/id_dsa.pub | |
done | |
} | |
# ------------------------------------------------------------------- | |
# USER SHELL ENVIRONMENT | |
# ------------------------------------------------------------------- | |
# source ~/.shenv now if it exists | |
test -r ~/.shenv && | |
. ~/.shenv | |
# Use the color prompt by default when interactive | |
test -n "$PS1" && | |
prompt_color | |
# ------------------------------------------------------------------- | |
# MOTD / FORTUNE | |
# ------------------------------------------------------------------- | |
test -n "$INTERACTIVE" -a -n "$LOGIN" && { | |
uname -npsr | |
uptime | |
} | |
function railsapp { | |
template=$1 | |
appname=$2 | |
shift 2 | |
rails $appname -m http://github.com/ryanb/rails-templates/raw/master/$template.rb $@ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment