(cherry picked from commit 25a04de1e51358fc8b119c047343a060ee34ced6) (cherry picked from commit 3f47be12e38c82d09ddaa4ba59269fa642d18840) |
||
|---|---|---|
| .. | ||
| README.md | ||
| responsive-prompt.plugin.zsh | ||
Responsive Prompt
Responsive Prompt is a OhMyZSH plugin, which makes your prompt
responsive to your terminal's column size. It does so, by watching
$COLUMNS environment variables. When it changes, this plugin reloads
your ZSH prompt.
Different Prompts
You can define several prompts for your terminal via functions named
like _prompt_60, which defines the prompt to be used when $COLUMNS
is greater than 60. Note that, you must set $PROMPT_BREAKPOINTS
variable, appropriately, for this to work. Example:
PROMPT_BREAKPOINTS=(100 50 0)
_prompt_100(){ PROMPT="<prompt1>"; } # prompt when $COLUMNS > 100
_prompt_50() { PROMPT="<prompt2>"; } # prompt when 100 >= $COLUMNS > 50
_prompt_0() { PROMPT="<prompt3>"; } # prompt when 50 >= $COLUMNS > 0
You can, even, define different prompts using conditional statements in
your $PROMPT_FILE. In this case, your $PROMPT_FILE will be sourced,
whenever the value of $COLUMNS change, to reload your prompt. Example:
if [[ $COLUMNS -gt 100 ]]; then
PROMPT="<prompt1>"
elif [[ $COLUMNS -gt 50 ]]; then
PROMPT="<prompt2>"
else
PROMPT="<prompt3>"
fi
Variables
-
PROMPT_FILE: File which will be sourced (in order to reload thePROMPT), if no appropriate prompt-setting functions were found. Since, most ZSH users will have prompt defined somewhere inside their~/.zshrcfile, it is the default. However, if you have a dedicated file for your prompt, you can specify it with this option, which will speed up prompt rendering. -
PROMPT_BREAKPOINTS: If you use prompt-setting functions, you can use this variable to define the various$COLUMNSvalues, when the plugin should reload your prompt. Note that, you must define this variable in a decreasing array format. Default value:(120 90 60 0), which means that when$COLUMNSis greater than120,_prompt_120function will be called, and so on. If the plugin is unable to find a function by these names, your$PROMPT_FILEwill be sourced to reload the prompt. -
PROMPT_NEWLINE_AFTER: If you prefer to break your prompt into a multi-line prompt when it exceeds a given display length, you can use this variable to specify such length. Once the prompt exceeds this length, a newline character will be inserted in the variable$prompt_newline, which you can use inside your prompt definition. Otherwise, this variable will remain empty.