-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux-statusline
executable file
·152 lines (127 loc) · 6.11 KB
/
tmux-statusline
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
## By Davoud Arsalani
## https://github.com/davoudarsalani/scripts
## https://github.com/davoudarsalani/scripts/blob/master/tmux-statusline
## https://raw.githubusercontent.com/davoudarsalani/scripts/master/tmux-statusline
## https://davoudarsalani.ir
case "$1" in
pwd )
printf '%s\n' "${2/$HOME/\~}" ;; ## '%-15s\n'
if_kaddy )
\grep -qi "$HOME/kaddy" <<< "$2" && printf 'KADDY \n' ;;
info )
if [ "$2" == "$HOME" ] || [ "$2" == "$HOME"/kaddy ]; then ## OR JUMP_1
printf '%s\n' '--'
exit
fi
source "$HOME"/main/scripts/gb-calculation
size="$(du -bs "$2" | awk '{print $1}')"
size="$(convert_byte "$size")"
directories_count="$(wc -l < <(find "$2" -mindepth 1 -maxdepth 1 -type d))"
files_count="$(wc -l < <(find "$2" -mindepth 1 -maxdepth 1 -type f))"
links_count="$(wc -l < <(find "$2" -mindepth 1 -maxdepth 1 -type l))"
(( links_count > 0 )) && links_count=" L:${links_count}" || links_count=''
printf '%s %s %s%s\n' "$size" "$directories_count" "$files_count" "$links_count" ;;
compare )
\grep -Eqi "^$HOME|\~" <<< "$2" && is_in_home='true'
[ "$is_in_home" ] || exit
\grep -qi "^$HOME$" <<< "$2" && is_home='true' ## OR [ "$2" == "$HOME" ] && is_home='true' as in JUMP_1
\grep -qi "^$HOME/\." <<< "$2" && is_in_hidden_dir='true'
# \grep -qi "^$HOME/downloads" <<< "$2" && is_in_downloads='true'
\grep -qi "^$HOME/kaddy" <<< "$2" && is_in_kaddy='true'
if [ ! "$is_home" ] && \
[ ! "$is_in_hidden_dir" ] && \
[ ! "$is_in_kaddy" ]; then
source "$HOME"/main/scripts/gb
source "$HOME"/main/scripts/gb-git
## ~/main/scripts -> ~/kaddy/scripts
kaddy_counterpart="$(get_kaddy_counterpart "$2")"
if [ ! -d "$kaddy_counterpart" ]; then
## if current directory has no counterpart in kaddy
no_counterpart='NO-KADDY-COUNTERPART '
printf '%s\n' "$no_counterpart"
else
## JUMP_1 the same structure in compare-home-with-kaddy script
## if hashes of HEAD in current directory and kaddy counterpart are different
if [ "$(if_git "$2")" == 'true' ]; then
[ "$(git_hash_head "$2")" == "$(git_hash_head "$kaddy_counterpart")" ] || {
head_='H '
}
[ "$(git_commits_ahead "$2")" == "$(git_commits_ahead "$kaddy_counterpart")" ] || {
ahead_='A '
}
fi
## JUMP_1 the same structure in compare-home-with-kaddy script
## if list of files/directories in current directory is different from the one in kaddy
if [ "$(\diff --brief <(\ls -A "$2") <(\ls -A "$kaddy_counterpart"))" ]; then ## NOTE do NOT add &>/dev/null to diff
ls_='LS '
fi
printf '%s%s%s\n' "$head_" "$ahead_" "$ls_"
fi
fi ;;
git )
source "$HOME"/main/scripts/gb-git
[ "$(if_git "$2")" == 'false' ] && exit
alert_sign='🔸' ## 🔸🔴
hash_head="$(git_hash_head "$2")"
relative_head="$(git_relative_head "$2")"
hash_last_commit="$(git_hash_last_commit "$2")"
[ "$hash_head" == "$hash_last_commit" ] || {
relative_last_commit="$(git_relative_last_commit "$2")"
is_head_detached="${alert_sign}${hash_last_commit}(${relative_last_commit})"
}
commits_count=" C:$(git_commits_count "$2")" ## Ⓒ
stts="$(git_status "$2")"
[ "$stts" ] && {
if_status=" $alert_sign"
mod_count="$(wc -l < <(printf '%s\n' "$stts" | \grep '^ M'))"
del_count="$(wc -l < <(printf '%s\n' "$stts" | \grep '^ D'))"
ren_count="$(wc -l < <(printf '%s\n' "$stts" | \grep '^ R'))"
add_count="$(wc -l < <(printf '%s\n' "$stts" | \grep '^ A'))"
unt_count="$(wc -l < <(printf '%s\n' "$stts" | \grep '^??'))"
upd_count="$(wc -l < <(printf '%s\n' "$stts" | \grep '^UU'))" ## updated but unmerged
sta_count="$(wc -l < <(printf '%s\n' "$stts" | \grep '^[MDAR] '))"
sta_m_count="$(wc -l < <(printf '%s\n' "$stts" | \grep '^[MDAR][MDAR]'))" ## staged but modified
(( mod_count > 0 )) && mod=" M:$mod_count" ##
(( del_count > 0 )) && del=" D:$del_count" ##
(( ren_count > 0 )) && ren=" R:$ren_count" ## Ⓡ
(( add_count > 0 )) && add=" A:$add_count" ##
(( unt_count > 0 )) && unt=" U:$unt_count" ##
(( upd_count > 0 )) && upd=" UU:$upd_count" ##
(( sta_count > 0 )) && sta=" S:$sta_count" ##
(( sta_m_count > 0 )) && sta_m=" SM:$sta_m_count" ##
}
commits_ahead="$(git_commits_ahead "$2")"
(( commits_ahead > 0 )) && commits_ahead=" A:${commits_ahead}" || commits_ahead='' ## Ⓐ
current_branch="$(git_current_branch "$2")"
branches_count="$(wc -l < <(git_branches_exclude_remote "$2"))"
(( branches_count > 1 )) && branch_info=" B:${current_branch}:${branches_count}"
remotes="$(git_remotes "$2")"
\grep -qi 'github' <<< "$remotes" && logo=' '
[ "$remotes" ] || is_local=' LOCAL'
printf 'H:%s:%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n' \
"$hash_head" \
"$relative_head" \
"$is_head_detached" \
"$commits_count" \
"$commits_ahead" \
"$branch_info" \
"$logo" \
"$is_local" \
\
"$if_status" \
"$mod" \
"$del" \
"$ren" \
"$add" \
"$unt" \
"$upd" \
"$sta" \
"$sta_m"
;;
if_dell )
## [CHECKING_HOST]
[ "$HOSTNAME" == 'acer' ] || printf '%s \n' "${HOSTNAME^^}" ;;
if_ssh )
[ "$SSH_CONNECTION" ] && printf 'SSH \n' ;;
esac