Skip to content

Commit

Permalink
Prevent unreadable prompt within Git repository
Browse files Browse the repository at this point in the history
When within a git repository, doing a tab-autocomplete on a command results with the command becoming unreadable. The command still works but this is pretty annoying visually.

Basically I

1. Navigate to a directory with a git repository in it. The prompt indicates the current branch properly
2. Next, type `git -` and hit tab

The prompt now shows only part of branch's name with the first suggestion appended.

After googling a bit I stumbled upon several pages describing a similar problem (most useful to me was http://stackoverflow.com/questions/23740862/issues-with-zsh-prompt).

The culprit seems to be the git_prompt_info function escaping the `$current_branch` variable as if it is a color. As a result zsh is confused where the cursor is. After "unescaping" the variable everything seems to work fine.

Using zsh 5.0.7 (x86_64-apple-darwin13.4.0).
  • Loading branch information
lunohodov committed Feb 12, 2015
1 parent 18a4c81 commit 38d11d3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion zshrc
Expand Up @@ -2,7 +2,7 @@
git_prompt_info() {
current_branch=$(git current-branch 2> /dev/null)
if [[ -n $current_branch ]]; then
echo " %{$fg_bold[green]%}%{$current_branch%}%{$reset_color%}"
echo " %{$fg_bold[green]%}$current_branch%{$reset_color%}"
fi
}
setopt promptsubst
Expand Down

0 comments on commit 38d11d3

Please sign in to comment.