Merge pull request #104 from joeperri95/master

Issue #67 Add git functionality
This commit is contained in:
Ethan Edwards 2021-07-29 14:21:12 -04:00 committed by GitHub
commit 9705766ba2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 188 additions and 2 deletions

View file

@ -155,6 +155,32 @@ Enable military time
set -g @dracula-military-time true
```
#### git options
Hide details of git changes
```bash
set -g @dracula-git-disable-status true
```
Set symbol to use for when branch is up to date with HEAD
```bash
# default is ✓. Avoid using non unicode characters that bash uses like $, * and !
set -g @dracula-git-show-current-symbol ✓
```
Set symbol to use for when branch diverges from HEAD
```bash
# default is unicode !. Avoid bash special characters
set -g @dracula-git-show-diff-symbol !
```
Set symbol or message to use when the current pane has no git repo
```bash
# default is unicode no message
set -g @dracula-git-no-repo-message ""
```
#### weather options
Switch from default fahrenheit to celsius

View file

@ -18,6 +18,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul
* Day, date, time, timezone
* Current location based on network with temperature and forecast icon (if available)
* Network connection status, bandwith and SSID
* Git branch and status
* Battery percentage and AC power connection status
* Refresh rate control
* CPU usage

View file

@ -38,7 +38,6 @@ main()
pink='#ff79c6'
yellow='#f1fa8c'
# Handle left icon configuration
case $show_left_icon in
smiley)
@ -126,6 +125,12 @@ main()
tmux set-option -g status-right ""
for plugin in "${plugins[@]}"; do
if [ $plugin = "git" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray")
script="#($current_dir/git.sh)"
fi
if [ $plugin = "battery" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-battery-colors" "pink dark_gray")
script="#($current_dir/battery.sh)"
@ -188,7 +193,7 @@ main()
tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script"
fi
done
tmux set-option -ga status-right " "
# Window option

154
scripts/git.sh Executable file
View file

@ -0,0 +1,154 @@
#!/usr/bin/env bash
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
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" "")
# 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
if [ "$(git -C $path status -s)" != "" ]; then
echo "true"
else
echo "false"
fi
else
echo "false"
fi
}
# check if a git repo exists in the directory
checkForGitDir()
{
if [ "$(git -C $path rev-parse --abbrev-ref HEAD)" != "" ]; then
echo "true"
else
echo "false"
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_repo_message
fi
}
# 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_repo_message
fi
}
main()
{
path=$(getPaneDir)
getMessage
}
#run main driver program
main