summaryrefslogtreecommitdiff
path: root/scripts/.local/bin/samedir
diff options
context:
space:
mode:
author--global <ik.boikov.public@protonmail.com>2021-07-14 23:02:24 +0200
committer--global <ik.boikov.public@protonmail.com>2021-07-14 23:02:24 +0200
commitfd850fb2ed9870edcb1df205e08e8ccb25fb6760 (patch)
tree641b5af724d86a0a383b2c580dd838b03c1cc42c /scripts/.local/bin/samedir
parent72000d2f0c23a685f4c4d458158712340f6b9a68 (diff)
more nnn plugins, more luke's scripts
Diffstat (limited to 'scripts/.local/bin/samedir')
-rwxr-xr-xscripts/.local/bin/samedir8
1 files changed, 8 insertions, 0 deletions
diff --git a/scripts/.local/bin/samedir b/scripts/.local/bin/samedir
new file mode 100755
index 0000000..73facfd
--- /dev/null
+++ b/scripts/.local/bin/samedir
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+# Open a terminal window in the same directory as the currently active window.
+
+PID=$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep -m 1 PID | cut -d " " -f 3)
+PID="$(pstree -lpA "$PID" | tail -n 1 | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g')"
+cd "$(readlink /proc/"$PID"/cwd)" || return 1
+"$TERMINAL"