The Kirby command line interface helps simplifying common tasks with your Kirby installations.
Make sure to add your composer bin directory to your
~/.bash_profile (Mac OS users) or into your
~/.bashrc (Linux users).
Your global composer directory is normally either
~/.config/composer/vendor/bin. You can find the correct path by running …
Afterwards, add the result to your bash profile …
Check if the installation worked by running the following in your terminal.
This should print the Kirby CLI version and a list of available commands
You can create a new command via the CLI:
This will create a new
site/commands folder in your installation with a new
The CLI will already put the basic scaffolding into the file:
You can define your command logic in the command callback. The
$cli object comes with a set of handy tools to create output, parse command arguments, create prompts and more.
You might have some commands that you need for all your local Kirby installations. This is where global commands come in handy. You can create a new global command with the
The command file will then be place in
~/.kirby/commands/hello.php and is automatically available everywhere.
Your Kirby plugins can define their own set of commands: https://getkirby.com/docs/reference/plugins/extensions/commands
You can always check back if your commands have been created properly by running
Once you no longer need a command, you can remove it with …
If you have a local and a global command, you can choose which one to delete.
Sending messages to the terminal is super easy.
For more available colors and formats, check out the CLImate docs: https://climate.thephpleague.com/styling/colors/
Your commands can define a list of required and optional arguments that need to be provided by the user.
The command can now be executed by providing the name …
If no name is provided, an error will be shown.
Arguments can be required, can set a default value and more. Check out the CLImate docs for additional options: https://climate.thephpleague.com/arguments/
Instead of taking arguments from the command, you can also ask for them in a prompt:
As a third alternative you can either take the argument or ask for it if it is not provided:
The CLI also supports more complex ways to get input from users. Check out the CLImate docs how to work with user input: https://climate.thephpleague.com/terminal-objects/input/
You can reuse all existing commands in your custom commands to create entire chains of actions.
Other plugins by Kirby Team