The response has been limited to 50k tokens of the smallest files in the repo. You can remove this limitation by removing the max tokens filter.
├── LICENSE.txt
├── README.md
├── base.sh
└── prompt.sh


/LICENSE.txt:
--------------------------------------------------------------------------------
 1 | The MIT License (MIT)
 2 | 
 3 | Copyright (c) 2013 Arialdo Martini
 4 | 
 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
 6 | this software and associated documentation files (the "Software"), to deal in
 7 | the Software without restriction, including without limitation the rights to
 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 | 
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 | 
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | 


--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
  1 | 
  2 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/01-ordinary-prompt.jpg)
  3 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/02-bang.jpg)
  4 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/03-useful-information.jpg)
  5 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/04-untracked-files.jpg)
  6 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/06-rm-commit.jpg)
  7 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/06-tris-colors.jpg)
  8 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/07-tracking-branches.jpg)
  9 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/08-push-rebase-and-remote-branch-names.jpg)
 10 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/09-you-can-push.jpg)
 11 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/10-you-are-behind-fast-forward.jpg)
 12 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/11-diverged.jpg)
 13 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/12-detached.jpg)
 14 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/13-stash-and-tag.jpg)
 15 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/14-action-in-progress.jpg)
 16 | 
 17 | 
 18 | ![alt tag](https://raw.github.com/arialdomartini/oh-my-git-gh-pages/gh-pages/images/shut-up.gif)
 19 | 
 20 | 
 21 | # Installation
 22 | ## <a name="install-the-font"></a>The Font
 23 | 
 24 | oh-my-git is shipped with 3 themes. The one showed above is called [oppa-lana-style](https://github.com/arialdomartini/oh-my-git-themes/blob/oppa-lana-style/oppa-lana-style.zsh-theme). It's based on the [Awesome-Terminal-Fonts](https://github.com/gabrielelana/awesome-terminal-fonts) by [@gabrielelana](https://github.com/gabrielelana). The screenshots above use the font [Source Code Pro](https://github.com/adobe/Source-Code-Pro) by Adobe patched to include additional glyphs from [Powerline](https://github.com/powerline/powerline) and from Awesome-Terminal-Fonts, but you can choose any other of the Awesome-Terminal-Fonts.
 25 | 
 26 | You can freely [download](https://github.com/gabrielelana/awesome-terminal-fonts/tree/patching-strategy/patched) the fonts from the original repo.
 27 | 
 28 | To install one of the fonts, on macOS just double click on the corresponding ```ttf``` file and click on ```Install font```. So far, I didn't find a way to make the fallback strategy work on macOS.
 29 | 
 30 | On Linux you can either [install the patched font](#install-the-patched-font) or you can apply the Awesome-Terminal-Fonts [fallback strategy](https://github.com/gabrielelana/awesome-terminal-fonts/blob/master/README.md#patching-vs-fallback).
 31 |     
 32 | Then, configure your terminal with the desired font, and restart it.
 33 | 
 34 | ## Bash
 35 | 
 36 | One liner for macOS:
 37 | 
 38 |     git clone https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.profile
 39 | 
 40 | One liner for Ubuntu:
 41 | 
 42 |     git clone https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.bashrc
 43 | 
 44 | Then restart your Terminal.
 45 | 
 46 | 
 47 | ## Manual installation
 48 | 
 49 | Fork the repo and git clone it in your home directory.
 50 | 
 51 | Then add
 52 | 
 53 |     source $HOME/oh-my-git/prompt.sh
 54 | 
 55 | to the bash startup file (`~/.profile` on Mac, `~/.bashrc` on Linux)
 56 | 
 57 | If you prefer to keep oh-my-git repository in a different directory, just modify the startup file accordingly to the chosen position
 58 | 
 59 |     source /wherever-you-want/oh-my-git/prompt.sh
 60 | 
 61 | ## zsh
 62 | 
 63 | With antigen installed, just add
 64 | 
 65 |     antigen use oh-my-zsh
 66 |     antigen bundle arialdomartini/oh-my-git
 67 |     antigen theme arialdomartini/oh-my-git-themes oppa-lana-style
 68 | 
 69 | to your `.zshrc` file.
 70 | 
 71 | [`oh-my-git-themes`](https://github.com/arialdomartini/oh-my-git-themes) still includes the old 2 themes [arialdo-granzestyle](https://github.com/arialdomartini/oh-my-git-themes/blob/master/arialdo-granzestyle.zsh-theme)  (which is inspired to the great [Granze theme](https://github.com/Granze/G-zsh-theme-2)) by [@granze](https://github.com/granze), and [arialdo-pathinline](https://github.com/arialdomartini/oh-my-git-themes/blob/master/arialdo-pathinline.zsh-theme). If you want to use them, edit accordingly your ```.zshrc``` file.
 72 | 
 73 | ## Fig
 74 | 
 75 | [Fig](https://fig.io) adds apps, shortcuts, and autocomplete to your existing terminal.
 76 | 
 77 | Install `oh-my-git` in just one click.
 78 | 
 79 | <a href="https://fig.io/plugins/other/oh-my-git" target="_blank"><img src="https://fig.io/badges/install-with-fig.svg" /></a>
 80 | 
 81 | ## How to install antigen
 82 | 
 83 | [antigen](https://github.com/zsh-users/antigen) is a plugin manager for `zsh`.
 84 | Installing antigen is straightforward:
 85 | 
 86 |     cd ~ && git clone https://github.com/zsh-users/antigen.git .antigen 
 87 | 
 88 | Then, edit your `.zshrc` file including
 89 | 
 90 |     source "$HOME/.antigen/antigen.zsh"
 91 | 
 92 |     antigen use oh-my-zsh
 93 |     antigen bundle arialdomartini/oh-my-git
 94 |     antigen theme arialdomartini/oh-my-git-themes oppa-lana-style
 95 | 
 96 |     antigen apply
 97 | 
 98 | When you restart zsh, antigen will download and install all that's needed.
 99 | 
100 | # Customizing symbols
101 | 
102 | You can easily change any symbols used by the prompt. Take a look to the file [prompt.sh](https://github.com/arialdomartini/oh-my-git/blob/master/prompt.sh) (or to [oppa-lana-style.zsh-theme](https://github.com/arialdomartini/oh-my-git-themes/blob/master/oppa-lana-style.zsh-theme) if you use zsh). You will find a bunch of variables, each of them with its default value. The variables names should be auto-explanatory. Something like
103 | 
104 | ```
105 | : ${omg_is_a_git_repo_symbol:='❤'}
106 | : ${omg_has_untracked_files_symbol:='∿'}
107 | : ${omg_has_adds_symbol:='+'}
108 | : ${omg_has_deletions_symbol:='-'}
109 | : ${omg_has_cached_deletions_symbol:='✖'}
110 | : ${omg_has_modifications_symbol:='✎'}
111 | : ${omg_has_cached_modifications_symbol:='☲'}
112 | : ${omg_ready_to_commit_symbol:='→'}
113 | : ${omg_is_on_a_tag_symbol:='⌫'}
114 | ```
115 | 
116 | You can override any of those variables in your shell startup file.
117 | 
118 | For example, just add a
119 | 
120 | ```
121 | omg_is_on_a_tag_symbol='#'
122 | ```
123 | 
124 | to your `.bashrc` file, and oh-my-git will use `#` when you are on a tag.
125 | 
126 | 
127 | # Disabling oh-my-git
128 | oh-my-git can be disabled on a per-repository basis. Just add a
129 | 
130 |     [oh-my-git]
131 |     enabled = false
132 | 
133 | in the `.git/config` file of a repo to revert to the original prompt for that particular repo. This could be handy when working with very huge repository, when the git commands invoked by oh-my-git can slow down the prompt.
134 | 
135 | # Uninstall
136 | 
137 | ## Bash
138 | * Remove the line `source ~/.oh-my-git/prompt.sh` from the terminal boot script (`.profile` or `.bash_rc`)
139 | * Delete the oh-my-git repo with a `rm -fr ~/.oh-my-git`
140 | 
141 | ## zsh
142 | Remove the lines
143 | 
144 | ```
145 | antigen use oh-my-zsh
146 | antigen bundle arialdomartini/oh-my-git
147 | antigen theme arialdomartini/oh-my-git-themes oppa-lana-style
148 | ```
149 | 
150 | from your `.zshrc` file
151 | 
152 | # Troubleshooting
153 | 
154 | #### Help, I installed oh-my-git but this is what I see:
155 | 
156 | 
157 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/bad-font.png)
158 | 
159 | **A**: It's likely that you forgot to [install the font](#install-the-font).
160 | 
161 | ---
162 | 
163 | #### I don't want to install a new font!
164 | 
165 | **A**: "No prob. You may select [another theme](https://github.com/arialdomartini/oh-my-git-themes), or you can customize symbols. Take a look to the [prompt.sh](https://github.com/arialdomartini/oh-my-git/blob/master/prompt.sh) file. It contains a list of pre-defined symbols, similar to:
166 | 
167 |     # Symbols
168 |     : ${omg_is_a_git_repo_symbol:='❤'}
169 |     : ${omg_has_untracked_files_symbol:='∿'}
170 |     : ${omg_has_adds_symbol:='+'}
171 |     : ${omg_has_deletions_symbol:='-'}
172 |     : ${omg_has_modifications_symbol:='✎'}
173 | 
174 | Those are just default values. If you wish to use another glyph for untracked file, just define a
175 | 
176 |     omg_has_untracked_files_symbol="whatever"
177 | 
178 | in your shell startup file.
179 | 
180 | ---
181 | #### With Bash the last symbol looks very bad, like this
182 | 
183 | ![oh-my-git](https://cloud.githubusercontent.com/assets/6009528/6031476/0b9bfe2c-ac00-11e4-898a-324a71be6cb5.png)
184 | 
185 | **A**: Unfortunately, I haven't find a way to tell bash "*print the next symbol using the background color currently used by the terminal*" and as far as I know [there's no way to achieve this result](http://unix.stackexchange.com/questions/1755/change-the-ps1-color-based-on-the-background-color#tab-top). Zsh is not affected by this issue, but bash is.
186 | 
187 | As a consequence, when printing the last symbol, oh-my-git has no choice but setting explicitly the foreground and background colors. Currently, the standard background color is black. This is unfortunate, because if the terminal uses a different background color than black, the result is bad, as showed in the above screenshot.
188 | 
189 | A smart solution is the one proposed by [@Sgiath](https://github.com/Sgiath): in the color palette set the first color (the one in the top-left corner) same as background color, like this
190 | 
191 | ![oh-my-git](https://cloud.githubusercontent.com/assets/6009528/6039646/454c965e-ac69-11e4-8f80-37425181d04b.png)
192 | 
193 | This in fact sets the "black" color to the same color used as the terminal background.
194 | 
195 | 
196 | If for any reasons you cannot change the palette, you can override the colors used to render the last symbol with the variable `omg_last_symbol_color`.
197 | 
198 | For example, if the terminal is using a gray background, you can add a
199 | 
200 | ```
201 | background=240
202 | red='\e[0;31m'
203 | omg_last_symbol_color="${red}\[\033[48;5;${background}m\]"
204 | ```
205 | 
206 | to your `.bashrc` and fix the issue by choosing the right value for `background`.
207 | 
208 | You can use
209 | 
210 | ```
211 | foreground=160
212 | background=240
213 | omg_last_symbol_color="\[\033[38;5;${foreground}m\]\[\033[48;5;${background}m\]"
214 | ```
215 | 
216 | if you want a more detailed control on the colors.
217 | 
218 | Finding the right value is not trivial. Please, refer to [this page](http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux) for a the 256 colors code table.
219 | 
220 | ---
221 | 
222 | #### On OS X, I configured iTerm2 with the patched font, but the prompt is still broken.
223 | 
224 | **A**: iTerm2 preferences have 2 sections for setting the font: one for `Regular Font` and one for `Non-ASCII Font`.
225 | The font should be set on both the sections, like showed in the following screenshot:
226 | 
227 | ![iTerm2 Preferences Page](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/iterm2.png)
228 | 
229 | ---
230 | 
231 | #### <a name="install-the-patched-font"></a>Help! On Linux I can't install the font!
232 | 
233 | **A**: You should refer to the documentation of [Awesome-Terminal-Fonts](https://github.com/gabrielelana/awesome-terminal-fonts). Anyway, this is how I personally setup the prompt on Ubuntu
234 | 
235 |     # Copy the awesome fonts to ~/.fonts
236 |     cd /tmp
237 |     git clone http://github.com/gabrielelana/awesome-terminal-fonts
238 |     cd awesome-terminal-fonts
239 |     git checkout patching-strategy
240 |     mkdir -p ~/.fonts
241 |     cp patched/*.ttf ~/.fonts
242 | 
243 |     # update the font-info cache
244 |     sudo fc-cache -fv ~/.fonts
245 | 
246 | Then, run ```gnome-terminal``` (or whatever terminal you like) and select one of the awesome-fonts
247 | 
248 | ![alt tag](https://raw.githubusercontent.com/arialdomartini/oh-my-git-gh-pages/master/images/samples/gnome-terminal.png)
249 | 
250 | Finally, install oh-my-zsh with the one-liner (if you use Bash) or with Antigen if you love zsh, and restart the Terminal.
251 | 
252 | ---
253 | 
254 | #### When I'm not in a git repo, I want to use my old, beloved prompt...
255 | 
256 | **A**: Sure! Use the variable `omg_ungit_prompt`. Store there your old prompt: it will be used when you are not in a git repo.
257 | 
258 | ---
259 | 
260 | #### Help! I used the one-liner for OS X, but the prompt doesn't start!
261 | 
262 | **A**: The one-liner for OS X adds the startup command in ```~/.profile```, which is the startup file for generic login shells. If a ```~/.bash_profile``` is present, this is used in place of ```.profile```, and ```.profile``` itself is ignored. To solve your issue, use this alternative one-liner
263 | 
264 |     cd ~ && git clone https://github.com/arialdomartini/oh-my-git.git && echo source $HOME/.oh-my-git/prompt.sh >> .bash_profile
265 | 
266 | or just move the startup command
267 | 
268 |     echo source $HOME/oh-my-git/prompt.sh
269 | 
270 | from ```.profile``` to ```.bash_profile```
271 | 
272 | ---
273 | 
274 | #### Hey, where's my current virtualenv name? It disappeared from the prompt! Or it appears like this
275 | 
276 | ![virtualenv badly rendered](https://cloud.githubusercontent.com/assets/150719/5852434/06933e88-a217-11e4-81a0-153c5a300b0a.png)
277 | 
278 | **A**: Yes, actually the virtualenv's approach with prompts is pretty disappointing (see [Virtualenv's bin/activate is Doing It Wrong](https://gist.github.com/datagrok/2199506)): in fact, the script ```activate``` performs a
279 | 
280 | ```
281 | PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
282 | ```
283 | 
284 | that arrogantly prepends the virtualenv name to the current ```PS1```, leaving you no opportunity to customise the output.
285 | 
286 | You can solve this problem disabling the standard virtualenv prompt injection and using the callback function `omg_prompt_callback`.
287 | 
288 | Add
289 | 
290 | ```
291 | VIRTUAL_ENV_DISABLE_PROMPT=true
292 | function omg_prompt_callback() {
293 |     if [ -n "${VIRTUAL_ENV}" ]; then
294 |         echo "\e[0;31m(`basename ${VIRTUAL_ENV}`)\e[0m "
295 |     fi
296 | }
297 | ```
298 | 
299 | to your shell startup script. It should render the prompt inside an active virtualenv like this
300 | 
301 | ![a proper virtualenv rendering](https://cloud.githubusercontent.com/assets/150719/5852429/e50d18a6-a216-11e4-9b0e-c902f47a1ca4.png)]
302 | 
303 | You can use the call back function to inject whatever you want at the beginning of the second line.
304 | 
305 | # Known bugs and limitations
306 | 
307 | * git v1.8.4 or newer is required
308 | * It works weird on brand new repositories, before the first commit
309 | * It has been tested on Mac and Ubuntu only. I never managed to make it work on Cygwin
310 | * Depending on the theme selected, you need an unicode font (like Sauce Code Pro, Menlo or Monaco on Mac OS X, or Monospace on Ubuntu; on Windows, with Cygwin, a good choice is [Meslo](https://github.com/andreberg/Meslo-Font) by [André Berg](https://github.com/andreberg), but I didn't tested the ooppa-lana-style theme)
311 | * If the Terminal uses a clear background color, in Bash you need to change the colors defined in [prompt.sh](https://github.com/arialdomartini/oh-my-git/blob/oppa-lana-style/prompt.sh). The zsh version is not affected by this problem.
312 | 


--------------------------------------------------------------------------------
/base.sh:
--------------------------------------------------------------------------------
  1 | function enrich {
  2 |     local flag=$1
  3 |     local symbol=$2
  4 | 
  5 |     local color_on=${3:-$omg_default_color_on}
  6 | 
  7 |     if [[ $flag != true && $omg_use_color_off == false ]]; then symbol=' '; fi
  8 |     if [[ $flag == true ]]; then local color=$color_on; else local color=$omg_default_color_off; fi    
  9 | 
 10 |     echo -n "${prompt}${color}${symbol}${reset} "
 11 | }
 12 | 
 13 | function get_current_action () {
 14 |     local info="$(git rev-parse --git-dir 2>/dev/null)"
 15 |     if [ -n "$info" ]; then
 16 |         local action
 17 |         if [ -f "$info/rebase-merge/interactive" ]
 18 |         then
 19 |             action=${is_rebasing_interactively:-"rebase -i"}
 20 |         elif [ -d "$info/rebase-merge" ]
 21 |         then
 22 |             action=${is_rebasing_merge:-"rebase -m"}
 23 |         else
 24 |             if [ -d "$info/rebase-apply" ]
 25 |             then
 26 |                 if [ -f "$info/rebase-apply/rebasing" ]
 27 |                 then
 28 |                     action=${is_rebasing:-"rebase"}
 29 |                 elif [ -f "$info/rebase-apply/applying" ]
 30 |                 then
 31 |                     action=${is_applying_mailbox_patches:-"am"}
 32 |                 else
 33 |                     action=${is_rebasing_mailbox_patches:-"am/rebase"}
 34 |                 fi
 35 |             elif [ -f "$info/MERGE_HEAD" ]
 36 |             then
 37 |                 action=${is_merging:-"merge"}
 38 |             elif [ -f "$info/CHERRY_PICK_HEAD" ]
 39 |             then
 40 |                 action=${is_cherry_picking:-"cherry-pick"}
 41 |             elif [ -f "$info/BISECT_LOG" ]
 42 |             then
 43 |                 action=${is_bisecting:-"bisect"}
 44 |             fi
 45 |         fi
 46 | 
 47 |         if [[ -n $action ]]; then printf "%s" "${1-}$action${2-}"; fi
 48 |     fi
 49 | }
 50 | 
 51 | function build_prompt {
 52 |     local enabled=`git config --get oh-my-git.enabled`
 53 |     if [[ ${enabled} == false ]]; then
 54 |         echo "${PSORG}"
 55 |         exit;
 56 |     fi
 57 | 
 58 |     local prompt=""
 59 |     
 60 |     # Git info
 61 |     local current_commit_hash=$(git rev-parse HEAD 2> /dev/null)
 62 |     if [[ -n $current_commit_hash ]]; then local is_a_git_repo=true; fi
 63 |     
 64 |     if [[ $is_a_git_repo == true ]]; then
 65 |         local current_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
 66 |         if [[ $current_branch == 'HEAD' ]]; then local detached=true; fi
 67 | 
 68 |         local number_of_logs="$(git log --pretty=oneline -n1 2> /dev/null | wc -l)"
 69 |         if [[ $number_of_logs -eq 0 ]]; then
 70 |             local just_init=true
 71 |         else
 72 |             local upstream=$(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} 2> /dev/null)
 73 |             if [[ -n "${upstream}" && "${upstream}" != "@{upstream}" ]]; then local has_upstream=true; fi
 74 | 
 75 |             local git_status="$(git status --porcelain 2> /dev/null)"
 76 |             local action="$(get_current_action)"
 77 | 
 78 |             if [[ $git_status =~ (
#39;\n'|^).M ]]; then local has_modifications=true; fi
 79 |             if [[ $git_status =~ (
#39;\n'|^)M ]]; then local has_modifications_cached=true; fi
 80 |             if [[ $git_status =~ (
#39;\n'|^)A ]]; then local has_adds=true; fi
 81 |             if [[ $git_status =~ (
#39;\n'|^).D ]]; then local has_deletions=true; fi
 82 |             if [[ $git_status =~ (
#39;\n'|^)D ]]; then local has_deletions_cached=true; fi
 83 |             if [[ $git_status =~ (
#39;\n'|^)[MAD] && ! $git_status =~ (
#39;\n'|^).[MAD\?] ]]; then local ready_to_commit=true; fi
 84 | 
 85 |             local number_of_untracked_files=$(\grep -c "^??" <<< "${git_status}")
 86 |             if [[ $number_of_untracked_files -gt 0 ]]; then local has_untracked_files=true; fi
 87 |         
 88 |             local tag_at_current_commit=$(git describe --exact-match --tags $current_commit_hash 2> /dev/null)
 89 |             if [[ -n $tag_at_current_commit ]]; then local is_on_a_tag=true; fi
 90 |         
 91 |             if [[ $has_upstream == true ]]; then
 92 |                 local commits_ahead commits_behind
 93 |                 read -r commits_ahead commits_behind <<<$(git rev-list --left-right --count ${current_commit_hash}...${upstream} 2> /dev/null)
 94 |             fi
 95 | 
 96 |             if [[ $commits_ahead -gt 0 && $commits_behind -gt 0 ]]; then local has_diverged=true; fi
 97 |             if [[ $has_diverged == false && $commits_ahead -gt 0 ]]; then local should_push=true; fi
 98 |         
 99 |             local will_rebase=$(git config --get branch.${current_branch}.rebase 2> /dev/null)
100 |         
101 |             local number_of_stashes="$(git stash list -n1 2> /dev/null | wc -l)"
102 |             if [[ $number_of_stashes -gt 0 ]]; then local has_stashes=true; fi
103 |         fi
104 |     fi
105 |     
106 |     echo "$(custom_build_prompt ${enabled:-true} ${current_commit_hash:-""} ${is_a_git_repo:-false} ${current_branch:-""} ${detached:-false} ${just_init:-false} ${has_upstream:-false} ${has_modifications:-false} ${has_modifications_cached:-false} ${has_adds:-false} ${has_deletions:-false} ${has_deletions_cached:-false} ${has_untracked_files:-false} ${ready_to_commit:-false} ${tag_at_current_commit:-""} ${is_on_a_tag:-false} ${has_upstream:-false} ${commits_ahead:-false} ${commits_behind:-false} ${has_diverged:-false} ${should_push:-false} ${will_rebase:-false} ${has_stashes:-false} ${action})"
107 |     
108 | }
109 | 
110 | function_exists() {
111 |     declare -f -F $1 > /dev/null
112 |     return $?
113 | }
114 | 
115 | function eval_prompt_callback_if_present {
116 |         function_exists omg_prompt_callback && echo "$(omg_prompt_callback)"
117 | }
118 | 


--------------------------------------------------------------------------------
/prompt.sh:
--------------------------------------------------------------------------------
  1 | PSORG=$PS1;
  2 | PROMPT_COMMAND_ORG=$PROMPT_COMMAND;
  3 | 
  4 | if [ -n "${BASH_VERSION}" ]; then
  5 |     DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  6 |     source ${DIR}/base.sh
  7 | 
  8 |     : ${omg_ungit_prompt:=$PS1}
  9 |     : ${omg_second_line:=$PS1}
 10 | 
 11 |     : ${omg_is_a_git_repo_symbol:=''}
 12 |     : ${omg_has_untracked_files_symbol:=''}        #                ?    
 13 |     : ${omg_has_adds_symbol:=''}
 14 |     : ${omg_has_deletions_symbol:=''}
 15 |     : ${omg_has_cached_deletions_symbol:=''}
 16 |     : ${omg_has_modifications_symbol:=''}
 17 |     : ${omg_has_cached_modifications_symbol:=''}
 18 |     : ${omg_ready_to_commit_symbol:=''}            #   →
 19 |     : ${omg_is_on_a_tag_symbol:=''}                #   
 20 |     : ${omg_needs_to_merge_symbol:='ᄉ'}
 21 |     : ${omg_detached_symbol:=''}
 22 |     : ${omg_can_fast_forward_symbol:=''}
 23 |     : ${omg_has_diverged_symbol:=''}               #   
 24 |     : ${omg_not_tracked_branch_symbol:=''}
 25 |     : ${omg_rebase_tracking_branch_symbol:=''}     #   
 26 |     : ${omg_merge_tracking_branch_symbol:=''}      #  
 27 |     : ${omg_should_push_symbol:=''}                #    
 28 |     : ${omg_has_stashes_symbol:=''}
 29 | 
 30 |     : ${omg_default_color_on:='\[\033[1;37m\]'}
 31 |     : ${omg_default_color_off:='\[\033[0m\]'}
 32 |     : ${omg_last_symbol_color:='\e[0;31m\e[40m'}
 33 |     
 34 |     PROMPT='$(build_prompt)'
 35 |     RPROMPT='%{$reset_color%}%T %{$fg_bold[white]%} %n@%m%{$reset_color%}'
 36 | 
 37 |     function enrich_append {
 38 |         local flag=$1
 39 |         local symbol=$2
 40 |         local color=${3:-$omg_default_color_on}
 41 |         if [[ $flag == false ]]; then symbol=' '; fi
 42 | 
 43 |         echo -n "${color}${symbol}  "
 44 |     }
 45 | 
 46 |     function custom_build_prompt {
 47 |         local enabled=${1}
 48 |         local current_commit_hash=${2}
 49 |         local is_a_git_repo=${3}
 50 |         local current_branch=$4
 51 |         local detached=${5}
 52 |         local just_init=${6}
 53 |         local has_upstream=${7}
 54 |         local has_modifications=${8}
 55 |         local has_modifications_cached=${9}
 56 |         local has_adds=${10}
 57 |         local has_deletions=${11}
 58 |         local has_deletions_cached=${12}
 59 |         local has_untracked_files=${13}
 60 |         local ready_to_commit=${14}
 61 |         local tag_at_current_commit=${15}
 62 |         local is_on_a_tag=${16}
 63 |         local has_upstream=${17}
 64 |         local commits_ahead=${18}
 65 |         local commits_behind=${19}
 66 |         local has_diverged=${20}
 67 |         local should_push=${21}
 68 |         local will_rebase=${22}
 69 |         local has_stashes=${23}
 70 | 
 71 |         local prompt=""
 72 |         local original_prompt=$PS1
 73 | 
 74 | 
 75 |         # foreground
 76 |         local black='\e[0;30m'
 77 |         local red='\e[0;31m'
 78 |         local green='\e[0;32m'
 79 |         local yellow='\e[0;33m'
 80 |         local blue='\e[0;34m'
 81 |         local purple='\e[0;35m'
 82 |         local cyan='\e[0;36m'
 83 |         local white='\e[0;37m'
 84 | 
 85 |         #background
 86 |         local background_black='\e[40m'
 87 |         local background_red='\e[41m'
 88 |         local background_green='\e[42m'
 89 |         local background_yellow='\e[43m'
 90 |         local background_blue='\e[44m'
 91 |         local background_purple='\e[45m'
 92 |         local background_cyan='\e[46m'
 93 |         local background_white='\e[47m'
 94 |         
 95 |         local reset='\e[0m'     # Text Reset]'
 96 | 
 97 |         local black_on_white="${black}${background_white}"
 98 |         local yellow_on_white="${yellow}${background_white}"
 99 |         local red_on_white="${red}${background_white}"
100 |         local red_on_black="${red}${background_black}"
101 |         local black_on_red="${black}${background_red}"
102 |         local white_on_red="${white}${background_red}"
103 |         local yellow_on_red="${yellow}${background_red}"
104 | 
105 | 
106 |         # Flags
107 |         local omg_default_color_on="${black_on_white}"
108 | 
109 |         if [[ $is_a_git_repo == true ]]; then
110 |             # on filesystem
111 |             prompt="${black_on_white} "
112 |             prompt+=$(enrich_append $is_a_git_repo $omg_is_a_git_repo_symbol "${black_on_white}")
113 |             prompt+=$(enrich_append $has_stashes $omg_has_stashes_symbol "${yellow_on_white}")
114 | 
115 |             prompt+=$(enrich_append $has_untracked_files $omg_has_untracked_files_symbol "${red_on_white}")
116 |             prompt+=$(enrich_append $has_modifications $omg_has_modifications_symbol "${red_on_white}")
117 |             prompt+=$(enrich_append $has_deletions $omg_has_deletions_symbol "${red_on_white}")
118 |             
119 | 
120 |             # ready
121 |             prompt+=$(enrich_append $has_adds $omg_has_adds_symbol "${black_on_white}")
122 |             prompt+=$(enrich_append $has_modifications_cached $omg_has_cached_modifications_symbol "${black_on_white}")
123 |             prompt+=$(enrich_append $has_deletions_cached $omg_has_cached_deletions_symbol "${black_on_white}")
124 |             
125 |             # next operation
126 | 
127 |             prompt+=$(enrich_append $ready_to_commit $omg_ready_to_commit_symbol "${red_on_white}")
128 | 
129 |             # where
130 | 
131 |             prompt="${prompt} ${white_on_red} ${black_on_red}"
132 |             if [[ $detached == true ]]; then
133 |                 prompt+=$(enrich_append $detached $omg_detached_symbol "${white_on_red}")
134 |                 prompt+=$(enrich_append $detached "(${current_commit_hash:0:7})" "${black_on_red}")
135 |             else            
136 |                 if [[ $has_upstream == false ]]; then
137 |                     prompt+=$(enrich_append true "-- ${omg_not_tracked_branch_symbol}  --  (${current_branch})" "${black_on_red}")
138 |                 else
139 |                     if [[ $will_rebase == true ]]; then
140 |                         local type_of_upstream=$omg_rebase_tracking_branch_symbol
141 |                     else
142 |                         local type_of_upstream=$omg_merge_tracking_branch_symbol
143 |                     fi
144 | 
145 |                     if [[ $has_diverged == true ]]; then
146 |                         prompt+=$(enrich_append true "-${commits_behind} ${omg_has_diverged_symbol} +${commits_ahead}" "${white_on_red}")
147 |                     else
148 |                         if [[ $commits_behind -gt 0 ]]; then
149 |                             prompt+=$(enrich_append true "-${commits_behind} ${white_on_red}${omg_can_fast_forward_symbol}${black_on_red} --" "${black_on_red}")
150 |                         fi
151 |                         if [[ $commits_ahead -gt 0 ]]; then
152 |                             prompt+=$(enrich_append true "-- ${white_on_red}${omg_should_push_symbol}${black_on_red}  +${commits_ahead}" "${black_on_red}")
153 |                         fi
154 |                         if [[ $commits_ahead == 0 && $commits_behind == 0 ]]; then
155 |                             prompt+=$(enrich_append true " --   -- " "${black_on_red}")
156 |                         fi
157 |                         
158 |                     fi
159 |                     prompt+=$(enrich_append true "(${current_branch} ${type_of_upstream} ${upstream//\/$current_branch/})" "${black_on_red}")
160 |                 fi
161 |             fi
162 |             prompt+=$(enrich_append ${is_on_a_tag} "${omg_is_on_a_tag_symbol} ${tag_at_current_commit}" "${black_on_red}")
163 |             prompt+="${omg_last_symbol_color}${reset}\n"
164 |             prompt+="$(eval_prompt_callback_if_present)"
165 |             prompt+="${omg_second_line}"
166 |         else
167 |             prompt+="$(eval_prompt_callback_if_present)"
168 |             prompt+="${omg_ungit_prompt}"
169 |         fi
170 | 
171 |         echo "${prompt}"
172 |     }
173 |     
174 |     PS2="${yellow}→${reset} "
175 | 
176 |     function bash_prompt() {
177 |         PS1="$(build_prompt)"
178 |     }
179 | 
180 |     PROMPT_COMMAND="bash_prompt; $PROMPT_COMMAND_ORG"
181 | 
182 | fi
183 | 


--------------------------------------------------------------------------------