Skip to content

Instantly share code, notes, and snippets.

@elia
Created October 12, 2011 09:08
Show Gist options
  • Save elia/1280714 to your computer and use it in GitHub Desktop.
Save elia/1280714 to your computer and use it in GitHub Desktop.
my git-prompt
#!/usr/bin/env bash
# coding: utf-8
# PROMPT
# more compact
# export PS1="\u@\h\w$ "
# export PS1=">: " # LOST style
# export PS1='> ' # Terminal Icon style
# Colored Terminal Icon style, with git project and branch when in git dir
# the $'...' solution prevents readline from messing up when walkin history:
# ( See:
# http://forums.macosxhints.com/showthread.php?t=90387
#
# $'...' instead of "...", to force \e to expand to ESC. It's a bash option
# whether that expansion happens inside "...", and it's usually safer if it
# doesn't, to guard against filenames containing escape sequences."
# )
clear=$'\[\e[0m\]'
red=$'\[\e[31m\]'
green=$'\[\e[32m\]'
yellow=$'\[\e[33m\]'
blue=$'\[\e[34m\]'
purple=$'\[\e[35m\]'
cyan=$'\[\e[36m\]'
gray=$'\[\e[37m\]'
# function git_dir {
# gitdir=`git pwd` && test -f "$gitdir/.git/HEAD" && basename $gitdir
# }
#
# function git_branch {
# if gitdir=`git pwd` && test -f "$gitdir/.git/HEAD"
# then
# git_head=`cat $gitdir/.git/HEAD`
# git_head="${git_head#ref\: refs\/heads\/}"
# git_sha=`git rev-parse --short $git_head 2> /dev/null`
# if test -n $git_sha
# then
# echo -n ":"$git_head
# else
# match=`expr $git_head : $git_sha`
#
# # If git_ref contains git_sha then use sha which is shorter
# if test $match = '0'
# then
# echo -n ":"$git_head
# else
# echo -n ":"$git_sha
# fi
# fi
# fi
# }
#
# function base_git_dir {
# gitdir=$(git_dir) && test -f "$gitdir/.git/HEAD" && basename $gitdir
# }
function __git_base_dir {
(__gitdir > /dev/null) && cd "$(__gitdir)" && cd .. && basename "$(pwd)"
}
function __bundler_dir () {
if [ $BUNDLE_GEMFILE ]; then
# ¤вβ◘♥♣
echo -n "¤ "
fi
}
export PS1="$cyan\$(__bundler_dir)$red\$(__git_base_dir)$green\$(__git_ps1 \":%s\")$yellow>$clear "
# To include this custom prompt put this file in "~/bin/" and and put the
# following lines in "~/.profile".
#
# # Include Custom prompt
# . ~/bin/custom-prompt.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment