jcorbin / zsh-git

Towards better Zsh Git integration
http://www.wunjo.org/zsh-git
MIT License
261 stars 38 forks source link

Remove color codes, use zstyle/zformat #7

Open cdlm opened 13 years ago

cdlm commented 13 years ago

Hi, as said in your TODO file, you have yet another implementation of ansi-color sequences in prompt_wunjo_setup. Using tput would indeed be nice, but I think it should be the responsability of someone refactoring the colors module.

For your prompt, using zstyle and zformat seems more to the poinf, as it would allow users to organize the whole messages (and display colors as they like). For instance, I like minimal prompts, so I'd prefer limit git information to short symbols about the branch and dirty status.

I took the liberty of adapting your prompt_wunjo_scm_branch function for my own use, and here's what it looks like:

function promptinfo_git_status() {
   zgit_isgit || return
   local msg

   if zgit_inworktree; then
      local fmt
      zstyle -s ':promptinfo:' git-status fmt
      [[ -z ${fmt} ]] && fmt='%(i.-.+)%(w.-.*)%(m.!.-)%(t.?.-)'

      zformat -f msg ${fmt} \
         i:$(status zgit_isindexclean) \
         w:$(status zgit_isworktreeclean) \
         m:$(status zgit_hasunmerged) \
         t:$(status zgit_hasuntracked)
   fi
   echo -n ${msg}
}

function status() { "$@"; echo $? } # needed because your functions don't echo anything themselves
michaelbarton commented 13 years ago

This was very useful. I have remodelled my prompt based on this. Thank you.