From 1ab110c264fc3da523b9ec288f84e60480f0bcd5 Mon Sep 17 00:00:00 2001 From: Eric Nielsen Date: Wed, 26 Dec 2018 20:56:57 -0500 Subject: [PATCH] [git-info] Add complete example to README.md so users don't need to look at our prompts code to figure out how having all the pieces together looks like. --- modules/git-info/README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/modules/git-info/README.md b/modules/git-info/README.md index c9bea97..be649ba 100644 --- a/modules/git-info/README.md +++ b/modules/git-info/README.md @@ -101,3 +101,29 @@ Second, format how the above attributes are displayed in prompts: Last, add `${(e)git_info[prompt]}` and `${(e)git_info[rprompt]}` to `PS1` and `RPS1` respectively, and call `git-info` in the `prompt_name_precmd` hook function. + +Here's a complete example of a `prompt_example_setup` file: +```zsh +prompt_example_precmd() { + (( ${+functions[git-info]} )) && git-info +} + +prompt_example_setup() { + autoload -Uz add-zsh-hook && add-zsh-hook precmd prompt_example_precmd + + prompt_opts=(cr percent sp subst) + + zstyle ':zim:git-info:branch' format 'branch:%b' + zstyle ':zim:git-info:commit' format 'commit:%c' + zstyle ':zim:git-info:remote' format 'remote:%R' + + zstyle ':zim:git-info:keys' format \ + 'prompt' 'git(%b%c)' \ + 'rprompt' '[%R]' + + PS1='${(e)git_info[prompt]}%# ' + RPS1='${(e)git_info[rprompt]}' +} + +prompt_example_setup "${@}" +```