每当在 bash 中运行特定命令时,我都会尝试写入 webhook。例如,当ls
被调用时,运行一个脚本。
更具体地说,当命令spark
运行时,我想使用他们的 webhook 写入一个松弛通道。
Put a wrapper earlier in the PATH. Let's say that spark
is in /usr/bin
. If your users' PATHS have /usr/local/bin
before /usr/bin
, then you can do this in /usr/local/bin/spark
:
#!/bin/sh
[ "${_SPARK_WRAPPER_DONE}" ] || send-to-slack-here "$@"
export _SPARK_WRAPPER_DONE=1
exec /usr/bin/spark "$@"
...where send-to-slack-here
, of course, is your code to send a message to Slack.
You could also move /usr/bin/spark
to /usr/bin/spark.real
and put your wrapper in the original executable's place.
If you control .bashrc
, you could also use a shell function (though this will work in fewer scenarios):
spark() {
send-to-slack-here "$@"
/usr/bin/spark "$@"
}