blob: 988751c3f82220ec48f28fd6c6058eb44333360d (
plain)
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
|
# This checks if the current branch is ahead of
# or behind the remote branch with which it is tracked
# Source lib to get the function get_tmux_pwd
source "${TMUX_POWERLINE_DIR_LIB}/tmux_adapter.sh"
flat_symbol="⤚"
run_segment() {
tmux_path=$(get_tmux_cwd)
cd "$tmux_path"
stats=""
if [ -n "${git_stats=$(__parse_git_stats)}" ]; then
stats="$git_stats"
elif [ -n "${svn_stats=$(__parse_svn_stats)}" ]; then
stats="$svn_stats"
elif [ -n "${hg_stats=$(__parse_hg_stats)}" ]; then
stats="$hg_stats"
fi
if [ -n "$stats" ]; then
echo "${stats}"
fi
return 0
}
__parse_git_stats() {
type git >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
return
fi
# check if git
[[ -z $(git rev-parse --git-dir 2> /dev/null) ]] && return
tracking_branch=$(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD))
# creates global variables $1 and $2 based on left vs. right tracking
set -- $(git rev-list --left-right --count $tracking_branch...HEAD)
behind=$1
ahead=$2
# print out the information
if [[ $behind -gt 0 ]] ; then
local ret="↓ $behind"
fi
if [[ $ahead -gt 0 ]] ; then
local ret="${ret}↑ $ahead"
fi
echo "$ret"
}
__parse_hg_stats() {
type hg >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
return
fi
# not yet implemented
}
__parse_svn_stats() {
type svn >/dev/null 2>&1
if [ "$?" -ne 0 ]; then
return
fi
# not yet implemented
}
|