Selaa lähdekoodia

using_oh_my_zsh: fix tab completion and mode change bugs

Characters in the prompt were being offset wrongly, due to lack of `%{` and `%}`
escape sequences
Weiyi Lou 13 vuotta sitten
vanhempi
commit
8effff2898
1 muutettua tiedostoa jossa 24 lisäystä ja 9 poistoa
  1. 24 9
      zsh/oh-my-zsh-customs/cinaeco.zsh-theme

+ 24 - 9
zsh/oh-my-zsh-customs/cinaeco.zsh-theme

@@ -1,9 +1,24 @@
-PROMPT='
-$fg[yellow][%n@%m] $reset_color%T $fg[blue]%3~$reset_color $(git_prompt_info)$reset_color
-→ '
-
-MODE_INDICATOR="$fg[red]-- COMMAND MODE --$reset_color"
-ZSH_THEME_GIT_PROMPT_PREFIX="$fg[magenta]==> $fg[cyan]git( "
-ZSH_THEME_GIT_PROMPT_SUFFIX=" $fg[cyan])"
-ZSH_THEME_GIT_PROMPT_CLEAN=" $fg[green]✔$fg[cyan] is clean"
-ZSH_THEME_GIT_PROMPT_DIRTY=" $fg[red]✗$fg[cyan] has changes"
+## Override the default `git_prompt_info` function
+function git_prompt_info() {
+  ref=$(git symbolic-ref HEAD 2> /dev/null) || return
+  echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
+}
+
+## Using precmd instead of having a multiline prompt reduces the number of 
+## `%{` and `%}` escape sequences needed. Actions like changing mode in vi-mode
+## and using tab completion need the escapes to know the right number of printed
+## characters in the prompt (and mode indicator) variable, otherwise, they
+## offset (backwards or forwards) by the wrong number of characters.
+function precmd() {
+  print -rP '
+$fg[cyan][%n@%m] $reset_color%T $fg[yellow]%3~  $(git_prompt_info)'
+}
+
+PROMPT='%{$reset_color%}→ '
+
+MODE_INDICATOR="%{$fg[red]%}-- COMMAND MODE --%{$reset_color%}"
+
+ZSH_THEME_GIT_PROMPT_PREFIX="[git:"
+ZSH_THEME_GIT_PROMPT_SUFFIX="]$reset_color"
+ZSH_THEME_GIT_PROMPT_CLEAN="$fg[green]"
+ZSH_THEME_GIT_PROMPT_DIRTY="$fg[red]+"