Skip to content

Commit

Permalink
Merge pull request #51 from code4nothing/bash-colors
Browse files Browse the repository at this point in the history
Bash colors, fix #49
  • Loading branch information
arialdomartini committed Feb 4, 2015
2 parents f1542ee + 0d65f53 commit 8fc48fd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,40 @@ Those are just default values. If you wish to use another glyph for untracked fi
in your shell startup file.

---
#### With Bash the last symbol looks very bad, like this

![oh-my-git](https://cloud.githubusercontent.com/assets/6009528/6031476/0b9bfe2c-ac00-11e4-898a-324a71be6cb5.png)

**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.

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.

Luckily, you can override the colors used to render the last symbol with the variable `omg_last_symbol_color`.

For example, if the terminal is using a gray background, you can add a

```
background=240
red='\e[0;31m'
omg_last_symbol_color="${red}\[\033[48;5;${background}m\]"
```

to your `.bashrc` and fix the issue by choosing the right value for `background`.

You can use

```
foreground=160
background=240
omg_last_symbol_color="\[\033[38;5;${foreground}m\]\[\033[48;5;${background}m\]"
```

if you want a more detailed control on the colors.

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.

---

#### On OS X, I configured iTerm2 with the patched font, but the prompt is still broken.

**A**: iTerm2 preferences have 2 sections for setting the font: one for `Regular Font` and one for `Non-ASCII Font`.
Expand Down
5 changes: 3 additions & 2 deletions prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ if [ -n "${BASH_VERSION}" ]; then

: ${omg_default_color_on:='\[\033[1;37m\]'}
: ${omg_default_color_off:='\[\033[0m\]'}

: ${omg_last_symbol_color:='\e[0;31m\e[40m'}

PROMPT='$(build_prompt)'
RPROMPT='%{$reset_color%}%T %{$fg_bold[white]%} %n@%m%{$reset_color%}'

Expand Down Expand Up @@ -158,7 +159,7 @@ if [ -n "${BASH_VERSION}" ]; then
fi
fi
prompt+=$(enrich_append ${is_on_a_tag} "${omg_is_on_a_tag_symbol} ${tag_at_current_commit}" "${black_on_red}")
prompt+="${red_on_black}${reset}\n"
prompt+="${omg_last_symbol_color}${reset}\n"
prompt+="$(eval_prompt_callback_if_present)"
prompt+="${omg_second_line}"
else
Expand Down

0 comments on commit 8fc48fd

Please sign in to comment.