Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Last active May 17, 2016 19:36
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 JoshCheek/821d684645c9d5a04350882b8c628018 to your computer and use it in GitHub Desktop.
Save JoshCheek/821d684645c9d5a04350882b8c628018 to your computer and use it in GitHub Desktop.
Quick/dirty bash profile for a server
# This file goes in ~/.bash_profile (the tilde is your home directory)
# ALIASES
# path
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
# NOTE: Delete this if you are using rvm
# override cd b/c I always want to list dirs after I cd
# note that this won't work with rvm b/c it overrides cd.
cd() {
builtin cd "$@"
l
}
# meta-p and meta-n: "starts with" history searching
# taken from http://blog.veez.us/the-unix-canon-n-p
bind '"\ep": history-search-backward'
bind '"\en": history-search-forward'
# 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 {
if [[ ! -z "$1" ]]; then
echo "\[\033[${2:-37};44m\]${1}\[\033[0m\]"
fi
}
function build_mah_prompt {
# time
ps1="$(prompt_segment " \@ ")"
# cwd with coloured current directory
# path="$(dirname `pwd`)"
# dir="$(basename `pwd`)"
# ps1="${ps1} $(prompt_segment " ${path}/")$(prompt_segment "$dir " 34)"
# cwd
ps1="${ps1} $(prompt_segment " \w ")"
# git branch
git_branch=`parse_git_branch`
if [[ ! -z "$git_branch" ]]; then ps1="${ps1} $(prompt_segment " $git_branch " 32)"; fi
# next line
ps1="${ps1}\n\$ "
# output
PS1="$ps1"
}
PROMPT_COMMAND='build_mah_prompt'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment