Skip to content

Commit eedd337

Browse files
committed
git: add remote info support
With this new option, we get information about which remote branch we're tracking. On top of this, we'll get information about ahead/behind commits when we diverged from remote. The output format will be in the form: 'local...remote +ahead -behind', where ahead and behind are the number of commits ahead and behind. This functionality is controlled by a new option called '@dracula-git-show-remote-status'. Note that for this to be properly displayed, we need to increase the size of the right status bar when the git plugin is enabled. In order to be easier to introduce the change, getMessage() was also a bit changed in order to be easier to append the remote info. Signed-off-by: Nuno Sá <[email protected]>
1 parent 79521cc commit eedd337

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
@@ -129,7 +129,8 @@ main()
129129

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

135136
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)