1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-07-05 23:09:44 +00:00
prezto/modules/prompt
Kaleb Elwert 9bdc1b35d5 Migrate sorin prompt to zsh-async (#1385)
This includes some improvements by @indrajitr in addition to the main migration.

The first step was to avoid PROMPT and RPROMPT modification when possible (which may help resolve some other issues as well relating to zsh crashes with the sorin prompt) then update the displayed git information in a separate variable rather than a command.

We use zsh-async for creating and running background tasks. The sorin prompt uses it to update git info without blocking the prompt from displaying (because of how long it can take). In the future it may be worth moving more tasks and more prompts to using this.

The move to zsh-async does make the git prompt slower in some circumstances (most noticeable in large repos), but this is a worthwhile tradeoff to avoid the cache file which had a number of potential security holes.

We have also switched to adding zsh-async as an external submodule (rather than the version bundled with pure) which may cause some migration headaches, but it will be worth it in the long run.
2017-07-24 11:55:02 -07:00
..
external Migrate sorin prompt to zsh-async (#1385) 2017-07-24 11:55:02 -07:00
functions Migrate sorin prompt to zsh-async (#1385) 2017-07-24 11:55:02 -07:00
init.zsh [Fix #713] Set prompt theme off in unsupported terminal 2014-11-05 17:41:36 -05:00
README.md [prompt] Rename helper function promptpwd to prompt-pwd for consistency 2017-07-22 13:13:00 -05:00

Prompt

Loads prompt themes.

Settings

Prompt Theme

To select a prompt theme, add the following to zpreztorc, and replace name with the name of the theme you wish to load. Setting it to random will load a random theme.

zstyle ':prezto:module:prompt' theme 'name'

Prompt Display Length

To change working directory prompt display length from 'short', set the following to 'long' (without '~' expansion) or 'full' (with '~' expansion) in zpreztorc.

zstyle ':prezto:module:prompt' pwd-length 'short'

Prompt Display Length

To change working directory prompt display length from 'short', set the following to 'long' (without '~' expansion) or 'full' (with '~' expansion) in zpreztorc.

zstyle ':prezto:module:prompt' pwd-length 'short'

Theming

A prompt theme is an autoloadable function file with a special name, prompt_name_setup, placed anywhere in $fpath, but for the purpose of this project, themes should be placed in the modules/prompt/functions directory.

Theme Functions

There are three theme functions, a setup function, a help function, and a preview function. The setup function must always be defined. The help function and the preview functions are optional.

prompt_name_setup

This function is called by the prompt function to install the theme. This function may define other functions as necessary to maintain the prompt, including a function that displays help or a function used to preview it.

Do not call this function directly.

The most basic example of this function can be seen below.

function prompt_name_setup {
  PROMPT='%m%# '
  RPROMPT=''
}

prompt_name_help

If the prompt_name_setup function is customizable via parameters, a help function should be defined. The user will access it via prompt -h name.

The most basic example of this function can be seen below.

function prompt_name_help {
  cat <<EOH
This prompt is color-scheme-able. You can invoke it thus:

  prompt theme [<color1>] [<color2>]

where the color is for the left-hand prompt.
EOH
}

prompt_name_preview

If the prompt_name_setup function is customizable via parameters, a preview function should be defined. The user will access it via prompt -p name.

The most basic example of this function can be seen below.

function prompt_name_preview {
  if (( $# > 0 )); then
    prompt_preview_theme theme "$@"
  else
    prompt_preview_theme theme red green blue
    print
    prompt_preview_theme theme yellow magenta black
  fi
}

Hook Functions

There are many Zsh hook functions, but mostly the precmd hook will be used.

prompt_name_precmd

This hook is called before the prompt is displayed and is useful for getting information to display in a prompt.

When calling functions to get information to display in a prompt, do not assume that all the dependencies have been loaded. Always check for the availability of a function before you calling it.

Do not register hook functions. They will be registered by the prompt function.

The most basic example of this function can be seen below.

function prompt_name_precmd {
  if (( $+functions[git-info] )); then
    git-info
  fi
}

Authors

The authors of this module should be contacted via the issue tracker.