From 6cac0951d4d1d6cc1aaa214a77a6e46f654ad6ae Mon Sep 17 00:00:00 2001 From: Joe Perri Date: Sat, 5 Jun 2021 12:21:05 -0400 Subject: [PATCH] Add git functionality --- INSTALL.md | 1 + README.md | 1 + scripts/dracula.sh | 13 +++++-- scripts/git.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100755 scripts/git.sh diff --git a/INSTALL.md b/INSTALL.md index 4cacbdf..4c47c12 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -45,6 +45,7 @@ programs.tmux = { #### Configuration 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 network functionality: `set -g @dracula-show-network false` * Disable weather functionality: `set -g @dracula-show-weather false` diff --git a/README.md b/README.md index 41069a8..b94b68d 100644 --- a/README.md +++ b/README.md @@ -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 and SSID +* Git branch and status * Battery percentage and AC power connection status * Refresh rate control * CPU usage diff --git a/scripts/dracula.sh b/scripts/dracula.sh index bb4f5de..7ee22a6 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -20,6 +20,7 @@ main() # set configuration option variables 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_weather=$(get_tmux_option "@dracula-show-weather" true) show_fahrenheit=$(get_tmux_option "@dracula-show-fahrenheit" true) @@ -142,8 +143,13 @@ main() tmux set-option -g status-right "" 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 - 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} fi @@ -192,8 +198,11 @@ main() 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 - 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 if $show_ram_usage; then tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh) " diff --git a/scripts/git.sh b/scripts/git.sh new file mode 100755 index 0000000..a025691 --- /dev/null +++ b/scripts/git.sh @@ -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