summaryrefslogtreecommitdiffstats
path: root/.local/bin/sd
blob: 8047d33bdcd8990b3b1ea58fbc263b491facbf97 (plain) (blame)
1
2
3
4
5
6
7
8
9
#!/bin/sh

# Open a terminal window in the same directory as the currently active window.

PID=$(xprop -id "$(xprop -root | sed -n "/_NET_ACTIVE_WINDOW/ s/^.*# // p")" | sed -n "/PID/ s/^.*= // p")
PID=$(pstree -lpATna "$PID" | grep -v '\-\(lf,[0-9]\+ -server\|(st-urlhandler,[0-9]\+)\|xclip,[0-9]\+\)' | sed '$s/.*,\([0-9]\+\).*/\1/;t;d')
cwd=$(readlink /proc/"$PID"/cwd)
[ "$PWD" != "$cwd" ] && [ -d "$cwd" ] && { cd "$cwd" || exit 1; }
"$TERMINAL"