Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (90 sloc) 2.95 KB
[ -e ~/.stconfig-before ] && source ~/.stconfig-before
source ~/.commonrc
source ~/.aliases-common
sx() { screen -x "$1/"; }
# username completion for sx
_sx_comp() {
local screen_dir=/var/run/screen
local cur
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(perl -e 'while (<$ARGV[0]/S-$ARGV[1]*>) { m|$ARGV[0]/S-([^/]*)|; print "$1\n" }' $screen_dir $cur ) )
return 0
}
complete -F _sx_comp sx
# sb completion, returns a list of all local and remote branches as one list
_sb_comp() {
local current=~/src/st/current/.git
local cur
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(git --git-dir $current branch -a | perl -e 'while (<STDIN>){ s{^..(?:[^/]+/)?}{}g; print if (/^$ARGV[0]/); }' $cur) )
return 0
}
complete -F _sb_comp sb
# see http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html
COLOR_RESET="\[\033[0;39;49m\]"
COLOR_BRANCH="\[\033[0;1;32;44m\]"
COLOR_REPO="\[\033[0;1;33;44m\]"
COLOR_WORKDIR="\[\033[0;1;33;42m\]"
MOD_GLYPH="*"
STATE_GLYPH="|"
PS1_GLYPH="\$"
# shamelessly ripped off from http://github.com/rtomayko/git-sh/tree/master
# ... and Ubuntu's __git_ps1() in /etc/bash_completion.d/git
_git_prompt_color() {
local g r b rel loc mod
g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -z $g ]; then
export BASH_GIT_BRANCH=""
PS1="\u@\h:\w$PS1_GLYPH "
return
fi
if [ -d "$g/../.dotest" ]
then
if test -f "$g/../.dotest/rebasing"
then
r="${STATE_GLYPH}REBASE"
elif test -f "$g/../.dotest/applying"
then
r="${STATE_GLYPH}AM"
else
r="${STATE_GLYPH}AM/REBASE"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)"
elif [ -f "$g/.dotest-merge/interactive" ]
then
r="${STATE_GLYPH}REBASE-i"
b="$(cat "$g/.dotest-merge/head-name")"
elif [ -d "$g/.dotest-merge" ]
then
r="${STATE_GLYPH}REBASE-m"
b="$(cat "$g/.dotest-merge/head-name")"
elif [ -f "$g/MERGE_HEAD" ]
then
r="${STATE_GLYPH}MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
if [ -f "$g/BISECT_LOG" ]
then
r="${STATE_GLYPH}BISECTING"
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
then
if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
then
b="$(cut -c1-7 "$g/HEAD")..."
fi
fi
fi
b="${b##refs/heads/}" # make it a pretty name
export BASH_GIT_BRANCH="$b"
mod=`git ls-files --modified --deleted --others --exclude-standard 2>/dev/null | head -1`
if [ ! -z "$mod" ]; then
r="${MOD_GLYPH}$r"
fi
rel=$(git rev-parse --show-prefix 2>/dev/null)
rel="${rel%/}"
loc="${PWD%/$rel}"
PS1="\u@\h:${COLOR_BRANCH}${b}${r}${COLOR_RESET}!${COLOR_REPO}${loc/*\/}${COLOR_RESET}${COLOR_WORKDIR}${rel:+/$rel}${COLOR_RESET}${PS1_GLYPH} "
}
# Set this in your ${USER}_after file to use the git prompt:
# PROMPT_COMMAND=_git_prompt_color