Skip to content

Instantly share code, notes, and snippets.

@parndt
Created September 16, 2013 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parndt/6587838 to your computer and use it in GitHub Desktop.
Save parndt/6587838 to your computer and use it in GitHub Desktop.
.bash_profile
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
export TERM=xterm-color
export MANPATH=/usr/local/git/man:$MANPATH
export EDITOR="$HOME/bin/editor.sh"
# Set the base PS1
export PS1="\t: \w$ "
# Rails 2, 3 and 4 console
function rc {
if [ -e "./script/console" ]; then
./script/console $@
elif [ -e "./bin/rails" ]; then
./bin/rails console $@
else
script/rails console $@
fi
}
# Rails 2, 3 and 4 server
function rs {
if [ -e "./script/server" ]; then
./script/server $@
elif [ -e "./bin/rails" ]; then
./bin/rails server $@
else
./script/rails server $@
fi
}
# Source the git bash completion file
. ~/.bashrc
# if [ -f ~/.git-completion.bash ]; then
# source ~/.git-completion.bash
# fi
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
### PS1
# Returns the current git branch (returns nothing if not a git repository)
parse_git_branch() {
\git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
parse_git_dirty() {
[ -n "$(\git status --short 2> /dev/null)" ] && echo "±"
}
# Returns the current ruby version.
parse_ruby_version() {
if (which ruby | grep -q ruby); then
ruby -v | cut -d ' ' -f2
fi
}
# Returns the Travis CI status for a github project
parse_travis_status() {
local branch="$1"
if [ -z "$branch" ]; then branch="master"; fi
local stat_file=$(find_in_cwd_or_parent ".travis_status~")
if [ -e "$stat_file" ]; then
case "$(grep -m 1 "^$branch " "$stat_file")" in
*passed) echo "\[\e[01;32m\]✔ ";; # green
*failed) echo "\[\e[01;31m\]✘ ";; # red
*running) echo "\[\e[01;33m\]⁇ ";; # yellow
esac
fi
}
# Test whether file exists in current or parent directories
find_in_cwd_or_parent() {
local slashes=${PWD//[^\/]/}; local directory=$PWD;
for (( n=${#slashes}; n>0; --n )); do
test -e $directory/$1 && echo "$directory/$1" && return 0
directory=$directory/..
done
return 1
}
# Allow symbols to represent users & machines
user_symbol(){ [ -e $HOME/.user_sym ] && cat $HOME/.user_sym || echo "$USER"; }
host_symbol(){ [ -e /home/.hostname_sym ] && cat /home/.hostname_sym || echo "$HOSTNAME"; }
user_host_sep() { ([ -e $HOME/.user_sym ] && [ -e /home/.hostname_sym ]) || echo "@"; }
set_ps1() {
local user_str="\[$_usr_col\]$(user_symbol)\[$_sep_col\]$(user_host_sep)\[$_hst_col\]$(host_symbol)\[$_txt_col\]"
local dir_str="\[$_cwd_col\]\w"
local git_branch=`parse_git_branch`
local git_dirty=`parse_git_dirty`
local trav_str=`parse_travis_status "$git_branch"`
local ruby=`parse_ruby_version`
git_str="\[$_git_col\]$git_branch\[$_wrn_col\]$git_dirty"
# Git repo & ruby version
if [ -n "$git_branch" ] && [ -n "$ruby" ]; then
env_str="\[$_env_col\][$git_str\[$_env_col\]|$ruby]"
# Just git repo
elif [ -n "$git_branch" ]; then
env_str="\[$_env_col\][$git_str\[$_env_col\]]"
# Just ruby version
elif [ -n "$ruby" ]; then
env_str="\[$_env_col\][$ruby]"
else
unset env_str
fi
# < username >@< hostname > < current directory > < ci status > [< git branch >|< ruby version >]
green=$(tput setaf 2)
blue=$(tput setaf 4)
reset=$(tput sgr0)
PS1="\t:\[$green\]${debian_chroot:+($debian_chroot)} $trav_str$env_str \[$_chr_col\]\[$blue\]$dir_str\[$reset\]$ \[$_txt_col\]"
}
### END PS1
# Set custom prompt
PROMPT_COMMAND+='set_ps1;'
export RUBY_GC_MALLOC_LIMIT=90000000
export RUBY_FREE_MIN=200000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment