Update to new plugin scheme

This commit is contained in:
joeperri95 2021-07-26 22:57:16 -04:00
commit e0203af1ed
14 changed files with 712 additions and 521 deletions

View file

@ -1,28 +1,80 @@
#!/usr/bin/env bash
# if option = 0 check for changes
# if option = 1 get branch
option=$1
path=$2
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
# Dracula Color Pallette
white='#f8f8f2'
gray='#44475a'
dark_gray='#282a36'
light_purple='#bd93f9'
dark_purple='#6272a4'
cyan='#8be9fd'
green='#50fa7b'
orange='#ffb86c'
red='#ff5555'
pink='#ff79c6'
yellow='#f1fa8c'
IFS=' ' read -r -a hide_status <<< $(get_tmux_option "@dracula-git-disable-status" "false")
IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-git-show-current-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" "")
changed_color=$red
up_to_date_color=$dark_gray
no_git_message=''
no_git_color=$dark_gray
# Get added, modified, updated and deleted files from git status
getChanges()
{
declare -i added=0;
declare -i modified=0;
declare -i updated=0;
declare -i deleted=0;
for i in $(git -C $path status -s)
do
case $i in
'A')
added+=1
;;
'M')
modified+=1
;;
'U')
updated+=1
;;
'D')
deleted+=1
;;
esac
done
output=""
[ $added -gt 0 ] && output+="${added}A"
[ $modified -gt 0 ] && output+=" ${modified}M"
[ $updated -gt 0 ] && output+=" ${updated}U"
[ $deleted -gt 0 ] && output+=" ${deleted}D"
echo $output
}
# getting the #{pane_current_path} from dracula.sh is no longer possible
getPaneDir()
{
nextone="false"
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}");
do
if [ "$nextone" == "true" ]; then
echo $i
return
fi
if [ "$i" == "1" ]; then
nextone="true"
fi
done
}
# check if the current or diff symbol is empty to remove ugly padding
checkEmptySymbol()
{
symbol=$1
if [ "$symbol" == "" ]; then
echo "true"
else
echo "false"
fi
}
# check to see if the current repo is not up to date with HEAD
checkForChanges()
{
if [ "$(checkForGitDir)" == "true" ]; then
@ -34,8 +86,9 @@ checkForChanges()
else
echo "false"
fi
}
}
# check if a git repo exists in the directory
checkForGitDir()
{
if [ "$(git -C $path rev-parse --abbrev-ref HEAD)" != "" ]; then
@ -45,40 +98,56 @@ checkForGitDir()
fi
}
assignColor()
{
# If there is a change set the foreground color
if [ "$(checkForGitDir)" == "true" ]; then
if [ "$(checkForChanges)" == "true" ]; then
echo $changed_color
else
echo $up_to_date_color
fi
# return branch name if there is one
getBranch()
{
if [ $(checkForGitDir) == "true" ]; then
echo $(git -C $path rev-parse --abbrev-ref HEAD)
else
echo $no_git_color
echo $no_repo_message
fi
}
getBranch()
{
# return branch name if there is one
if [ "$(git -C $path rev-parse --abbrev-ref HEAD)" != "" ]; then
echo "$(git -C $path rev-parse --abbrev-ref HEAD) "
# return the final message for the status bar
getMessage()
{
if [ $(checkForGitDir) == "true" ]; then
branch="$(getBranch)"
if [ $(checkForChanges) == "true" ]; then
changes="$(getChanges)"
if [ "${hide_status}" == "false" ]; then
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
echo "${changes} $branch"
else
echo "$diff_symbol ${changes} $branch"
fi
else
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
echo "$branch"
else
echo "$diff_symbol $branch"
fi
fi
else
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
echo "$branch"
else
echo "$current_symbol $branch"
fi
fi
else
echo $no_git_message
echo $no_repo_message
fi
}
main()
{
case $option in
0)
assignColor
;;
1)
getBranch
;;
esac
path=$(getPaneDir)
getMessage
}
#run main driver program