Skip to content

Commit

Permalink
Merge pull request #174 from nunojsa/dev/git-remote-info
Browse files Browse the repository at this point in the history
  • Loading branch information
ethancedwards8 authored Feb 1, 2023
2 parents ffc6ef8 + eedd337 commit b346d10
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
6 changes: 6 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ Hide untracked files from being displayed as local changes
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

Switch from default fahrenheit to celsius
Expand Down
3 changes: 2 additions & 1 deletion scripts/dracula.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ main()

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

if [ $plugin = "battery" ]; then
Expand Down
37 changes: 30 additions & 7 deletions scripts/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 show_remote_status <<< $(get_tmux_option "@dracula-git-show-remote-status" "false")

# Get added, modified, updated and deleted files from git status
getChanges()
Expand Down Expand Up @@ -110,37 +111,59 @@ getBranch()
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
getMessage()
{
if [ $(checkForGitDir) == "true" ]; then
branch="$(getBranch)"

output=""

if [ $(checkForChanges) == "true" ]; then

changes="$(getChanges)"

if [ "${hide_status}" == "false" ]; then
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
echo "${changes} $branch"
output=$(echo "${changes} $branch")
else
echo "$diff_symbol ${changes} $branch"
output=$(echo "$diff_symbol ${changes} $branch")
fi
else
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
echo "$branch"
output=$(echo "$branch")
else
echo "$diff_symbol $branch"
output=$(echo "$diff_symbol $branch")
fi
fi

else
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
echo "$branch"
output=$(echo "$branch")
else
echo "$current_symbol $branch"
output=$(echo "$current_symbol $branch")
fi
fi

[ "$show_remote_status" == "true" ] && output+=$(getRemoteInfo)
echo "$output"
else
echo $no_repo_message
fi
Expand Down

0 comments on commit b346d10

Please sign in to comment.