Skip to content

Instantly share code, notes, and snippets.

@mrdomino
Last active January 16, 2024 20:10
Show Gist options
  • Save mrdomino/e988ab72cb46571dc5f5a9accadb53d9 to your computer and use it in GitHub Desktop.
Save mrdomino/e988ab72cb46571dc5f5a9accadb53d9 to your computer and use it in GitHub Desktop.
kill zsh with USR1 every time a path directory changes
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.wholezero.watchpath</string>
<key>ProgramArguments</key>
<array>
<string>/bin/zsh</string>
<string>-lc</string>
<string>fswatch -o "${path[@]}" | xargs -n1 -I{} pkill -USR1 -u "$UID" zsh</string>
</array>
<key>KeepAlive</key>
<true/>
</dict>
</plist>
<!-- vi: set noet :vi -->
@mrdomino
Copy link
Author

mrdomino commented Jan 9, 2024

For this to work, you need something like this in your ~/.zshrc:

TRAPUSR1() { rehash }

And you probably want something like this in ~/.zshenv:

[[ ! -o interactive ]] && TRAPUSR1(){}

@mrdomino
Copy link
Author

mrdomino commented Jan 10, 2024

Oh, I had a hard time getting this working. This is what worked for me in the end:

launchctl enable gui/$(id -u)/org.wholezero.watchpath
launchctl load -w ~/Library/LaunchAgents/org.wholezero.watchpath.plist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment