From 0e95d05575ccbdfcf0bdb12b2f4796563f7add7a Mon Sep 17 00:00:00 2001 From: AnnatarHe Date: Tue, 6 Jan 2026 01:27:34 +0800 Subject: [PATCH 1/2] feat(hooks): add PPID capture for terminal tracking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass parent process ID to shelltime track command for terminal emulator detection in daemon service. - bash: add --ppid=$PPID to track calls - zsh: add --ppid=$PPID to track calls - fish: capture PPID at startup, add --ppid flag 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- hooks/bash.bash | 6 +++--- hooks/fish.fish | 7 +++++-- hooks/zsh.zsh | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/hooks/bash.bash b/hooks/bash.bash index 287ae96..7787714 100644 --- a/hooks/bash.bash +++ b/hooks/bash.bash @@ -40,7 +40,7 @@ preexec_invoke_cmd() { return fi - shelltime track -s=bash -id=$SESSION_ID -cmd="$CMD" -p=pre &> /dev/null + shelltime track -s=bash -id=$SESSION_ID -cmd="$CMD" -p=pre --ppid=$PPID &> /dev/null } # Function to be executed after each command (before prompt) @@ -57,13 +57,13 @@ precmd_invoke_cmd() { if [[ "$CMD" =~ ^shelltime ]]; then return fi - + # Ensure CMD is not empty or the precmd_invoke_cmd itself if [ -z "$CMD" ] || [ "$CMD" == "precmd_invoke_cmd" ]; then return fi - shelltime track -s=bash -id=$SESSION_ID -cmd="$CMD" -p=post -r=$LAST_RESULT &> /dev/null + shelltime track -s=bash -id=$SESSION_ID -cmd="$CMD" -p=post -r=$LAST_RESULT --ppid=$PPID &> /dev/null } # Set the functions for bash-preexec diff --git a/hooks/fish.fish b/hooks/fish.fish index 435a2bd..da25227 100644 --- a/hooks/fish.fish +++ b/hooks/fish.fish @@ -10,13 +10,16 @@ end # Create a timestamp for the session when the shell starts set -g SESSION_ID (date +%Y%m%d%H%M%S) +# Capture parent process ID at shell startup (fish doesn't have native $PPID) +set -g FISH_PPID (ps -o ppid= -p %self | string trim) + # Define the preexec function function fish_preexec --on-event fish_preexec if string match -q 'exit*' -- $argv; or string match -q 'logout*' -- $argv; or string match -q 'reboot*' -- $argv return end - shelltime track -s=fish -id=$SESSION_ID -cmd="$argv" -p=pre > /dev/null + shelltime track -s=fish -id=$SESSION_ID -cmd="$argv" -p=pre --ppid=$FISH_PPID > /dev/null end # Define the postexec function @@ -26,5 +29,5 @@ function fish_postexec --on-event fish_postexec return end # This event is triggered before each prompt, which is after each command - shelltime track -s=fish -id=$SESSION_ID -cmd="$argv" -p=post -r=$LAST_RESULT > /dev/null + shelltime track -s=fish -id=$SESSION_ID -cmd="$argv" -p=post -r=$LAST_RESULT --ppid=$FISH_PPID > /dev/null end diff --git a/hooks/zsh.zsh b/hooks/zsh.zsh index 0384f7a..a6dcc24 100644 --- a/hooks/zsh.zsh +++ b/hooks/zsh.zsh @@ -19,7 +19,7 @@ preexec() { return fi - shelltime track -s=zsh -id=$SESSION_ID -cmd=$CMD -p=pre &> /dev/null + shelltime track -s=zsh -id=$SESSION_ID -cmd=$CMD -p=pre --ppid=$PPID &> /dev/null } # Define the postexec function (in zsh, it's called precmd) @@ -30,5 +30,5 @@ precmd() { if [[ $CMD =~ ^(exit|logout|reboot) ]]; then return fi - shelltime track -s=zsh -id=$SESSION_ID -cmd=$CMD -p=post -r=$LAST_RESULT &> /dev/null + shelltime track -s=zsh -id=$SESSION_ID -cmd=$CMD -p=post -r=$LAST_RESULT --ppid=$PPID &> /dev/null } From 4b529c743d724d88bde1bd333992d9c04dba9a6e Mon Sep 17 00:00:00 2001 From: AnnatarHe Date: Tue, 6 Jan 2026 21:16:03 +0800 Subject: [PATCH 2/2] fix(zsh): quote $CMD variable to prevent word splitting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commands containing spaces (e.g., `ls -l`) would undergo word splitting, causing incorrect arguments to be passed to shelltime track. This aligns with the quoting pattern already used in bash.bash and fish.fish. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- hooks/zsh.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/zsh.zsh b/hooks/zsh.zsh index a6dcc24..fb89c05 100644 --- a/hooks/zsh.zsh +++ b/hooks/zsh.zsh @@ -19,7 +19,7 @@ preexec() { return fi - shelltime track -s=zsh -id=$SESSION_ID -cmd=$CMD -p=pre --ppid=$PPID &> /dev/null + shelltime track -s=zsh -id=$SESSION_ID -cmd="$CMD" -p=pre --ppid=$PPID &> /dev/null } # Define the postexec function (in zsh, it's called precmd) @@ -30,5 +30,5 @@ precmd() { if [[ $CMD =~ ^(exit|logout|reboot) ]]; then return fi - shelltime track -s=zsh -id=$SESSION_ID -cmd=$CMD -p=post -r=$LAST_RESULT --ppid=$PPID &> /dev/null + shelltime track -s=zsh -id=$SESSION_ID -cmd="$CMD" -p=post -r=$LAST_RESULT --ppid=$PPID &> /dev/null }