Skip to content

Commit b346d10

Browse files
Merge pull request #174 from nunojsa/dev/git-remote-info
2 parents ffc6ef8 + eedd337 commit b346d10

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

INSTALL.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ Hide untracked files from being displayed as local changes
212212
set -g @dracula-git-no-untracked-files true
213213
```
214214

215+
Show remote tracking branch together with diverge/sync state
216+
```bash
217+
# default is false
218+
set -g @dracula-git-show-remote-status true
219+
```
220+
215221
#### weather options
216222

217223
Switch from default fahrenheit to celsius

scripts/dracula.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ main()
130130

131131
if [ $plugin = "git" ]; then
132132
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray")
133-
script="#($current_dir/git.sh)"
133+
tmux set-option -g status-right-length 250
134+
script="#($current_dir/git.sh)"
134135
fi
135136

136137
if [ $plugin = "battery" ]; then

scripts/git.sh

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-git-show-curre
88
IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-git-show-diff-symbol" "!")
99
IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-git-no-repo-message" "")
1010
IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-git-no-untracked-files" "false")
11+
IFS=' ' read -r -a show_remote_status <<< $(get_tmux_option "@dracula-git-show-remote-status" "false")
1112

1213
# Get added, modified, updated and deleted files from git status
1314
getChanges()
@@ -110,37 +111,59 @@ getBranch()
110111
fi
111112
}
112113

114+
getRemoteInfo()
115+
{
116+
base=$(git -C $path for-each-ref --format='%(upstream:short) %(upstream:track)' "$(git -C $path symbolic-ref -q HEAD)")
117+
remote=$(echo "$base" | cut -d" " -f1)
118+
out=""
119+
120+
if [ -n "$remote" ]; then
121+
out="...$remote"
122+
ahead=$(echo "$base" | grep -E -o 'ahead[ [:digit:]]+' | cut -d" " -f2)
123+
behind=$(echo "$base" | grep -E -o 'behind[ [:digit:]]+' | cut -d" " -f2)
124+
125+
[ -n "$ahead" ] && out+=" +$ahead"
126+
[ -n "$behind" ] && out+=" -$behind"
127+
fi
128+
129+
echo "$out"
130+
}
131+
113132
# return the final message for the status bar
114133
getMessage()
115134
{
116135
if [ $(checkForGitDir) == "true" ]; then
117136
branch="$(getBranch)"
118-
137+
output=""
138+
119139
if [ $(checkForChanges) == "true" ]; then
120140

121141
changes="$(getChanges)"
122142

123143
if [ "${hide_status}" == "false" ]; then
124144
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
125-
echo "${changes} $branch"
145+
output=$(echo "${changes} $branch")
126146
else
127-
echo "$diff_symbol ${changes} $branch"
147+
output=$(echo "$diff_symbol ${changes} $branch")
128148
fi
129149
else
130150
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
131-
echo "$branch"
151+
output=$(echo "$branch")
132152
else
133-
echo "$diff_symbol $branch"
153+
output=$(echo "$diff_symbol $branch")
134154
fi
135155
fi
136156

137157
else
138158
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
139-
echo "$branch"
159+
output=$(echo "$branch")
140160
else
141-
echo "$current_symbol $branch"
161+
output=$(echo "$current_symbol $branch")
142162
fi
143163
fi
164+
165+
[ "$show_remote_status" == "true" ] && output+=$(getRemoteInfo)
166+
echo "$output"
144167
else
145168
echo $no_repo_message
146169
fi

0 commit comments

Comments
 (0)