Created
January 15, 2011 02:49
-
-
Save sujal/780640 to your computer and use it in GitHub Desktop.
Bash Git Completion section in jasoncodes or my dotfiles
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
# add git status if available | |
if which git > /dev/null | |
then | |
GIT_COMPLETION_PATH="$(dirname $(realpath "$(which git)"))/../etc/bash_completion.d/git-completion.bash" | |
fi | |
if [ ! -f "$GIT_COMPLETION_PATH" ] | |
then | |
GIT_COMPLETION_PATH=$(first_file_match -f \ | |
"/usr/local/git/contrib/completion/git-completion.bash" \ | |
"/opt/local/share/doc/git-core/contrib/completion/git-completion.bash" \ | |
"/etc/bash_completion.d/git" \ | |
) | |
fi |
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
# begin awesome colour prompt.. | |
export PS1="" | |
# add rvm version@gemset | |
if [[ -n "$rvm_path" ]] | |
then | |
function __my_rvm_ps1() | |
{ | |
[[ -z "$rvm_ruby_string" ]] && return | |
if [[ -z "$rvm_gemset_name" && "$rvm_sticky_flag" -ne 1 ]] | |
then | |
[[ "$rvm_ruby_string" = "system" && ! -s "$rvm_path/config/alias" ]] && return | |
grep -q -F "default=$rvm_ruby_string" "$rvm_path/config/alias" && return | |
fi | |
local full=$( | |
"$rvm_path/bin/rvm-prompt" i v p g s | | |
sed \ | |
-e 's/jruby-jruby-/jruby-/' -e 's/ruby-//' \ | |
-e 's/-head/H/' \ | |
-e 's/-2[0-9][0-9][0-9]\.[0-9][0-9]//' \ | |
-e 's/-@/@/' -e 's/-$//') | |
[ -n "$full" ] && echo "$full " | |
} | |
export PS1="$PS1"'\[\033[01;30m\]$(__my_rvm_ps1)' | |
fi | |
# add user@host:path | |
export PS1="$PS1\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w" | |
function realpath() | |
{ | |
python -c 'import os,sys;print os.path.realpath(sys.argv[1])' "$@" | |
} | |
function first_file_match() | |
{ | |
local OP="$1" | |
shift | |
while [ $# -gt 0 ] | |
do | |
if [ $OP "$1" ] | |
then | |
echo "$1" | |
return 0 | |
fi | |
shift | |
done | |
return 1 | |
} | |
function realpath() | |
{ | |
python -c 'import os,sys;print os.path.realpath(sys.argv[1])' "$@" | |
} | |
# add git status if available | |
if which git > /dev/null | |
then | |
GIT_COMPLETION_PATH="$(dirname $(realpath "$(which git)"))/../etc/bash_completion.d/git-completion.bash" | |
fi | |
if [ ! -f "$GIT_COMPLETION_PATH" ] | |
then | |
GIT_COMPLETION_PATH=$(first_file_match -f \ | |
"/usr/local/git/contrib/completion/git-completion.bash" \ | |
"/opt/local/share/doc/git-core/contrib/completion/git-completion.bash" \ | |
"/etc/bash_completion.d/git" \ | |
) | |
fi | |
if [ -f "$GIT_COMPLETION_PATH" ] | |
then | |
source "$GIT_COMPLETION_PATH" | |
export GIT_PS1_SHOWDIRTYSTATE=1 | |
export GIT_PS1_SHOWSTASHSTATE=1 | |
export GIT_PS1_SHOWUNTRACKEDFILES=1 | |
export PS1="$PS1"'\[\033[01;33m\]$(__git_ps1 " (%s)")' | |
fi | |
# finish off the prompt | |
export PS1="$PS1"'\[\033[00m\]\$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment