37 lines
1.7 KiB
Bash
Executable File
37 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
json=$(cat)
|
|
hook_event_name=$(jq -r '.hook_event_name' <<< "$json")
|
|
tool_name=$(jq -r '.tool_name' <<< "$json")
|
|
session_id=$(jq -r '.session_id' <<< "$json")
|
|
file_path=$(jq -r '.tool_input.file_path' <<< "$json")
|
|
if [ "$hook_event_name" == "PreToolUse" ];then
|
|
if [ "$tool_name" == "Read" ]; then
|
|
notify-hook log "$(echo -e "session:$session_id, \n开始读取文件:$file_path")"
|
|
elif [ "$tool_name" == "Write" ]; then
|
|
notify-hook log "session:$session_id, 开始创建文件:$file_path"
|
|
elif [ "$tool_name" == "Edit" ]; then
|
|
notify-hook log "session:$session_id, 开始编辑文件:$file_path"
|
|
fi
|
|
elif [ "$hook_event_name" == "PostToolUse" ];then
|
|
|
|
if [ "$tool_name" == "Read" ]; then
|
|
notify-hook log "session:$session_id, 读取了文件:$file_path"
|
|
elif [ "$tool_name" == "Write" ]; then
|
|
notify-hook log "session:$session_id, 创建了文件:$file_path"
|
|
elif [ "$tool_name" == "Edit" ]; then
|
|
notify-hook log "session:$session_id, 编辑了文件:$file_path"
|
|
elif [ "$tool_name" == "Bash" ]; then
|
|
command_content=$(jq -r '.tool_input.command' <<< "$json")
|
|
std_err=$(jq -r '.tool_response.stderr' <<< "$json")
|
|
interrupted=$(jq -r '.tool_response.interruptedr' <<< "$json")
|
|
if [ "$interrupted" == "true" ]; then
|
|
notify-hook log "$(echo -e "session:$session_id, \n命令:$command_content. 执行终止!!!")"
|
|
elif [ "$std_err" == "" ]; then
|
|
notify-hook log "session:$session_id, 命令:$command_content. 执行成功."
|
|
else
|
|
notify-hook log "session:$session_id, 命令:$command_content. 执行失败:$std_err"
|
|
fi
|
|
fi
|
|
fi
|