Last active
August 29, 2015 14:02
-
-
Save sysout/1f966118044b89efcda9 to your computer and use it in GitHub Desktop.
my command prompt setup for Mac Rails develpment, it shows git information in prompt and change terminal name
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
# http://brettterpstra.com/2009/11/17/my-new-favorite-bash-prompt/ | |
# http://bytebaker.com/2012/01/09/show-git-information-in-your-prompt/ | |
function git-dirty() { | |
st=$(git status 2>/dev/null | tail -n 1) | |
if [[ $st != "nothing to commit, working directory clean" ]] | |
then | |
echo "*" | |
fi | |
} | |
function git-branch-name() | |
{ | |
echo $(git symbolic-ref HEAD 2>/dev/null | awk -F/ {'print $NF'}) | |
} | |
function git-unpushed { | |
#brinfo=$(git branch -v | grep $(git-branch-name)) | |
brinfo=$(git branch -v) | |
if [[ $brinfo =~ ("[ahead "([[:digit:]]*)) ]] | |
then | |
echo "(${BASH_REMATCH[2]})" | |
fi | |
} | |
function gitify { | |
status=$(git status 2>/dev/null) | |
if [[ $status == "" ]] | |
then | |
echo "" | |
else | |
echo \ $(git-branch-name)$(git-dirty)$(git-unpushed) | |
fi | |
} | |
# adding \[ and \] around all of your color sequences in your PS1 declaration | |
# http://stackoverflow.com/questions/706750/why-is-this-bash-prompt-acting-strangely-disappearing-and-how-do-i-fix-it-os-x | |
# https://wiki.archlinux.org/index.php/Color_Bash_Prompt | |
GREEN="\[\033[0;32m\]" | |
CYAN="\[\033[0;36m\]" | |
BCYAN="\[\033[1;36m\]" | |
BLUE="\[\033[0;34m\]" | |
GRAY="\[\033[0;37m\]" | |
DKGRAY="\[\033[1;30m\]" | |
WHITE="\[\033[1;37m\]" | |
RED="\[\033[0;31m\]" | |
LIGHT_RED="\[\033[1;31;40m\]" | |
MAGENTA="\[\033[1;35;40m\]" | |
LIME="\[\033[1;32;40m\]" | |
YELLOW="\[\033[0;33m\]" | |
YELLRED="\[\033[1;33;41m\]" | |
LIGHT_GRAY="\[\033[0;37m\]" | |
# return color to Terminal setting for text color | |
DEFAULT="\[\033[0;39m\]" | |
#PS1="$CYAN}\h${GREEN} \w${RED} \$(gitify)${GREEN} >${LIGHT_GRAY} " | |
#PS1="$CYAN\$(date +%H:%M) $GREEN\$(rvm-prompt v)$DEFAULT[$GREEN\w$RED\$(gitify)$DEFAULT]$DEFAULT\$ " | |
PS1="$CYAN\$(date +%H:%M:%S) $GREEN\$(rvm-prompt v)$DEFAULT[$GREEN\W$RED\$(gitify)$DEFAULT]$DEFAULT\$ " | |
# http://superuser.com/questions/223308/name-terminal-tabs | |
# http://hints.macworld.com/article.php?story=20060502160527780 | |
# function settitle() { echo -ne "\033]0;$@\007"; } | |
# http://stackoverflow.com/questions/1371261/get-current-directory-name-without-full-path-in-bash-script | |
# This cd function is not compatible with RVM, so disable it for the time being. | |
# function cd() { command cd "$@"; settitle ${PWD##*/} $(gitify); } | |
function title() { echo -ne "\033]0;${PWD##*/} $(gitify)\007"; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment