Skip to content

Templates

Pascal Zarrad edited this page Mar 26, 2024 · 6 revisions

Templates are an easy way to customize zsh to fit your needs. You can use them to apply entire predefined snippets of a .zshrc. This enables a fast and easy way to to customize psh without many experience in shell scripting - but even advanced users can combine templates and plugins to use compose great things together!

If you want to add something that needs to interact with the user or system where psh is being installed, a plugins may be the better choice.

How templates work

Templates are simple files with a special directive in the head of the file that tells psh where to put the template into the .zshrc. This enables the fast and easy creation of short snippets (like a collection of aliases). The templates must be located in the templates directory and should end with <file-name>.template.zshrc. The templates are being loaded and applied at the position in the .zshrc, that you defined using the #PSH_TEMPLATE=<TYPE> directive.

Example

Your templates have to have the #PSH_TEMPLATE=<TYPE>-directive to work. Where type defines the position of the template in your generated .zshrc. A list of all available types is available under "Template positions".

#PSH_TEMPLATE=END
alias psh=zsh
# A comment and then another alias
alias test=ps aux | grep java

Template positions

The following types are available for the position of templates in the templates directive:

Type Position
START Placed directly after the generated header, but before zplug is being loaded
BETWEEN_ZPLUG_AND_OH_MY_ZSH Placed between after zplug has been loaded, but before oh-my-zsh is added
BETWEEN_OH_MY_ZSH_AND_PLUGINS Placed after oh-my-zsh has been applied, but before the plugins are added
AFTER_PLUGINS_BEFORE_ZPLUG_APPLY Placed afte the plugins have been added, but before zplug's changes are applied
END Placed at the end of the the .zshrc
Clone this wiki locally