Shared code and commands run elsewhere
Two pack features for bigger packs, written in the pack file.
Shared code
When several tools in a pack need the same helper, like a function, write it once in [pack.prelude]. It goes in
front of every script in the pack that uses that language:
[pack.prelude]
powershell = '''
function Get-Greeting([string]$Name) { "Hello, $Name!" }
'''
[[tool]]
name = "greet"
description = "Greet someone"
read_only = true
script = { shell = "powershell", code = "Get-Greeting {{ who }}" }
[tool.params]
who = "Who to greet"
The key is the script's language: powershell, sh, bash, python and so on. The built-in WSL pack keeps its
Invoke-Wsl helper this way.
Commands run somewhere else
Some tools run a command you give them somewhere other than your own terminal: inside WSL, on a server over SSH, or
in a container. Mark the parameter that holds the command with shell_command:
[[tool]]
name = "server_run"
description = "Run a command on my server"
confirm = true
shell_command = "command"
command = ["ssh", "my-server", "{{ command }}"]
[tool.params]
command = "The command to run"
Then:
- the command is checked against the same blocked list as the terminal tool, so things like
sudoandshutdownare refused - the approval question shows the command itself
See also Writing packs by hand.