Improve sd script (#1235)

* Improve sd script

Now sd will also work on apps like mpv and zathura

* Fix sd script not working on firefox
This commit is contained in:
Rokosun 2022-11-16 16:04:26 +00:00 committed by GitHub
parent d6616cf08b
commit 0efa08107c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,10 +2,8 @@
# 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.
PID=$(xprop -id "$(xprop -root | xprop -root | sed -n "/_NET_ACTIVE_WINDOW/ s/^.*# // p")" | sed -n "/PID/ s/^.*= // p") PID=$(xprop -id "$(xprop -root | sed -n "/_NET_ACTIVE_WINDOW/ s/^.*# // p")" | sed -n "/PID/ s/^.*= // p")
PID="$(pstree -lpA "$PID")" PID=$(pstree -lpATna "$PID" | grep -v '\-\(lf,[0-9]\+ -server\|(st-urlhandler,[0-9]\+)\|xclip,[0-9]\+\)' | sed '$s/.*,\([0-9]\+\).*/\1/;t;d')
PID="${PID##*"${SHELL##*/}"(}" cwd=$(readlink /proc/"$PID"/cwd)
PID="${PID#*lf(}" [ "$PWD" != "$cwd" ] && [ -d "$cwd" ] && { cd "$cwd" || exit 1; }
PID="${PID%%)*}"
cd "$(readlink /proc/"$PID"/cwd)" || return 1
"$TERMINAL" "$TERMINAL"