-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.git_bashrc
123 lines (99 loc) · 3.75 KB
/
.git_bashrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#git aliases
#git config alias.ls 'diff --name-status'
#git config alias.ll "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --left-right"
alias gls='git diff --name-status'
alias gll="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative --left-right"
alias gllrm='git log --all --pretty=format: --name-only --diff-filter=D'
alias glist='for ref in $(git for-each-ref --sort=-committerdate --format="%(refname)" refs/heads/ refs/remotes ); do git log -n1 $ref --pretty=format:"%Cgreen%cr%Creset %C(yellow)%d%Creset %C(bold blue)<%an>%Creset%n" | cat ; done | awk '"'! a["'$0'"]++'"
alias gfiles='git show --pretty="format:" --name-only'
alias gc='git checkout'
alias gst='git status --ignore-submodules'
alias gb='git branch'
alias gpush='git push origin HEAD'
alias gfetch='git fetch -v'
alias gf='gfetch'
alias gfeature1='git_jenkins_feature_tag.sh feature1'
alias gfeature2='git_jenkins_feature_tag.sh feature2'
alias gintegration='git_jenkins_tags integration'
function git_show_branches() {
for branch in $(git branch -a); do
echo $'\n------------------- '${branch}' ----------------------------'
git --no-pager ll -n 2 ${branch}
done
echo
}
function git_info() {
if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then
# print informations
echo "git repo overview"
echo "-----------------"
echo
# print all remotes and thier details
for remote in $(git remote show); do
echo $remote:
git remote show $remote
echo
done
# print status of working repo
echo "status:"
if [ -n "$(git status -s 2> /dev/null)" ]; then
git status -s
else
echo "working directory is clean"
fi
# print at least 5 last log entries
echo
echo "log:"
git log -5 --oneline
echo
else
echo "you're currently not in a git repository"
fi
}
GIT_THEME_PROMPT_DIRTY='*'
#complex construct to have colors properly. I know...
#hash a string into an useful color
hash_color() {
echo $(($(cksum<<<"$*"|cut -f1 -d' ')%210+22))
}
#get the branch name and dirty state
git_prompt_info ()
{
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
echo -e "(${ref#refs/heads/}$(git_remote_dist)$(parse_git_dirty))"
}
#is branch dirty?
function parse_git_dirty {
if [[ -n "$(git status --porcelain --ignore-submodules 2> /dev/null)" ]]; then
echo -e "$GIT_THEME_PROMPT_DIRTY"
else
echo -e "$GIT_THEME_PROMPT_CLEAN"
fi
}
#distance to remote commit
git_remote_dist() {
local dist=$(git branch -v | sed -n 's/\* '$(git symbolic-ref HEAD | cut -d/ -f3)' [^[]*\[\([^]]*\)\].*/\1/p' | sed 's/ahead /+/;s/behind /-/')
[[ "$dist" ]] && echo "[${dist}]"
}
git_ps() {
if [[ "$_GIT_PS" ]]; then
[[ "$1" == "on" ]] && return
PS1="$_GIT_PS"
unset _GIT_PS
echo git prompt: off
else
[[ "$1" == "off" ]] && return
_GIT_PS="$PS1"
PS1="${PS1%\\$ } \[\033[1;38;5;232;48;5;\$(hash_color \$(git symbolic-ref HEAD 2> /dev/null)|| echo 0)m\]\$(git_prompt_info)\[\033[0m\] \$ "
#PS1="${PS1%\\$ } \[\033[38;5;228m\]\$(git_prompt_info)\[\033[00m\]\$ "
echo git prompt: on
fi
}
#turn git prompt on by default
#git_ps on >/dev/null
# Set config variables first
GIT_PROMPT_ONLY_IN_REPO=1
GIT_PROMPT_THEME=Solarized
# as last entry source the gitprompt script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$DIR/bash-git-prompt/gitprompt.sh"