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.
This commit is contained in:
snailed 2023-02-22 09:24:17 +00:00 committed by GitHub
parent 6c92dfa4eb
commit 033c7f854d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,8 +2,7 @@
# Open a terminal window in the same directory as the currently active window. # 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 "$(xdotool getactivewindow getwindowpid)" | sed -En 's/.*,([0-9]+).*/\1/p' | tac)
PIDlist=$(pstree -lpATna "$windowPID" | sed -En 's/.*,([0-9]+).*/\1/p' | tac)
for PID in $PIDlist; do for PID in $PIDlist; do
cmdline=$(ps -o args= -p "$PID") cmdline=$(ps -o args= -p "$PID")
process_group_leader=$(ps -o comm= -p "$(ps -o pgid= -p "$PID" | tr -d ' ')") process_group_leader=$(ps -o comm= -p "$(ps -o pgid= -p "$PID" | tr -d ' ')")