-
Notifications
You must be signed in to change notification settings - Fork 8
/
bash_git
91 lines (80 loc) · 2.6 KB
/
bash_git
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
#############################################
# The place for all things bash/git
# Originally written by the venerable Estani
#############################################
#### GIT ####
$(hub --version >& /dev/null) && alias git=hub
alias gstat='git status'
alias gci='git commit'
alias gco='git checkout'
alias gls='git branch'
alias gitweb='git instaweb -d webrick'
alias gll="git log --graph --pretty=format:'%Cred%h%Creset -[%G?]%C(yellow)%d%Creset %s %Cgreen(%cD %cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"
ginfo() {
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
}
#complex construct to have colors properly. I know...
#hash a string into an useful color
hash_color() {
local val="$*"
val="${val//\//_}"
local color=$(($(cksum<<<"$*"|cut -f1 -d' ')%210+22))
echo $color
}
#----------------------------------------------------
# OLDER __git functions... (no longer directly used)
#----------------------------------------------------
#__git_ps1() {
# local b="$(git symbolic-ref HEAD 2>/dev/null)";
# if [ -n "$b" ]; then
# if [ -n "$1" ]; then
# printf "$1" "${b##refs/heads/}";
# else
# printf " (%s)" "${b##refs/heads/}";
# fi;
# 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 /-/') 2>/dev/null || return
[[ "$dist" ]] && echo "${dist}"
}
#is branch dirty?
GIT_THEME_PROMPT_DIRTY='*'
__parse_git_dirty() {
#if [[ -n "$(git status --porcelain --ignore-submodules 2> /dev/null)" ]]; then
if [[ -n "$(git diff --shortstat 2> /dev/null )" ]]; then
echo -e "$GIT_THEME_PROMPT_DIRTY"
else
echo -e "$GIT_THEME_PROMPT_CLEAN"
fi
}
__git_prompt_info() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
echo -e "$(__git_remote_dist)$(__parse_git_dirty)"
}