generated from 2KAbhishek/bare-minimum
-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathgit.sh
executable file
ยท128 lines (110 loc) ยท 3.14 KB
/
git.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
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
124
125
126
127
128
#!/usr/bin/env bash
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$current_dir/../lib/utils.sh"
display_status=$(get_tmux_option '@tmux2k-git-display-status' 'false')
added_icon=$(get_tmux_option '@tmux2k-git-added-icon' '๏')
modified_icon=$(get_tmux_option '@tmux2k-git-modified-icon' '๏')
updated_icon=$(get_tmux_option '@tmux2k-git-updated-icon' '๏ด')
deleted_icon=$(get_tmux_option '@tmux2k-git-deleted-icon' '๏')
repo_icon=$(get_tmux_option '@tmux2k-git-repo-icon' '๏')
diff_icon=$(get_tmux_option '@tmux2k-git-diff-icon' '๏')
no_repo_icon=$(get_tmux_option '@tmux2k-git-no-repo-icon' '๎ฎ')
get_changes() {
declare -i added=0
declare -i modified=0
declare -i updated=0
declare -i deleted=0
for i in $(git -C "$path" status -s); do
case $i in
'A') added+=1 ;;
'M') modified+=1 ;;
'U') updated+=1 ;;
'D') deleted+=1 ;;
esac
done
output=""
[ $added -gt 0 ] && output+="${added} $added_icon"
[ $modified -gt 0 ] && output+=" ${modified} $modified_icon"
[ $updated -gt 0 ] && output+=" ${updated} $updated_icon"
[ $deleted -gt 0 ] && output+=" ${deleted} $deleted_icon"
echo "$output"
}
get_pane_dir() {
nextone="false"
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); do
if [ "$nextone" == "true" ]; then
echo "$i"
return
fi
if [ "$i" == "1" ]; then
nextone="true"
fi
done
}
check_empty_symbol() {
symbol=$1
if [ "$symbol" == "" ]; then
echo "true"
else
echo "false"
fi
}
check_for_changes() {
if [ "$(check_for_git_dir)" == "true" ]; then
if [ "$(git -C "$path" status -s)" != "" ]; then
echo "true"
else
echo "false"
fi
else
echo "false"
fi
}
check_for_git_dir() {
if [ "$(git -C "$path" rev-parse --abbrev-ref HEAD)" != "" ]; then
echo "true"
else
echo "false"
fi
}
get_branch() {
if [ $(check_for_git_dir) == "true" ]; then
printf "%.20s ๏ฆ" $(git -C "$path" rev-parse --abbrev-ref HEAD)
else
echo "$no_repo_icon"
fi
}
get_message() {
if [ $(check_for_git_dir) == "true" ]; then
branch="$(get_branch)"
if [ $(check_for_changes) == "true" ]; then
changes="$(get_changes)"
if [ "${display_status}" == "false" ]; then
if [ $(check_empty_symbol "$diff_icon") == "true" ]; then
echo "${changes} $branch"
else
echo "$diff_icon ${changes} $branch"
fi
else
if [ $(check_empty_symbol "$diff_icon") == "true" ]; then
echo "$branch"
else
echo "$diff_icon $branch"
fi
fi
else
if [ $(check_empty_symbol "$repo_icon") == "true" ]; then
echo "$branch"
else
echo "$repo_icon $branch"
fi
fi
else
echo "$no_repo_icon"
fi
}
main() {
path=$(get_pane_dir)
get_message
}
main