Shell Hook (Auto Start/Stop)
Automatically start daemons when you enter a project directory and stop them when you leave.
Install the Shell Hook
Add the shell hook to your shell configuration:
bash
echo 'eval "$(pitchfork activate bash)"' >> ~/.bashrcbash
echo 'eval "$(pitchfork activate zsh)"' >> ~/.zshrcbash
echo 'pitchfork activate fish | source' >> ~/.config/fish/config.fishRestart your shell or source your config file for changes to take effect.
Configure Daemons
In your project's pitchfork.toml, add the auto option:
toml
[daemons.api]
run = "npm run server:api"
auto = ["start", "stop"] # Auto-start and auto-stop
[daemons.database]
run = "postgres -D /var/lib/pgsql/data"
auto = ["start"] # Auto-start only, stays running when you leave
[daemons.worker]
run = "npm run worker"
auto = ["stop"] # Manually start, auto-stops when you leaveAuto Options
| Value | Behavior |
|---|---|
["start"] | Daemon starts automatically when entering the directory |
["stop"] | Daemon stops automatically when leaving the directory |
["start", "stop"] | Both auto-start and auto-stop |
How It Works
- When you
cdinto a directory containingpitchfork.toml, daemons withauto = ["start", ...]are started - When you
cdout of the directory, daemons withauto = [..., "stop"]are marked for stopping - Pitchfork waits a few seconds before actually stopping, in case you quickly return to the directory
- If no terminal sessions are still in the directory, the daemons stop
TIP
You can manually start daemons with pitchfork start and they will still auto-stop when you leave if configured with auto = ["stop"].
Example Workflow
bash
# Enter your project directory
cd ~/projects/myapp
# api daemon starts automatically
# Work on your code...
# Leave the project
cd ~
# After a delay, api daemon stops (if no other terminals are in ~/projects/myapp)