-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitmux_update.sh
executable file
·61 lines (54 loc) · 2.13 KB
/
gitmux_update.sh
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
#!/bin/bash
#--------------------------------------------------------------------------------------------------------
# GITMUX UPDATE
#--------------------------------------------------------------------------------------------------------
#
# GITMUX UPDATE: Internal file for GITMUX plugin
# By 0phoff
# MIT license
#
#--------------------------------------------------------------------------------------------------------
## HELPER FUNCTIONS
function is_git_repo {
local is_working_tree=$(git rev-parse --is-inside-work-tree 2> /dev/null)
if [ "$is_working_tree" == true ]; then
return 0
else
return 1
fi
}
## MAIN FUNCTION
function main {
local current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
local dir=$(tmux display -p '#{pane_current_path}')
cd "$dir"
is_git_repo
if [ $? -eq 0 ]; then # Git repo
local git_fields=($("$current_dir/gitstatus.sh" "$dir" 2>/dev/null))
tmux setenv GITMUX_REPO 1
tmux setenv GITMUX_BRANCH "${git_fields[0]}"
tmux setenv GITMUX_COMMITS_AHEAD "${git_fields[1]}"
tmux setenv GITMUX_COMMITS_BEHIND "${git_fields[2]}"
tmux setenv GITMUX_REMOTE "${git_fields[3]}"
tmux setenv GITMUX_STAGED "${git_fields[4]}"
tmux setenv GITMUX_CONFLICTS "${git_fields[5]}"
tmux setenv GITMUX_CHANGED "${git_fields[6]}"
tmux setenv GITMUX_UNTRACKED "${git_fields[7]}"
tmux setenv GITMUX_STASHED "${git_fields[8]}"
tmux setenv GITMUX_CLEAN "${git_fields[9]}"
else # No git repo
tmux setenv GITMUX_REPO 0
tmux setenv -u GITMUX_BRANCH
tmux setenv -u GITMUX_REMOTE
tmux setenv -u GITMUX_COMMITS_AHEAD
tmux setenv -u GITMUX_COMMITS_BEHIND
tmux setenv -u GITMUX_STAGED
tmux setenv -u GITMUX_CONFLICTS
tmux setenv -u GITMUX_CHANGED
tmux setenv -u GITMUX_UNTRACKED
tmux setenv -u GITMUX_STASHED
tmux setenv -u GITMUX_CLEAN
fi
tmux refresh-client -S
}
main &