From 033c7f854d6d5ed2f384b12bf61f8e3c5609fa6b Mon Sep 17 00:00:00 2001 From: snailed Date: Wed, 22 Feb 2023 09:24:17 +0000 Subject: [PATCH] Improve window PID discovery in sd script The current way of finding the PID of the active window is quite fragile due to the extremely loose regex in place. Since xdotool is already a dependency of multiple other scripts I'd recommend just using that. --- .local/bin/sd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.local/bin/sd b/.local/bin/sd index a0ff84c2..f6de1263 100755 --- a/.local/bin/sd +++ b/.local/bin/sd @@ -2,8 +2,7 @@ # Open a terminal window in the same directory as the currently active window. -windowPID=$(xprop -id "$(xprop -root | sed -n "/_NET_ACTIVE_WINDOW/ s/^.*# // p")" | sed -n "/PID/ s/^.*= // p") -PIDlist=$(pstree -lpATna "$windowPID" | sed -En 's/.*,([0-9]+).*/\1/p' | tac) +PIDlist=$(pstree -lpATna "$(xdotool getactivewindow getwindowpid)" | sed -En 's/.*,([0-9]+).*/\1/p' | tac) for PID in $PIDlist; do cmdline=$(ps -o args= -p "$PID") process_group_leader=$(ps -o comm= -p "$(ps -o pgid= -p "$PID" | tr -d ' ')")