Created
June 14, 2011 19:02
-
-
Save ryansch/1025596 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # .bashrc | |
| # User specific aliases and functions | |
| # Source global definitions | |
| if [ -f /etc/bashrc ]; then | |
| . /etc/bashrc | |
| fi | |
| if [ -f .bash_completion ]; then | |
| shopt -s extglob progcomp | |
| . .bash_completion | |
| fi | |
| if [ -f /etc/bash_completion.d/git ]; then | |
| shopt -s extglob progcomp | |
| . /etc/bash_completion.d/git | |
| # export PS1="[\u@\h \$(__git_ps1 '(%s)')\W]\$ " | |
| elif [ -f /usr/local/git/contrib/completion/git-completion.bash ] ; then | |
| shopt -s extglob progcomp | |
| . /usr/local/git/contrib/completion/git-completion.bash | |
| # export PS1='[\u@\h $(__git_ps1 "(%s)")\W]\$ ' | |
| elif [ -f /usr/local/etc/bash_completion.d/git-completion.bash ] ; then | |
| shopt -s extglob progcomp | |
| . /usr/local/etc/bash_completion.d/git-completion.bash | |
| # export PS1="[\u@\h \$(__git_ps1 '(%s)')\$(rvm-prompt) \W]\$ " | |
| #else | |
| # export PS1='[\u@\h \W]\$ ' | |
| fi | |
| #export EDITOR=/usr/bin/vim | |
| export EDITOR=/usr/local/bin/mvim | |
| export PATH=$HOME/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/ruby-enterprise/bin:$PATH | |
| export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/local/lib | |
| alias git=hub | |
| alias gitx='gitx --all' | |
| alias cucwip="./script/cucumber --profile wip" | |
| alias cuc="./script/cucumber" | |
| alias onecuc="./script/cucumber --profile one" | |
| export RSPEC_COLOR=true | |
| alias cucumber="cucumber -c" | |
| export LESS="-R -X -F" | |
| #Linux colors | |
| #export LS_COLORS='no=00:fi=00:di=01;33:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.png=01;35:*.mpg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:' | |
| #Mac OS colors | |
| alias ls="ls -G" | |
| #export LSCOLORS='DxGxfxfxcxDxDxhbhDecec' | |
| # Xterm Titles in mac os | |
| # are we an interactive shell? | |
| if [ "$PS1" ]; then | |
| case $TERM in | |
| xterm*) | |
| if [ -e /etc/sysconfig/bash-prompt-xterm ]; then | |
| PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm | |
| else | |
| PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"' | |
| fi | |
| ;; | |
| screen) | |
| if [ -e /etc/sysconfig/bash-prompt-screen ]; then | |
| PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen | |
| else | |
| PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"' | |
| fi | |
| ;; | |
| *) | |
| [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default | |
| ;; | |
| esac | |
| fi | |
| # Ripped from rvm/contrib/ps1_functions | |
| # Examples: | |
| # | |
| # ps1_set --prompt ∫ | |
| # | |
| # or | |
| # | |
| # ps1_set --prompt ∴ | |
| # | |
| # This will yield a prompt like the following, for example, | |
| # | |
| # 00:00:50 wayneeseguin@GeniusAir:~/projects/db0/rvm/rvm (git:master:156d0b4) ruby-1.8.7-p334@rvm | |
| # ∴ | |
| # | |
| ps1_identity() | |
| { | |
| if [[ $UID -eq 0 ]] ; then | |
| #printf "%s" "\[\033[31m\]\\u\[\033[0m\]@\[\033[36m\]\\h\[\033[35m\]:\W\[\033[0m\] " | |
| printf "%s" "\[\033[31m\]\\u\[\033[0m\]@\[\033[36m\]\\h\[\033[0m\] " | |
| else | |
| # printf "%s" "\[\033[32m\]\\u\[\033[0m\]@\[\033[36m\]\\h\[\033[35m\]:\W\[\033[0m\] " | |
| printf "%s" "\[\033[32m\]\\u\[\033[0m\]@\[\033[36m\]\\h\[\033[0m\] " | |
| fi | |
| } | |
| ps1_workdir() | |
| { | |
| printf "\[\033[35m\]\W\[\033[0m\]" | |
| } | |
| ps1_git() | |
| { | |
| local branch="" sha1="" line="" attr="" color=0 | |
| shopt -s extglob # Important, for our nice matchers :) | |
| if ! command -v git >/dev/null 2>&1 ; then | |
| printf " \033[1;37m\033[41m[git not found]\033[m " | |
| return 0 | |
| fi | |
| branch=$(git symbolic-ref -q HEAD 2>/dev/null) | |
| if [[ $? -gt 0 ]] ; then | |
| return 0 # Not in a git repo, no need to continue. | |
| fi | |
| branch=${branch##refs/heads/} | |
| # Now we display the branch. | |
| #sha1=($(git log --no-color -1 2>/dev/null)) | |
| #sha1=${sha1[1]} | |
| #sha1=${sha1:0:7} | |
| case "${branch:-"(no branch)"}" in | |
| master) attr="1;37m\033[" ; color=41 ;; # red | |
| release/*|hotfix/*) color=31 ;; # red | |
| stage|staging) color=33 ;; # yellow | |
| develop) color=34 ;; # blue | |
| next) color=36 ;; # gray | |
| *) | |
| if [[ -n "${branch}" ]] ; then # Feature Branch :) | |
| color=32 # green | |
| else | |
| color=0 # reset | |
| fi | |
| ;; | |
| esac | |
| if [[ $color -gt 0 ]] ; then | |
| printf "\[\033[${attr}${color}m\](${branch}$(ps1_git_status))\[\033[0m\] " | |
| fi | |
| } | |
| ps1_git_status() | |
| { | |
| local git_status="$(git status 2>/dev/null)" | |
| case "${git_status}" in (*deleted:*) printf "%s" "-" ;; esac | |
| case "${git_status}" in (*Untracked[[:space:]]files:*) printf "%s" "+" ;; esac | |
| case "${git_status}" in (*modified:*) printf "%s" "*" ;; esac | |
| } | |
| ps1_rvm() | |
| { | |
| if command -v rvm-prompt >/dev/null 2>/dev/null ; then | |
| if [[ ! $(rvm-prompt) == $OLD_RVM ]]; then | |
| export OLD_RVM=$(rvm-prompt) | |
| printf "$(rvm-prompt) " | |
| fi | |
| fi | |
| } | |
| ps1_update() | |
| { | |
| local prompt_char='$' | |
| local separator="\n" | |
| local notime=0 | |
| if [[ $UID -eq 0 ]] ; then | |
| prompt_char='#' | |
| fi | |
| while [[ $# -gt 0 ]] ; do | |
| local token="$1" ; shift | |
| case "$token" in | |
| --trace) | |
| export PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > " | |
| set -o xtrace | |
| ;; | |
| --prompt) | |
| prompt_char="$1" | |
| shift | |
| ;; | |
| --noseparator) | |
| separator="" | |
| ;; | |
| --separator) | |
| separator="$1" | |
| shift | |
| ;; | |
| --notime) | |
| notime=1 | |
| ;; | |
| *) | |
| true # Ignore everything else. | |
| ;; | |
| esac | |
| done | |
| if [[ $notime -gt 0 ]] ; then | |
| PS1="[$(ps1_identity)$(ps1_git)$(ps1_workdir)]${separator}${prompt_char} " | |
| else | |
| PS1="\D{%H:%M:%S} $(ps1_identity)$(ps1_git)$(ps1_workdir)${separator}${prompt_char} " | |
| fi | |
| } | |
| ps2_set() | |
| { | |
| PS2=" \[\033[0;40m\]\[\033[0;33m\]> \[\033[1;37m\]\[\033[1m\]" | |
| } | |
| ps4_set() | |
| { | |
| export PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > " | |
| } | |
| # WARNING: This clobbers your PROMPT_COMMAND so if you need to write your own, call | |
| # ps1_update within your PROMPT_COMMAND with the same arguments you pass | |
| # to ps1_set | |
| # | |
| # The PROMPT_COMMAND is used to help the prompt work if the separator is not a new line. | |
| # In the event that the separtor is not a new line, the prompt line may become distored if | |
| # you add or delete a certian number of characters, making the string wider than the | |
| # $COLUMNS + len(your_input_line). | |
| # This orginally was done with callbacks within the PS1 to add in things like the git | |
| # commit, but this results in the PS1 being of an unknown width which results in the prompt | |
| # being distored if you add or remove a certain number of characters. To work around this | |
| # it now uses the PROMPT_COMMAND callback to re-set the PS1 with a known width of chracters | |
| # each time a new command is entered. see PROMPT_COMMAND for more details. | |
| # | |
| ps1_set() | |
| { | |
| # PROMPT_COMMAND="ps1_update $@" | |
| PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}: ${PWD/#$HOME/~}\007"'"; ps1_update $@" | |
| } | |
| ps1_set --notime --noseparator | |
| . ~/.preexec.bash | |
| # called before each command and starts stopwatch | |
| function preexec () { | |
| export PREEXEC_CMD="$BASH_COMMAND" | |
| export PREEXEC_TIME=$(date +'%s') | |
| } | |
| # called after each command, stops stopwatch | |
| # and notifies if time elpsed exceeds threshold | |
| function precmd () { | |
| stop=$(date +'%s') | |
| start=${PREEXEC_TIME:-$stop} | |
| let elapsed=$stop-$start | |
| max=${PREEXEC_MAX:-10} | |
| if [ $elapsed -gt $max ]; then | |
| growlnotify -n "iTerm" -m "took $elapsed secs" "${PREEXEC_CMD:-Some Command}" | |
| fi | |
| } | |
| preexec_install | |
| [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment