Crate zsh_module
source ·Expand description
This is a high level crate that allows you to define your own zsh module.
Getting started
To get started, first, you need to create library, not an executable. Then, change your crate
type to "cdylib" on your Cargo.toml:
[lib]
crate-type = ["cdylib"]
Boilerplate
On your lib.rs, you need to put a impl_hooks macro call, alongside a setup function
with the following signature:
use zsh_module::{ Module, ModuleBuilder }
zsh_module::impl_hooks!();
fn setup() -> Result<Module, ()> {
todo!()
}Defining Actions
The main point part of crating a module is implementing Actions. Here’s an example module:
use zsh_module::{ Module, ModuleBuilder, Actions, Result }
zsh_module::impl_hooks!();
struct Greeter;
impl Actions for Greeter {
fn boot(mut &self) -> Result<()> {
println!("Hello, everyone!");
Ok(())
}
fn cleanup(&mut self) -> Result<()> {
println!("Bye, everyone!");
Ok(())
}
}
fn setup() -> Result<Module> {
let module = ModuleBuilder::new()
.build(Greeter);
Ok(module)
}Installing
When your module is ready, copy your shared library to your distribution’s zsh module folder,
without the lib prefix.
On Arch Linux, it’s /usr/lib/zsh/<zsh-version>/zsh/.
That is it!
If everything went fine, you can load it in zsh using the following command:
zmodload zsh/<module-name>
Modules
Zsh native log functions. This module contains high level interfaces to the zsh log functions.
Macros
This macro defines hooks to the zsh C functions, therefore, you must put this in the same
file as your
setup function.Prints out a warning message from a command, like
println!Structs
Properties of a zsh builtin command
A zsh module. You must build it using
ModuleBuilderAllows you to build a
ModuleTraits
This trait allows for defining behaviour to be enacted on parts of the zsh module lifecycle.
Type Definitions
Trait Aliases
This trait corresponds to the function signature of a zsh builtin command handler.