#
Custom Filters
Bashly supports custom filter functions for your commands. These filters allow you to define custom conditions that can prevent your command from running unless they are met.
This is how it works:
- In your Bashly configuration file, commands can include a
filters
option, which specifies an array of one or more function names. - Whenever you run your script, it will search for functions with those names,
prefixed by
filter_
, and execute them before running the command code. - If any of the functions return (echo) a string, it will be treated as an error. The returned string will be displayed on the screen as the error message.
bashly.yml
name: viewer
filters:
- docker_running
src/lib/filter_docker_running.sh
filter_docker_running() {
docker info > /dev/null 2>&1 || echo "Docker must be running"
}
Tips
- To verify a program is installed, use
dependencies
instead. - To verify an environment variable is defined, use
environment_variables
instead.