Add prompt theme options #2

Closed
opened 2017-12-03 18:12:34 +00:00 by benie · 3 comments
Owner

Make prompt theme configurable, it should support:

  • disable git-prompt
  • disable almostontop
  • disable RPS1
Make prompt theme configurable, it should support: * disable git-prompt * disable almostontop * disable RPS1
Author
Owner

Writing Themes

The first step for adding your own theme is to choose a name for it, and
create a file prompt_<name>_setup in a directory in your fpath, such as
~/myfns in the example above. The file should at minimum contain assignments
for the prompt variables that your theme wishes to modify. By convention,
themes use PS1, PS2, RPS1, etc., rather than the longer PROMPT and
RPROMPT.

The file is autoloaded as a function in the current shell context, so it may
contain any necessary commands to customize your theme, including defining
additional functions. To make some complex tasks easier, your setup function may
also do any of the following:

Assign prompt_opts

The array prompt_opts may be assigned any of bang, cr, percent, sp,
and/or subst as values. The corresponding setopts (promptbang, etc.) are
turned on, all other prompt-related options are turned off. The prompt_opts
array preserves setopts even beyond the scope of localoptions, should your
function need that.

Modify precmd and preexec

Use of add-zsh-hook is recommended. The precmd and preexec hooks are
automatically adjusted if the prompt theme changes or is disabled.

Declare cleanup

If your function makes any other changes that should be undone when the theme is
disabled, your setup function may call prompt_cleanup command where command
should be suitably quoted. If your theme is ever disabled or replaced by
another, command is executed with eval. You may declare more than one such
cleanup hook.

Define preview

Define or autoload a function prompt_<name>_preview to display a simulated
version of your prompt. A simple default previewer is defined by promptinit
for themes that do not define their own. This preview function is called by
prompt -p.

Provide help

Define or autoload a function prompt_<name>_help to display documentation or
help text for your theme. This help function is called by prompt -h.

# Writing Themes The first step for adding your own theme is to choose a name for it, and create a file `prompt_<name>_setup` in a directory in your `fpath`, such as `~/myfns` in the example above. The file should at minimum contain assignments for the prompt variables that your theme wishes to modify. By convention, themes use `PS1`, `PS2`, `RPS1`, etc., rather than the longer `PROMPT` and `RPROMPT`. The file is autoloaded as a function in the current shell context, so it may contain any necessary commands to customize your theme, including defining additional functions. To make some complex tasks easier, your setup function may also do any of the following: ## Assign prompt_opts The array `prompt_opts` may be assigned any of `bang`, `cr`, `percent`, `sp`, and/or `subst` as values. The corresponding setopts (`promptbang`, etc.) are turned on, all other prompt-related options are turned off. The `prompt_opts` array preserves setopts even beyond the scope of `localoptions`, should your function need that. ## Modify precmd and preexec Use of `add-zsh-hook` is recommended. The `precmd` and `preexec` hooks are automatically adjusted if the prompt theme changes or is disabled. ## Declare cleanup If your function makes any other changes that should be undone when the theme is disabled, your setup function may call `prompt_cleanup` command where command should be suitably quoted. If your theme is ever disabled or replaced by another, command is executed with `eval`. You may declare more than one such cleanup hook. ## Define preview Define or autoload a function `prompt_<name>_preview` to display a simulated version of your prompt. A simple default previewer is defined by `promptinit` for themes that do not define their own. This preview function is called by `prompt -p`. ## Provide help Define or autoload a function `prompt_<name>_help` to display documentation or help text for your theme. This help function is called by `prompt -h`.
Author
Owner

Options for almostontop and RPS1 are easy enough as they are controlled
directory from prompt_fresh_setup but since the git prompt stats are in a hook
function the option needs to be propagated somehow.

Options for almostontop and RPS1 are easy enough as they are controlled directory from `prompt_fresh_setup` but since the git prompt stats are in a hook function the option needs to be propagated somehow.
Author
Owner

prompt_fresh_setup has been configurable since 7653ea6f93.

`prompt_fresh_setup` has been configurable since 7653ea6f937ba69e43af0f6eb4a5e1638d31bdd0.
benie closed this issue 2024-04-13 15:39:07 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: config/zsh#2
No description provided.