Add git functionality

This commit is contained in:
Joe Perri 2021-06-05 12:21:05 -04:00
parent f508a8907f
commit 6cac0951d4
4 changed files with 98 additions and 2 deletions

View file

@ -45,6 +45,7 @@ programs.tmux = {
#### Configuration #### Configuration
Customize the status bar by adding any of these lines to your .tmux.conf as desired: Customize the status bar by adding any of these lines to your .tmux.conf as desired:
* Disable git functionality: `set -g @dracula-show-git false`
* Disable battery functionality: `set -g @dracula-show-battery false` * Disable battery functionality: `set -g @dracula-show-battery false`
* Disable network functionality: `set -g @dracula-show-network false` * Disable network functionality: `set -g @dracula-show-network false`
* Disable weather functionality: `set -g @dracula-show-weather false` * Disable weather functionality: `set -g @dracula-show-weather false`

View file

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

View file

@ -20,6 +20,7 @@ main()
# set configuration option variables # set configuration option variables
show_battery=$(get_tmux_option "@dracula-show-battery" true) show_battery=$(get_tmux_option "@dracula-show-battery" true)
show_git=$(get_tmux_option "@dracula-show-git" true)
show_network=$(get_tmux_option "@dracula-show-network" true) show_network=$(get_tmux_option "@dracula-show-network" true)
show_weather=$(get_tmux_option "@dracula-show-weather" true) show_weather=$(get_tmux_option "@dracula-show-weather" true)
show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true) show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true)
@ -142,8 +143,13 @@ main()
tmux set-option -g status-right "" tmux set-option -g status-right ""
powerbg=${gray} powerbg=${gray}
if $show_git; then # git
tmux set-option -g status-right "#[fg=${green},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=#($current_dir/git.sh 0 #{pane_current_path}),bg=${green}] #($current_dir/git.sh 1 #{pane_current_path})"
powerbg=${green}
fi
if $show_battery; then # battery if $show_battery; then # battery
tmux set-option -g status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh)" tmux set-option -ga status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh)"
powerbg=${pink} powerbg=${pink}
fi fi
@ -192,8 +198,11 @@ main()
tmux set-option -g status-right "" tmux set-option -g status-right ""
if $show_git; then
tmux set-option -g status-right "#[fg=#($current_dir/git.sh 0 #{pane_current_path}),bg=${green}] #($current_dir/git.sh 1 #{pane_current_path})"
fi
if $show_battery; then # battery if $show_battery; then # battery
tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh) " tmux set-option -ga status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh) "
fi fi
if $show_ram_usage; then if $show_ram_usage; then
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh) " tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh) "

85
scripts/git.sh Executable file
View file

@ -0,0 +1,85 @@
#!/usr/bin/env bash
# if option = 0 check for changes
# if option = 1 get branch
option=$1
path=$2
# 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'
changed_color=$red
up_to_date_color=$dark_gray
no_git_message=''
no_git_color=$dark_gray
checkForChanges()
{
if [ "$(checkForGitDir)" == "true" ]; then
if [ "$(git -C $path status -s)" != "" ]; then
echo "true"
else
echo "false"
fi
else
echo "false"
fi
}
checkForGitDir()
{
if [ "$(git -C $path rev-parse --abbrev-ref HEAD)" != "" ]; then
echo "true"
else
echo "false"
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
else
echo $no_git_color
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) "
else
echo $no_git_message
fi
}
main()
{
case $option in
0)
assignColor
;;
1)
getBranch
;;
esac
}
#run main driver program
main