Skip to content

Instantly share code, notes, and snippets.

@donaldducky
Created February 8, 2013 15:44
Show Gist options
  • Select an option

  • Save donaldducky/4739819 to your computer and use it in GitHub Desktop.

Select an option

Save donaldducky/4739819 to your computer and use it in GitHub Desktop.
function git_branch() {
git branch 2> /dev/null | grep ^* | cut -c 3-
}
function git_remote() {
if [ -z "$1" ]; then
return 0
fi
local git_repo=$1
local git_config=$(git rev-parse --show-toplevel)/.git/config
cat $git_config 2> /dev/null | grep "\"$git_repo\"" -A 2 | grep remote | cut -d ' ' -f 3
}
function my_prompt {
# need to record last exist status here before anymore shell commands are run
LAST_EXIT_STATUS="$?"
# http://jonisalonen.com/2012/your-bash-prompt-needs-this/
GOTO_FIRST_COLUMN="\[\033[G\]"
CLEAR=""
BLACK="\[\e[1;30m\]"
RED="\[\e[1;31m\]"
GREEN="\[\e[1;32m\]"
YELLOW="\[\e[1;33m\]"
BLUE="\[\e[1;34m\]"
MAGENTA="\[\e[1;35m\]"
CYAN="\[\e[1;36m\]"
WHITE="\[\e[1;37m\]"
RESET="\[\e[0m\]"
git_repo=$(git_branch)
git_remote=$(git_remote $git_repo)
git_prompt=""
if [ ${#git_repo} -ne 0 ]; then
#git_prompt=" \[\e[1;32m\]<git\[\e[0;31m\]<3\[\e[1;32m\]:$git_remote/$git_repo>\[\e[1;33m\]"
git_prompt=" ($git_remote/$git_repo)"
fi
# ✔ ✘
# \342\234\223 \342\234\227
EXIT_STATUS=""
if [ "$LAST_EXIT_STATUS" -eq 0 ]; then
EXIT_STATUS="${GREEN}✔"
else
EXIT_STATUS="${RED}✘"
fi
#export PS1="\n\[\033[G\]\[\e[1;33m\]\w $EXIT_STATUS$git_prompt \[\e[0m\]"
export PS1="\n${GOTO_FIRST_COLUMN}${WHITE}[${EXIT_STATUS}${WHITE}] ${YELLOW}\w${GREEN}$git_prompt ${RESET}"
# set iterm tab's title
processes=`jobs | wc -l | sed "s/ *//"`
process_line=""
if [ $processes -gt 0 ]; then
process_line="($processes) "
fi
echo -ne "\033]0;$process_line${USER}@${HOSTNAME%%.*}: ${PWD/#$HOME/~}\007"
}
if [[ "$TERM" == "xterm" || "$TERM" == "xterm-color" ]] ; then
export PROMPT_COMMAND="my_prompt"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment