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á <noname.nuno@gmail.com>
This commit is contained in:
parent
79521cc737
commit
eedd33771f
3 changed files with 38 additions and 8 deletions
|
@ -212,6 +212,12 @@ Hide untracked files from being displayed as local changes
|
||||||
set -g @dracula-git-no-untracked-files true
|
set -g @dracula-git-no-untracked-files true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Show remote tracking branch together with diverge/sync state
|
||||||
|
```bash
|
||||||
|
# default is false
|
||||||
|
set -g @dracula-git-show-remote-status true
|
||||||
|
```
|
||||||
|
|
||||||
#### weather options
|
#### weather options
|
||||||
|
|
||||||
Switch from default fahrenheit to celsius
|
Switch from default fahrenheit to celsius
|
||||||
|
|
|
@ -129,6 +129,7 @@ main()
|
||||||
|
|
||||||
if [ $plugin = "git" ]; then
|
if [ $plugin = "git" ]; then
|
||||||
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray")
|
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray")
|
||||||
|
tmux set-option -g status-right-length 250
|
||||||
script="#($current_dir/git.sh)"
|
script="#($current_dir/git.sh)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-git-show-curre
|
||||||
IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-git-show-diff-symbol" "!")
|
IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-git-show-diff-symbol" "!")
|
||||||
IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-git-no-repo-message" "")
|
IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-git-no-repo-message" "")
|
||||||
IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-git-no-untracked-files" "false")
|
IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-git-no-untracked-files" "false")
|
||||||
|
IFS=' ' read -r -a show_remote_status <<< $(get_tmux_option "@dracula-git-show-remote-status" "false")
|
||||||
|
|
||||||
# Get added, modified, updated and deleted files from git status
|
# Get added, modified, updated and deleted files from git status
|
||||||
getChanges()
|
getChanges()
|
||||||
|
@ -110,11 +111,30 @@ getBranch()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRemoteInfo()
|
||||||
|
{
|
||||||
|
base=$(git -C $path for-each-ref --format='%(upstream:short) %(upstream:track)' "$(git -C $path symbolic-ref -q HEAD)")
|
||||||
|
remote=$(echo "$base" | cut -d" " -f1)
|
||||||
|
out=""
|
||||||
|
|
||||||
|
if [ -n "$remote" ]; then
|
||||||
|
out="...$remote"
|
||||||
|
ahead=$(echo "$base" | grep -E -o 'ahead[ [:digit:]]+' | cut -d" " -f2)
|
||||||
|
behind=$(echo "$base" | grep -E -o 'behind[ [:digit:]]+' | cut -d" " -f2)
|
||||||
|
|
||||||
|
[ -n "$ahead" ] && out+=" +$ahead"
|
||||||
|
[ -n "$behind" ] && out+=" -$behind"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$out"
|
||||||
|
}
|
||||||
|
|
||||||
# return the final message for the status bar
|
# return the final message for the status bar
|
||||||
getMessage()
|
getMessage()
|
||||||
{
|
{
|
||||||
if [ $(checkForGitDir) == "true" ]; then
|
if [ $(checkForGitDir) == "true" ]; then
|
||||||
branch="$(getBranch)"
|
branch="$(getBranch)"
|
||||||
|
output=""
|
||||||
|
|
||||||
if [ $(checkForChanges) == "true" ]; then
|
if [ $(checkForChanges) == "true" ]; then
|
||||||
|
|
||||||
|
@ -122,25 +142,28 @@ getMessage()
|
||||||
|
|
||||||
if [ "${hide_status}" == "false" ]; then
|
if [ "${hide_status}" == "false" ]; then
|
||||||
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
|
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
|
||||||
echo "${changes} $branch"
|
output=$(echo "${changes} $branch")
|
||||||
else
|
else
|
||||||
echo "$diff_symbol ${changes} $branch"
|
output=$(echo "$diff_symbol ${changes} $branch")
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
|
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
|
||||||
echo "$branch"
|
output=$(echo "$branch")
|
||||||
else
|
else
|
||||||
echo "$diff_symbol $branch"
|
output=$(echo "$diff_symbol $branch")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
|
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
|
||||||
echo "$branch"
|
output=$(echo "$branch")
|
||||||
else
|
else
|
||||||
echo "$current_symbol $branch"
|
output=$(echo "$current_symbol $branch")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[ "$show_remote_status" == "true" ] && output+=$(getRemoteInfo)
|
||||||
|
echo "$output"
|
||||||
else
|
else
|
||||||
echo $no_repo_message
|
echo $no_repo_message
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue