Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add indicators for interactive rebase and bisect #94

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
69988cf
Show a wrench symbol for interactive rebasing.
compholio Jun 6, 2016
4fd423e
Show a binoculars symbol for bisecting.
compholio Jun 6, 2016
408b529
Add bisect status indicator (tested vs. total revisions).
compholio Jun 7, 2016
3705ad6
Add remaining bisect steps estimate indicator.
compholio Jun 7, 2016
2f934d7
Replace bisect symbol with telescope.
compholio Dec 8, 2016
7cd287c
Use a 'bug' prompt icon for a completed bisect.
compholio Dec 8, 2016
2dfd288
Use a 'microscope' prompt icon for a nearly completed bisect.
compholio Dec 13, 2016
49a642e
Fix last character having black background
krayon Feb 12, 2017
4556f33
Remove last char manual fix documentation
krayon Apr 12, 2017
2f0206c
Fix ohmygit-enabled error if not in git dir
cy4n May 10, 2017
9825dff
remove --local param
cy4n Jun 27, 2017
900eaa5
replace '$' signs in branch name by pile_of_poo
cy4n Jul 3, 2017
0ac3c30
replace '$' signs in branch name by pile_of_poo
cy4n Jul 3, 2017
09b8e9c
Use the 'git repo' symbol that is also available in Courier New.
compholio Aug 8, 2017
9e349cf
Add an indicator for out of date submodules.
compholio Aug 8, 2017
5a1df36
Merge remote-tracking branch 'krayon/lastcharfix'
compholio Aug 9, 2017
41972b3
Merge remote-tracking branch 'cy4n/prevent_code_exec'
compholio Aug 9, 2017
3dde872
Merge pull request #1 from krayon/lastcharfix
cy4n Aug 9, 2017
e8dddc9
merged compholio-master
cy4n Aug 9, 2017
666a8d1
Merge branch 'compholio-master'
cy4n Aug 9, 2017
84e7a16
change has_stashes_indicator color, yellow on white sucked
cy4n Aug 9, 2017
a45eb7b
Use a 'cached modifications' symbol that is also available in Courier…
compholio Aug 9, 2017
e327162
Use a 'ready to commit' symbol that is also availabe in Courier New.
compholio Aug 9, 2017
adc5000
Use a 'detached head' symbol that is also available in Courier New.
compholio Aug 9, 2017
61082e9
Use an 'untracked branch' symbol that is also available in Courier New.
compholio Aug 9, 2017
6af3750
Use a 'needs to merge' symbol that is also available in Courier New.
compholio Aug 9, 2017
6145105
Use a 'has stashes' symbol that is also available in Courier New.
compholio Aug 9, 2017
7e99e94
Use an 'untracked files' symbol that is also available in Courier New.
compholio Aug 9, 2017
c55239a
Use a 'tag' symbol that is also available in Courier New.
compholio Aug 9, 2017
0f1239c
Move the arrow symbol to being customizable.
compholio Aug 9, 2017
9eaa25c
Reduce code churn when custom_build_prompt parameters are changed.
compholio Aug 9, 2017
36b5c05
Merge pull request #3 from compholio/master
cy4n Aug 15, 2017
4b68e08
Merge branch 'master' of https://github.com/compholio/oh-my-git into …
cy4n Aug 29, 2017
50b45ec
Merge branch 'compholio-master'
cy4n Aug 29, 2017
8eece85
Add a 'condensed' mode that absorbs cached adds/deletions into modifi…
compholio Aug 10, 2017
2ee6e09
Merge branch 'compholio-master'
cy4n Aug 29, 2017
4d0bf78
Add support for multiple tags on the same commit.
compholio Aug 9, 2017
973ddbc
Merge pull request #6 from compholio/master
cy4n Sep 5, 2017
298daee
Use shallow clone
wwna Sep 20, 2017
8c25b67
Redirect error to null when checking oh-my-git.enabled
wwna Sep 20, 2017
dd12020
Add support for python virtualenv
wwna Sep 20, 2017
a3808ae
Fix symbol not show up with font issue
wwna Sep 21, 2017
f7bfccb
Merge pull request #7 from shadowwalker/master
cy4n Sep 21, 2017
8a24247
Add an indicator for rename operations.
compholio Oct 22, 2017
ad4cf40
Fix the 'has renames' display in uncondensed mode.
compholio Dec 8, 2017
30e3bbf
use unicode arrow for 'has_renames'
cy4n Dec 9, 2017
48eea6a
Skip submodule branch checking if the submodule is not tracking a bra…
compholio Jan 14, 2018
282e489
fix bisect status outside the toplevel directory
compholio Dec 10, 2019
a58e30f
recognize 'both modified' modifications
Oct 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 2 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Then, configure your terminal with the desired font, and restart it.

One liner for OS X:

git clone https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.profile
git clone --depth=1 https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.profile

One liner for Ubuntu:

git clone https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.bashrc
git clone --depth=1 https://github.com/arialdomartini/oh-my-git.git ~/.oh-my-git && echo source ~/.oh-my-git/prompt.sh >> ~/.bashrc

Then restart your Terminal.

Expand Down Expand Up @@ -169,46 +169,6 @@ 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.

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

![oh-my-git](https://cloud.githubusercontent.com/assets/6009528/6039646/454c965e-ac69-11e4-8f80-37425181d04b.png)

This in fact sets the "black" color to the same color used as the terminal background.


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

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.
Expand Down
101 changes: 85 additions & 16 deletions base.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#!/usr/bin/env bash
function enrich {
local flag=$1
local symbol=$2

local color_on=${3:-$omg_default_color_on}

if [[ $flag != true && $omg_use_color_off == false ]]; then symbol=' '; fi
if [[ $flag == true ]]; then local color=$color_on; else local color=$omg_default_color_off; fi
if [[ $flag == true ]]; then local color=$color_on; else local color=$omg_default_color_off; fi

echo -n "${prompt}${color}${symbol}${reset} "
}

function get_current_action () {
local info="$(git rev-parse --git-dir 2>/dev/null)"
local info="$(git rev-parse --git-dir 2> /dev/null)"
if [ -n "$info" ]; then
local action
if [ -f "$info/rebase-merge/interactive" ]
Expand Down Expand Up @@ -49,21 +50,22 @@ function get_current_action () {
}

function build_prompt {
local enabled=`git config --local --get oh-my-git.enabled`
local enabled=`git config --get oh-my-git.enabled 2> /dev/null`
if [[ ${enabled} == false ]]; then
echo "${PSORG}"
exit;
fi

local prompt=""

# Git info
local current_commit_hash=$(git rev-parse HEAD 2> /dev/null)
if [[ -n $current_commit_hash ]]; then local is_a_git_repo=true; fi

if [[ $is_a_git_repo == true ]]; then
local current_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [[ $current_branch == 'HEAD' ]]; then local detached=true; fi
local current_branch_sanitized=${current_branch//\$/💩}
if [[ $current_branch_sanitized == 'HEAD' ]]; then local detached=true; fi

local number_of_logs="$(git log --pretty=oneline -n1 2> /dev/null | wc -l)"
if [[ $number_of_logs -eq 0 ]]; then
Expand All @@ -76,18 +78,19 @@ function build_prompt {
local action="$(get_current_action)"

if [[ $git_status =~ ($'\n'|^).M ]]; then local has_modifications=true; fi
if [[ $git_status =~ ($'\n'|^)UU ]]; then local has_modifications=true; fi
if [[ $git_status =~ ($'\n'|^)M ]]; then local has_modifications_cached=true; fi
if [[ $git_status =~ ($'\n'|^)A ]]; then local has_adds=true; fi
if [[ $git_status =~ ($'\n'|^).D ]]; then local has_deletions=true; fi
if [[ $git_status =~ ($'\n'|^)D ]]; then local has_deletions_cached=true; fi
if [[ $git_status =~ ($'\n'|^)R ]]; then local has_renames=true; fi
if [[ $git_status =~ ($'\n'|^)[MAD] && ! $git_status =~ ($'\n'|^).[MAD\?] ]]; then local ready_to_commit=true; fi

local number_of_untracked_files=$(\grep -c "^??" <<< "${git_status}")
if [[ $number_of_untracked_files -gt 0 ]]; then local has_untracked_files=true; fi

local tag_at_current_commit=$(git describe --exact-match --tags $current_commit_hash 2> /dev/null)
if [[ -n $tag_at_current_commit ]]; then local is_on_a_tag=true; fi


local tags_at_current_commit=$(git tag --points-at $current_commit_hash 2> /dev/null)

if [[ $has_upstream == true ]]; then
local commits_diff="$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} 2> /dev/null)"
local commits_ahead=$(\grep -c "^<" <<< "$commits_diff")
Expand All @@ -96,16 +99,82 @@ function build_prompt {

if [[ $commits_ahead -gt 0 && $commits_behind -gt 0 ]]; then local has_diverged=true; fi
if [[ $has_diverged == false && $commits_ahead -gt 0 ]]; then local should_push=true; fi
local will_rebase=$(git config --get branch.${current_branch}.rebase 2> /dev/null)

local will_rebase=$(git config --get branch.${current_branch_sanitized}.rebase 2> /dev/null)

local number_of_stashes="$(git stash list -n1 2> /dev/null | wc -l)"
if [[ $number_of_stashes -gt 0 ]]; then local has_stashes=true; fi

if [ "${action}" = "bisect" ]; then
local bisect_toplevel=$(git rev-parse --show-toplevel)
local bisect_log=$(git -C ${bisect_toplevel} bisect log)
local bisect_first=$(grep 'git bisect good' <<< "${bisect_log}" | head -n1 | cut -d' ' -f4)
local bisect_last=$(grep 'git bisect bad' <<< "${bisect_log}" | head -n1 | cut -d' ' -f4)
local bisect_total=$(git log --pretty=oneline ${bisect_first}..${bisect_last} 2> /dev/null | wc -l)
local bisect_total=$(bc <<< "${bisect_total} - 1")
local bisect_remain=$(git -C ${bisect_toplevel} bisect view --pretty=oneline 2> /dev/null | wc -l)
local bisect_remain=$(bc <<< "${bisect_remain} / 2")
local bisect_tested=$(bc <<< "${bisect_total} - ${bisect_remain}")
if [[ ${bisect_remain} -ne 0 ]]; then
local bisect_steps=$(bc -l <<< "a=l(${bisect_remain})/l(2); scale=0; (a+0.5)/1")
local bisect_steps="~${bisect_steps}"
else
local bisect_steps="0"
fi
fi

local toplevel=$(git rev-parse --show-toplevel)
local modules=$(git -C ${toplevel} config --file .gitmodules --name-only --get-regexp path | sed 's/\.path$//')
local submodules_outdated=false
local module=''
for module in ${modules}; do
# obtain the module configuration
local module_path=$(git -C "${toplevel}" config --file .gitmodules ${module}.path)
local module_branch=$(git -C "${toplevel}" config --file .gitmodules ${module}.branch)
if [ -z "${module_branch}" ]; then continue; fi
# spawn a background update of our cached information
(git -C "${toplevel}/${module_path}" remote update &) 1>/dev/null 2>/dev/null
# determine whether the branch is out of date (with cached data)
local branch_rev=$(git -C "${toplevel}/${module_path}" rev-parse origin/${module_branch})
local head_rev=$(git -C "${toplevel}/${module_path}" rev-parse HEAD)
if [[ "${head_rev}" != "${branch_rev}" ]]; then
submodules_outdated=true;
fi
done
fi
fi

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})"


echo "$(custom_build_prompt \
${enabled:-true} \
${current_commit_hash:-""} \
${is_a_git_repo:-false} \
${current_branch_sanitized:-""} \
${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_renames:-false} \
${has_untracked_files:-false} \
${ready_to_commit:-false} \
"${tags_at_current_commit:-""}" \
${has_upstream:-false} \
${commits_ahead:-false} \
${commits_behind:-false} \
${has_diverged:-false} \
${should_push:-false} \
${will_rebase:-false} \
${has_stashes:-false} \
${bisect_tested:-""} \
${bisect_total:-""} \
${bisect_steps:-""} \
${submodules_outdated:-false} \
${action} \
)"

}

function_exists() {
Expand Down
Loading