├── .gitignore ├── README.md └── oh-my-git.plugin.zsh /.gitignore: -------------------------------------------------------------------------------- 1 | ghpages 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ⚠️⚠️⚠️ **not anymore maintained** ⚠️⚠️⚠️ 2 | 3 | Similar, compeling and up-to-date alternative exist : 4 | 5 | - https://github.com/romkatv/powerlevel10k 6 | - https://github.com/starship/starship 7 | - https://github.com/fish-shell/fish-shell 8 | - ... 9 | 10 | # oh-my-zsh-git 11 | 12 | 13 | This plugin is an opinionated git prompt status, tailored for [**oh-my-zsh**](https://github.com/robbyrussell/oh-my-zsh). It is based on the work of [fabulous work](https://github.com/arialdomartini/oh-my-git/) of Arialdo Martini, but has been completely rewritten to avoid shortcoming and enable more features na despecially a nice oh-my-zsh integration. 14 | 15 | In other word it is _oh_my_git_ for _oh_my_zsh_. 16 | 17 | This derivative fork is taken from my pull request on his project [there](https://github.com/arialdomartini/oh-my-git/pull/22). 18 | 19 | ![oh-my-git in action](http://bric3.github.io/oh-my-zsh-git/images/oh-my-git.in.action.png) 20 | 21 | ## Reading the abstract 22 | 23 | This new git information script (`oh-my-git.plugin.zsh`) has a few bullet points 24 | 25 | * Show more information than usual git prompt status function here and there, thanks to Arialdo Martini for that 26 | * Configurable color and symbols (or string) 27 | * Configurable suffix and prefix 28 | * Toggleable per git repository (`git config --get oh-my-zsh.hide-status`) 29 | * Toggleable git repository symbol (`display_git_symbol`) 30 | * Git _off_ flags (like content in stash or untracked files) can be either displayed or not (`use_color_off`) Toggleable empty spaces when git flag is on or off (`print_unactive_flags_space`) 31 | * Git _off_ flags can be ommited in the status (with both `use_color_off=false` and `print_unactive_flags_space=false`) 32 | * Showing current git action (`REBASE-i`, `REBASE-m`, `REBASE`, `AM/REBASE`, `MERGING`, `BISECTING`, `CHERRY-PICKING`) 33 | * External configuration is optional, defaults are already configured 34 | 35 | On a technical ground 36 | 37 | * The shell script file and function are more human compatible. And this layout is directly working with oh-my-zsh plugins layout. 38 | * While designed with oh-my-zsh in mind it is does not depend on a specific shell 39 | * Doesn't leak variables 40 | 41 | 42 | ## Install the git prompt status 43 | 44 | This install assume the current shell is **ZSH** with [**oh-my-zsh**](https://github.com/robbyrussell/oh-my-zsh) already installed. 45 | 46 | Install a clone of this repository in oh-my-zsh plugin [custom folder](https://github.com/robbyrussell/oh-my-zsh/wiki/Customization). *Note it is possible to change the default custom directory of oh-my-zsh by redefining the `$ZSH_CUSTOM` in the `.zshrc` * 47 | 48 | ```bash 49 | mkdir -p $ZSH_CUSTOM/plugins 50 | git clone git@github.com:bric3/oh-my-git-4-oh-my-zsh.git $ZSH_CUSTOM/plugins/oh-my-git 51 | ``` 52 | 53 | This will make _oh-my-git_ available as a plugin for _oh-my-zsh_. Now you still need to activate it. In your `.zshrc` just activate the plugin by adding `oh-my-git` to the `plugins` variable : 54 | 55 | ```bash 56 | plugins=( 57 | # custom plugins 58 | git2 59 | oh-my-git 60 | 61 | # bundled plugins 62 | github 63 | osx 64 | mosh 65 | ... 66 | ``` 67 | 68 | Finally use the main function of the plugin `oh_my_git_info` in the variables in your theme `PROMPT` or `RPROMPT`. For example to place it in the right part of your theme use the `RPROMPT` environment variable : 69 | 70 | ```bash 71 | RPROMPT='$(oh_my_git_info)' 72 | ``` 73 | 74 | 75 | ## Customize it 76 | 77 | In order to customize either the symbol, the color or if some symbol should be displayed define on of these varaible in your oh-my-zsh theme. 78 | 79 | For example in your theme set the following variables to have a prompt info that will look like : `[(master ᄉ origin)]` 80 | 81 | ```bash 82 | # oh-my-git config 83 | omg_prefix=" %{%B%F{green}%}[%{%f%k%b%}" 84 | omg_suffix="%{%B%F{green}%}]%{%f%k%b%}" 85 | 86 | display_git_symbol=false 87 | display_git_current_action=left 88 | print_unactive_flags_space=false 89 | ``` 90 | 91 | Here is the possible variables and flags with their default value 92 | 93 | 94 | ### Options 95 | 96 | option variable | value 97 | ---------------------------------- | ---------- 98 | display_has_upstream | `false` 99 | display_tag | `false` 100 | display_tag_name | `true` 101 | use_color_off | `false` 102 | print_unactive_flags_space | `true` 103 | display_git_symbol | `true` 104 | display_git_current_action | `false` 105 | 106 | ### Symbols and related colors 107 | 108 | symbol and color variable | value 109 | ---------------------------------- | ---------- 110 | is_a_git_repo_symbol | `±` 111 | is_a_git_repo_color | `$violet` 112 | has_untracked_files_symbol | `∿` 113 | has_untracked_files_color | `$red` 114 | has_adds_symbol | `+` 115 | has_adds_color | `$yellow` 116 | has_deletions_symbol | `-` 117 | has_deletions_color | `$red` 118 | has_deletions_cached_symbol | `✖` 119 | has_deletions_cached_color | `$yellow` 120 | has_modifications_symbol | `✎` 121 | has_modifications_color | `$red` 122 | has_modifications_cached_symbol | `☲` 123 | has_modifications_cached_color | `$yellow` 124 | ready_to_commit_symbol | `→` 125 | ready_to_commit_color | `$green` 126 | is_on_a_tag_symbol | `⌫` 127 | is_on_a_tag_color | `$yellow` 128 | needs_to_merge_symbol | `ᄉ` 129 | needs_to_merge_color | `$yellow` 130 | has_upstream_symbol | `⇅` 131 | has_upstream_color | `$on` 132 | has_no_upstream_color | `$on` 133 | detached_symbol | `⚯` 134 | detached_color | `$red` 135 | detached_current_commit_color | `$on` 136 | can_fast_forward_symbol | `»` 137 | can_fast_forward_color | `$on` 138 | has_diverged_symbol | `Ⴤ` 139 | has_diverged_color | `$red` 140 | rebase_tracking_branch_symbol | `↶` 141 | rebase_tracking_branch_color | `$reset` 142 | merge_tracking_branch_symbol | `ᄉ` 143 | merge_tracking_branch_color | `$reset` 144 | should_push_symbol | `↑` 145 | should_push_color | `$on` 146 | has_stashes_symbol | `★` 147 | has_stashes_color | `$yellow` 148 | commits_behind_symbol | `-` 149 | commits_behind_color | `$reset` 150 | commits_ahead_symbol | `+` 151 | commits_ahead_color | `$reset` 152 | current_branch_color | `$green` 153 | tag_name_color | `$yellow` 154 | 155 | 156 | ### Default colors 157 | 158 | For the ZSH shell, the default values are the [ZSH prompt escape sequences](http://zsh.sourceforge.net/Doc/Release/Prompt-Expansion.html) which are correctly interpreted to match the terminal width. 159 | 160 | display variable | value 161 | ---------------------------------- | ---------- 162 | on | `%B` 163 | off | `%b` 164 | green | `%F{green}` 165 | red | `%F{red}` 166 | violet | `%F{magenta}` 167 | yellow | `%F{yellow}` 168 | reset | `%{%f%k%b%}` 169 | 170 | 171 | 172 | ## Show a demo 173 | 174 | A rather long demo with [asciinema](https://asciinema.org/a/10426) 175 | 176 | [![asciicast](https://asciinema.org/a/10426.png)](https://asciinema.org/a/10426) 177 | -------------------------------------------------------------------------------- /oh-my-git.plugin.zsh: -------------------------------------------------------------------------------- 1 | # Based on the work of fabulous work of Arialdo Martini 2 | # https://github.com/arialdomartini/oh-my-git/ 3 | # 4 | # This derivative fork is taken from my pull request on his project here : https://github.com/arialdomartini/oh-my-git/pull/22 5 | # 6 | # ABSTRACT 7 | # ======== 8 | # 9 | # This new git information script (`oh-my-git.plugin.zsh`) 10 | # * is not rely on a prompt shell anymore 11 | # * is using configurable color codes 12 | # * doesn't leak variables 13 | # * does not depend on external configuration 14 | # * offers configurable color codes per symbol 15 | # * has a more understandable name, that can be easily used in another context (I'm using it in my own crafted oh-my-zsh theme, though it's named `oh-my-git.plugin.zsh`) 16 | # * offers suffix and prefix config 17 | # * enables toggling of the display of the git repository symbol (`display_git_symbol`) 18 | # * enables to toggle if empty spaces for _off_ flags will be displayed (`use_color_off=false` and flag is off, toggable with `print_unactive_flags_space`) 19 | # * enables toggling per git repository config `git config --get oh-my-zsh.hide-status` 20 | # * displays current git action (`REBASE-i`, `REBASE-m`, `REBASE`, `AM/REBASE`, `MERGING`, `BISECTING`, `CHERRY-PICKING`) 21 | # 22 | 23 | 24 | function oh_my_git_info { 25 | local oh_my_git_string=""; 26 | 27 | # Colors 28 | if [ -n "$ZSH_VERSION" ]; then 29 | local on="${omg_on:-%B}"; 30 | local off="${omg_off:-%b}"; 31 | local red="${omg_red:-%F{red}}"; 32 | local green="${omg_green:-%F{green}}"; 33 | local yellow="${omg_yellow:-%F{yellow}}"; 34 | local violet="${omg_violet:-%F{magenta}}"; 35 | local reset="${omg_reset:-%{%f%k%b%}}"; 36 | else 37 | local on="${omg_on:-\[\e[0;37m\]}"; 38 | local off="${omg_off:-\[\e[1;30m\]}"; 39 | local red="${omg_red:-\[\e[0;31m\]}"; 40 | local green="${omg_green:-\[\e[0;32m\]}"; 41 | local yellow="${omg_yellow:-\[\e[0;33m\]}"; 42 | local violet="${omg_violet:-\[\e[0;35m\]}"; 43 | local reset="${omg_reset:-\[\e[0m\]}"; 44 | fi 45 | 46 | # Some unicode chars : ⚯᠁ះ⊶☍⧲⧬⧂»⇅〜✚-⫘ 47 | # ⚙ ♨ ♋ ㍖♫𝄢♬♪𝄆𝄇𝄈𝄐〖⦖〘〙》〰︴෴⸚⌁⌀⌖𝌁⿓⎃☢☣☠☤⚕☸⚔☉♁☄⚚⚛ ⌘⎋⏎⌤⌥⌃⌅⇧⇪⌫⌦⇥⬆⬇⬍✔✘✖✭☲✎⌫ᄉ⇅⚯»Ⴤ↶↑± 48 | # ⇪ ⇫ ⇬ ⇭ ⇮ ⇯ ⇳ ⥮ ⥯ ↥ ↧ ↞ ↠ ↟ ↡ ➟ ➠ 49 | # Symbols 50 | if [[ -z "${is_a_git_repo_symbol}" ]]; then local is_a_git_repo_symbol="±"; fi 51 | if [[ -z "${is_a_git_repo_color}" ]]; then local is_a_git_repo_color="$violet"; fi 52 | if [[ -z "${has_untracked_files_symbol}" ]]; then local has_untracked_files_symbol="〜"; fi 53 | if [[ -z "${has_untracked_files_color}" ]]; then local has_untracked_files_color="$red"; fi 54 | if [[ -z "${has_adds_symbol}" ]]; then local has_adds_symbol="✚"; fi 55 | if [[ -z "${has_adds_color}" ]]; then local has_adds_color="$yellow"; fi 56 | if [[ -z "${has_deletions_symbol}" ]]; then local has_deletions_symbol="-"; fi 57 | if [[ -z "${has_deletions_color}" ]]; then local has_deletions_color="$red"; fi 58 | if [[ -z "${has_deletions_cached_symbol}" ]]; then local has_deletions_cached_symbol="✘"; fi 59 | if [[ -z "${has_deletions_cached_color}" ]]; then local has_deletions_cached_color="$yellow"; fi 60 | if [[ -z "${has_modifications_symbol}" ]]; then local has_modifications_symbol="✎"; fi 61 | if [[ -z "${has_modifications_color}" ]]; then local has_modifications_color="$red"; fi 62 | if [[ -z "${has_modifications_cached_symbol}" ]]; then local has_modifications_cached_symbol="☲"; fi 63 | if [[ -z "${has_modifications_cached_color}" ]]; then local has_modifications_cached_color="$yellow"; fi 64 | if [[ -z "${ready_to_commit_symbol}" ]]; then local ready_to_commit_symbol="✔"; fi 65 | if [[ -z "${ready_to_commit_color}" ]]; then local ready_to_commit_color="$green"; fi 66 | if [[ -z "${is_on_a_tag_symbol}" ]]; then local is_on_a_tag_symbol="⌫"; fi 67 | if [[ -z "${is_on_a_tag_color}" ]]; then local is_on_a_tag_color="$yellow"; fi 68 | if [[ -z "${needs_to_merge_symbol}" ]]; then local needs_to_merge_symbol="ᄉ"; fi 69 | if [[ -z "${needs_to_merge_color}" ]]; then local needs_to_merge_color="$yellow"; fi 70 | if [[ -z "${has_upstream_symbol}" ]]; then local has_upstream_symbol="⬍"; fi 71 | if [[ -z "${has_upstream_color}" ]]; then local has_upstream_color="$on"; fi 72 | if [[ -z "${has_no_upstream_color}" ]]; then local has_no_upstream_color="$on"; fi 73 | if [[ -z "${detached_symbol}" ]]; then local detached_symbol="⫘"; fi 74 | if [[ -z "${detached_color}" ]]; then local detached_color="$red"; fi 75 | if [[ -z "${detached_current_commit_color}" ]]; then local detached_current_commit_color="$on"; fi 76 | if [[ -z "${can_fast_forward_symbol}" ]]; then local can_fast_forward_symbol="⋙"; fi 77 | if [[ -z "${can_fast_forward_color}" ]]; then local can_fast_forward_color="$on"; fi 78 | if [[ -z "${has_diverged_symbol}" ]]; then local has_diverged_symbol="Ⴤ"; fi 79 | if [[ -z "${has_diverged_color}" ]]; then local has_diverged_color="$red"; fi 80 | if [[ -z "${rebase_tracking_branch_symbol}" ]]; then local rebase_tracking_branch_symbol="⬿"; fi 81 | if [[ -z "${rebase_tracking_branch_color}" ]]; then local rebase_tracking_branch_color="$reset"; fi 82 | if [[ -z "${merge_tracking_branch_symbol}" ]]; then local merge_tracking_branch_symbol="ᄉ"; fi 83 | if [[ -z "${merge_tracking_branch_color}" ]]; then local merge_tracking_branch_color="$reset"; fi 84 | if [[ -z "${should_push_symbol}" ]]; then local should_push_symbol="⤊"; fi 85 | if [[ -z "${should_push_color}" ]]; then local should_push_color="$on"; fi 86 | if [[ -z "${has_stashes_symbol}" ]]; then local has_stashes_symbol="★"; fi 87 | if [[ -z "${has_stashes_color}" ]]; then local has_stashes_color="$yellow"; fi 88 | if [[ -z "${commits_behind_symbol}" ]]; then local commits_behind_symbol="-"; fi 89 | if [[ -z "${commits_behind_color}" ]]; then local commits_behind_color="$reset"; fi 90 | if [[ -z "${commits_ahead_symbol}" ]]; then local commits_ahead_symbol="+"; fi 91 | if [[ -z "${commits_ahead_color}" ]]; then local commits_ahead_color="$reset"; fi 92 | if [[ -z "${current_branch_color}" ]]; then local current_branch_color="$green"; fi 93 | if [[ -z "${tag_name_color}" ]]; then local tag_name_color="$yellow"; fi 94 | 95 | 96 | # flags 97 | if [[ -z "${display_has_upstream}" ]]; then local display_has_upstream=false; fi 98 | if [[ -z "${display_tag}" ]]; then local display_tag=false; fi 99 | if [[ -z "${display_tag_name}" ]]; then local display_tag_name=true; fi 100 | if [[ -z "${use_color_off}" ]]; then local use_color_off=false; fi 101 | if [[ -z "${print_unactive_flags_space}" ]]; then local print_unactive_flags_space=true; fi 102 | if [[ -z "${display_git_symbol}" ]]; then local display_git_symbol=true; fi 103 | if [[ -z "${display_git_current_action}" ]]; then local display_git_current_action=false; fi 104 | 105 | # Early return if git repo is configured to be hidden 106 | if [[ "$(git config --get oh-my-zsh.hide-status)" == "1" ]]; then return; fi 107 | # if [[ "$(git config --get oh-my-git.enabled)" != "true" ]]; then return; fi 108 | 109 | # Git info 110 | local current_commit_hash=$(git rev-parse HEAD 2> /dev/null) 111 | if [[ -n $current_commit_hash ]]; then local is_a_git_repo=true; else local is_a_git_repo=false; fi 112 | 113 | if [[ $is_a_git_repo == true ]]; then 114 | local current_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) 115 | if [[ $current_branch == 'HEAD' ]]; then local detached=true; else local detached=false; fi 116 | 117 | local number_of_logs=$(git log --pretty=oneline -n1 2> /dev/null | wc -l | tr -d ' ') 118 | if [[ $number_of_logs -eq 0 ]]; then 119 | local just_init=true 120 | else 121 | local upstream=$(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} 2> /dev/null) 122 | if [[ -n "${upstream}" && "${upstream}" != "@{upstream}" ]]; then local has_upstream=true; else local has_upstream=false; fi 123 | 124 | local git_status="$(git status --porcelain 2> /dev/null)" 125 | 126 | if [[ $git_status =~ ($'\n'|^).M ]]; then local has_modifications=true; else local has_modifications=false; fi 127 | 128 | if [[ $git_status =~ ($'\n'|^)M ]]; then local has_modifications_cached=true; else local has_modifications_cached=false; fi 129 | 130 | if [[ $git_status =~ ($'\n'|^)A ]]; then local has_adds=true; else local has_adds=false; fi 131 | 132 | if [[ $git_status =~ ($'\n'|^).D ]]; then local has_deletions=true; else local has_deletions=false; fi 133 | 134 | if [[ $git_status =~ ($'\n'|^)D ]]; then local has_deletions_cached=true; else local has_deletions_cached=false; fi 135 | 136 | if [[ $git_status =~ ($'\n'|^)[MAD] && ! $git_status =~ ($'\n'|^).[MAD\?] ]]; then local ready_to_commit=true; else local ready_to_commit=false; fi 137 | 138 | local number_of_untracked_files=`echo $git_status | grep -c "^??"` 139 | if [[ $number_of_untracked_files -gt 0 ]]; then local has_untracked_files=true; else local has_untracked_files=false; fi 140 | 141 | local tag_at_current_commit=$(git describe --exact-match --tags $current_commit_hash 2> /dev/null) 142 | if [[ -n $tag_at_current_commit ]]; then local is_on_a_tag=true; else local is_on_a_tag=false; fi 143 | 144 | local has_diverged=false 145 | local can_fast_forward=false 146 | 147 | if [[ $has_upstream == true ]]; then 148 | local commits_diff="$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} 2> /dev/null)" 149 | local commits_ahead=$(grep -c "^<" <<< "$commits_diff"); 150 | local commits_behind=$(grep -c "^>" <<< "$commits_diff"); 151 | fi 152 | if [[ $commits_ahead -gt 0 && $commits_behind -gt 0 ]]; then 153 | local has_diverged=true 154 | fi 155 | if [[ $commits_ahead -eq 0 && $commits_behind -gt 0 ]]; then 156 | local can_fast_forward=true 157 | fi 158 | 159 | local will_rebase=$(git config --get branch.${current_branch}.rebase 2> /dev/null) 160 | 161 | if [[ -f ${GIT_DIR:-.git}/refs/stash ]]; then 162 | local number_of_stashes=$(wc -l 2> /dev/null < ${GIT_DIR:-.git}/refs/stash | tr -d ' ') 163 | else 164 | local number_of_stashes=0 165 | fi 166 | if [[ $number_of_stashes -gt 0 ]]; then local has_stashes=true; else local has_stashes=false; fi 167 | fi 168 | fi 169 | 170 | 171 | if [[ ${is_a_git_repo} == true ]]; then 172 | oh_my_git_string=" 173 | $(echo_if_true ${display_git_symbol} ${is_a_git_repo_symbol} ${is_a_git_repo_color}) 174 | 175 | $(echo_if_true ${has_stashes} ${has_stashes_symbol} ${has_stashes_color}) 176 | $(echo_if_true ${has_untracked_files} ${has_untracked_files_symbol} ${has_untracked_files_color}) 177 | $(echo_if_true ${has_adds} ${has_adds_symbol} ${has_adds_color}) 178 | 179 | $(echo_if_true ${has_deletions} ${has_deletions_symbol} ${has_deletions_color}) 180 | $(echo_if_true ${has_deletions_cached} ${has_deletions_cached_symbol} ${has_deletions_cached_color}) 181 | 182 | $(echo_if_true ${has_modifications} ${has_modifications_symbol} ${has_modifications_color}) 183 | $(echo_if_true ${has_modifications_cached} ${has_modifications_cached_symbol} ${has_modifications_cached_color}) 184 | $(echo_if_true ${ready_to_commit} ${ready_to_commit_symbol} ${ready_to_commit_color}) 185 | 186 | $(echo_if_true ${detached} ${detached_symbol} ${detached_color}) 187 | "; 188 | 189 | if [[ ${display_has_upstream} == true ]]; then 190 | oh_my_git_string+="$(echo_if_true ${has_upstream} ${has_upstream_symbol} ${has_upstream_color})"; 191 | fi 192 | 193 | if [[ ${detached} == true ]]; then 194 | if [[ ${just_init} == true ]]; then 195 | oh_my_git_string+="${detached_color}detached${reset}"; 196 | else 197 | oh_my_git_string+="${detached_current_commit_color}(${current_commit_hash:0:7})${reset}"; 198 | fi 199 | else 200 | if [[ $has_upstream == true ]]; then 201 | if [[ ${will_rebase} == true ]]; then 202 | type_of_upstream="${rebase_tracking_branch_color}${rebase_tracking_branch_symbol}${reset}"; 203 | else 204 | type_of_upstream="${merge_tracking_branch_color}${merge_tracking_branch_symbol}${reset}"; 205 | fi 206 | 207 | if [[ ${has_diverged} == true ]]; then 208 | oh_my_git_string+=" 209 | ${commits_behind_color}${commits_behind_symbol}${commits_behind}${reset} 210 | ${has_diverged_color}${has_diverged_symbol}${reset} 211 | ${commits_ahead_color}${commits_ahead_symbol}${commits_ahead}${reset} 212 | "; 213 | else 214 | if [[ ${commits_behind} -gt 0 ]]; then 215 | oh_my_git_string+=" 216 | ${can_fast_forward_color}${commits_behind_symbol}${commits_behind} ${can_fast_forward_symbol}${reset} 217 | "; 218 | fi 219 | if [[ ${commits_ahead} -gt 0 ]]; then 220 | oh_my_git_string+=" 221 | ${should_push_color}${should_push_symbol} ${commits_ahead_symbol}${commits_ahead} ${reset} 222 | "; 223 | fi 224 | fi 225 | 226 | oh_my_git_string+=" 227 | (${current_branch_color}${current_branch}${reset} 228 | ${type_of_upstream} 229 | ${upstream//\/$current_branch/})"; 230 | 231 | else 232 | oh_my_git_string+=" 233 | ${has_no_upstream_color}(${current_branch_color}${current_branch}${reset}${has_no_upstream_color})${reset} 234 | "; 235 | fi 236 | fi 237 | 238 | if [[ ${display_tag} == true ]]; then 239 | oh_my_git_string+=" ${is_on_a_tag_color}${is_on_a_tag_symbol}${reset}"; 240 | fi 241 | if [[ ${display_tag_name} == true && ${is_on_a_tag} == true ]]; then 242 | oh_my_git_string+=" ${tag_name_color}[${tag_at_current_commit}]${reset}"; 243 | fi 244 | 245 | if [[ $display_git_current_action == "left" ]]; then 246 | oh_my_git_string="$(git_current_action $red $reset) ${oh_my_git_string}"; 247 | elif [[ $display_git_current_action == "right" ]]; then 248 | oh_my_git_string="${oh_my_git_string} $(git_current_action $red $reset)"; 249 | fi 250 | 251 | # clean up leading and trailing spaces, (prefix and suffix might add them if wanted) 252 | oh_my_git_string=$(trim "$oh_my_git_string"); 253 | 254 | oh_my_git_string="${omg_prefix}${oh_my_git_string}${reset}${omg_suffix}"; 255 | fi 256 | 257 | # collapse contiguous spaces including new lines 258 | echo $(echo "${oh_my_git_string}") 259 | } 260 | 261 | 262 | # based on bash __git_ps1 to read branch and current action 263 | function git_current_action () { 264 | local info="$(git rev-parse --git-dir 2>/dev/null)" 265 | if [ -n "$info" ]; then 266 | local action 267 | if [ -f "$info/rebase-merge/interactive" ] 268 | then 269 | action=${is_rebasing_interactively:-"REBASE-i"} 270 | elif [ -d "$info/rebase-merge" ] 271 | then 272 | action=${is_rebasing_merge:-"REBASE-m"} 273 | else 274 | if [ -d "$info/rebase-apply" ] 275 | then 276 | if [ -f "$info/rebase-apply/rebasing" ] 277 | then 278 | action=${is_rebasing:-"REBASE"} 279 | elif [ -f "$info/rebase-apply/applying" ] 280 | then 281 | action=${is_applying_mailbox_patches:-"|AM"} 282 | else 283 | action=${is_rebasing_mailbox_patches:-"AM/REBASE"} 284 | fi 285 | elif [ -f "$info/MERGE_HEAD" ] 286 | then 287 | action=${is_merging:-"MERGING"} 288 | elif [ -f "$info/CHERRY_PICK_HEAD" ] 289 | then 290 | action=${is_cherry_picking:-"CHERRY-PICKING"} 291 | elif [ -f "$info/BISECT_LOG" ] 292 | then 293 | action=${is_bisecting:-"BISECTING"} 294 | fi 295 | fi 296 | 297 | if [[ -n $action ]]; then printf "%s" "${1-}$action${2-}"; fi 298 | fi 299 | } 300 | 301 | 302 | function echo_if_true { 303 | flag=$1 304 | symbol=$2 305 | if [[ -n $3 ]]; then 306 | coloron=$3 307 | else 308 | coloron=${on} 309 | fi 310 | if [[ ${use_color_off} == false && ${flag} == false ]]; then symbol=' '; fi 311 | if [[ $flag == true ]]; then color="${coloron}"; else color="${off}"; fi 312 | if [[ ${print_unactive_flags_space} == false && ${flag} == false ]]; then 313 | return; 314 | else 315 | echo "${color}${symbol}${reset}"; 316 | fi 317 | } 318 | 319 | 320 | if [ -n "$ZSH_VERSION" ]; then 321 | function trim() { 322 | leading_trimmed="${1##+([[:space:]])}"; 323 | trimmed="${leading_trimmed%%+([[:space:]])}"; 324 | echo "$trimmed"; 325 | } 326 | elif [ -n "$BASH_VERSION" ]; then 327 | function trim() { 328 | leading_trimmed="${1#"${1%%[![:space:]]*}"}"; 329 | trimmed="${leading_trimmed%"${leading_trimmed##*[![:space:]]}"}"; 330 | echo "$trimmed"; 331 | } 332 | else 333 | function trim() { 334 | return $1; 335 | } 336 | fi 337 | --------------------------------------------------------------------------------