|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 4 | +source $current_dir/utils.sh |
| 5 | + |
| 6 | +IFS=' ' read -r -a hide_status <<< $(get_tmux_option "@dracula-fossil-disable-status" "false") |
| 7 | +IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-fossil-show-current-symbol" "✓") |
| 8 | +IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-fossil-show-diff-symbol" "!") |
| 9 | +IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-fossil-no-repo-message" "") |
| 10 | +IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-fossil-no-untracked-files" "false") |
| 11 | +IFS=' ' read -r -a show_remote_status <<< $(get_tmux_option "@dracula-fossil-show-remote-status" "false") |
| 12 | + |
| 13 | +# Get added, modified, updated and deleted files from git status |
| 14 | +getChanges() |
| 15 | +{ |
| 16 | + declare -i added=0; |
| 17 | + declare -i modified=0; |
| 18 | + declare -i updated=0; |
| 19 | + declare -i deleted=0; |
| 20 | + |
| 21 | +for i in $(cd $path; fossil changes --differ|cut -f1 -d' ') |
| 22 | + |
| 23 | + do |
| 24 | + case $i in |
| 25 | + 'EXTRA') |
| 26 | + added+=1 |
| 27 | + ;; |
| 28 | + 'EDITED') |
| 29 | + modified+=1 |
| 30 | + ;; |
| 31 | + 'U') |
| 32 | + updated+=1 |
| 33 | + ;; |
| 34 | + 'DELETED') |
| 35 | + deleted+=1 |
| 36 | + ;; |
| 37 | + |
| 38 | + esac |
| 39 | + done |
| 40 | + |
| 41 | + output="" |
| 42 | + [ $added -gt 0 ] && output+="${added}A" |
| 43 | + [ $modified -gt 0 ] && output+=" ${modified}M" |
| 44 | + [ $updated -gt 0 ] && output+=" ${updated}U" |
| 45 | + [ $deleted -gt 0 ] && output+=" ${deleted}D" |
| 46 | + |
| 47 | + echo $output |
| 48 | +} |
| 49 | + |
| 50 | + |
| 51 | +# getting the #{pane_current_path} from dracula.sh is no longer possible |
| 52 | +getPaneDir() |
| 53 | +{ |
| 54 | + nextone="false" |
| 55 | + for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); |
| 56 | + do |
| 57 | + if [ "$nextone" == "true" ]; then |
| 58 | + echo $i |
| 59 | + return |
| 60 | + fi |
| 61 | + if [ "$i" == "1" ]; then |
| 62 | + nextone="true" |
| 63 | + fi |
| 64 | + done |
| 65 | +} |
| 66 | + |
| 67 | + |
| 68 | +# check if the current or diff symbol is empty to remove ugly padding |
| 69 | +checkEmptySymbol() |
| 70 | +{ |
| 71 | + symbol=$1 |
| 72 | + if [ "$symbol" == "" ]; then |
| 73 | + echo "true" |
| 74 | + else |
| 75 | + echo "false" |
| 76 | + fi |
| 77 | +} |
| 78 | + |
| 79 | +# check to see if the current repo is not up to date with HEAD |
| 80 | +checkForChanges() |
| 81 | +{ |
| 82 | + if [ "$(checkForFossilDir)" == "true" ]; then |
| 83 | + if [ "$(cd $path; fossil changes --differ)" != "" ]; then |
| 84 | + echo "true" |
| 85 | + else |
| 86 | + echo "false" |
| 87 | + fi |
| 88 | + else |
| 89 | + echo "false" |
| 90 | + fi |
| 91 | +} |
| 92 | + |
| 93 | +# check if a git repo exists in the directory |
| 94 | +checkForFossilDir() |
| 95 | +{ |
| 96 | + if [ -f ${path}/.fslckout ]; then |
| 97 | + echo "true" |
| 98 | + else |
| 99 | + echo "false" |
| 100 | + fi |
| 101 | +} |
| 102 | + |
| 103 | +# return branch name if there is one |
| 104 | +getBranch() |
| 105 | +{ |
| 106 | + if [ $(checkForFossilDir) == "true" ]; then |
| 107 | + echo $(cd $path; fossil branch current) |
| 108 | + else |
| 109 | + echo $no_repo_message |
| 110 | + fi |
| 111 | +} |
| 112 | + |
| 113 | +getRemoteInfo() |
| 114 | +{ |
| 115 | + base=$(cd $path; fossil branch current) |
| 116 | + remote=$(echo "$base" | cut -d" " -f1) |
| 117 | + out="" |
| 118 | + |
| 119 | + if [ -n "$remote" ]; then |
| 120 | + out="...$remote" |
| 121 | + ahead=$(echo "$base" | grep -E -o 'ahead[ [:digit:]]+' | cut -d" " -f2) |
| 122 | + behind=$(echo "$base" | grep -E -o 'behind[ [:digit:]]+' | cut -d" " -f2) |
| 123 | + |
| 124 | + [ -n "$ahead" ] && out+=" +$ahead" |
| 125 | + [ -n "$behind" ] && out+=" -$behind" |
| 126 | + fi |
| 127 | + |
| 128 | + echo "$out" |
| 129 | +} |
| 130 | + |
| 131 | +# return the final message for the status bar |
| 132 | +getMessage() |
| 133 | +{ |
| 134 | + if [ $(checkForFossilDir) == "true" ]; then |
| 135 | + branch="$(getBranch)" |
| 136 | + output="" |
| 137 | + |
| 138 | + if [ $(checkForChanges) == "true" ]; then |
| 139 | + |
| 140 | + changes="$(getChanges)" |
| 141 | + |
| 142 | + if [ "${hide_status}" == "false" ]; then |
| 143 | + if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then |
| 144 | + output=$(echo "${changes} $branch") |
| 145 | + else |
| 146 | + output=$(echo "$diff_symbol ${changes} $branch") |
| 147 | + fi |
| 148 | + else |
| 149 | + if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then |
| 150 | + output=$(echo "$branch") |
| 151 | + else |
| 152 | + output=$(echo "$diff_symbol $branch") |
| 153 | + fi |
| 154 | + fi |
| 155 | + |
| 156 | + else |
| 157 | + if [ $(checkEmptySymbol $current_symbol) == "true" ]; then |
| 158 | + output=$(echo "$branch") |
| 159 | + else |
| 160 | + output=$(echo "$current_symbol $branch") |
| 161 | + fi |
| 162 | + fi |
| 163 | + |
| 164 | + [ "$show_remote_status" == "true" ] && output+=$(getRemoteInfo) |
| 165 | + echo "$output" |
| 166 | + else |
| 167 | + echo $no_repo_message |
| 168 | + fi |
| 169 | +} |
| 170 | + |
| 171 | +main() |
| 172 | +{ |
| 173 | + path=$(getPaneDir) |
| 174 | + getMessage |
| 175 | +} |
| 176 | + |
| 177 | +#run main driver program |
| 178 | +main |
0 commit comments