Skip to content

Plugins

Davis Forsythe edited this page Dec 26, 2024 · 5 revisions

Creating plugins

Creating plugins is pretty simple. It's just create a function with the proper syntax and you have a new module.

Basic module

The function should be named integral:module:<MODULE NAME>. If it's passed an argument ($1), it needs to output its length, if not, it needs to output the text in ZSH prompt syntax. If you want to hide the module (such as when it's not needed), output a length of 0.

Here's an example:

integral:module:arch-logo() {
  if [[ $1 ]]; then
    print "1"
  fi
  print "󰣇"
}

Wrapping support

Should your module be long enough it can cross the edge of the screen, you should probably add wrapping support. Unfortunately, due to the current implementation, modules that can wrap can only have one color. You can technically add whatever formatting you like, but it's likely to get mangled during the wrapping function.

You need to add some extra processing. You need to add a check for when the first argument is "w", and return 1 when if it is. This need to be before the normal $1 check. After that, $1 will be "r" when requesting the raw, unformatted string, and "c" when asking for the color. Make sure to keep the normal length check.

Here's an example from the included modules:

integral:module:dir() {
  local dir=$(int_dir_format)
  if [[ $1 == "w" ]]; then
    return 1
  elif [[ $1 == "r" ]]; then
    print "$dir"
  elif [[ $1 == "c" ]]; then
    print "%F{$int_dir_color}"
  elif [[ $1 ]]; then
    print "${#dir}"
  else
    print "%F{$int_dir_color}$dir"
  fi
}

Sourcing a plugin

If you want to create/distribute a large amount of plugins, it's best to add the path to your plugin file to the $int_plugins list. But using this method means your plugin needs to be loaded before the normal prompt.

Clone this wiki locally