From ef6dff4cce15186a66ba34cdd7bd39958ebf7f58 Mon Sep 17 00:00:00 2001 From: awy Date: Tue, 29 Jul 2025 03:42:18 +0300 Subject: first commit --- .local/bin/sd | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 .local/bin/sd (limited to '.local/bin/sd') diff --git a/.local/bin/sd b/.local/bin/sd new file mode 100755 index 0000000..6ac08a6 --- /dev/null +++ b/.local/bin/sd @@ -0,0 +1,22 @@ +#!/bin/sh + +# Open a terminal window in the same directory as the currently active window. + +windowPID=$(hyprctl activewindow | rg -oP '^\s*pid:\s*\K.*\S.*') +PIDlist=$(pstree -lpATna "$windowPID" | 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 ' ')") + cwd=$(readlink /proc/"$PID"/cwd) + # zsh and yazi won't be ignored even if it shows ~ or / + case "$cmdline" in + 'Yazi') continue ;; + "${SHELL##*/}"|'yazi'|'yazi '*) break ;; + esac + # git (and its sub-processes) will show the root of a repository instead of the actual cwd, so they're ignored + [ "$process_group_leader" = 'git' ] || [ ! -d "$cwd" ] && continue + # This is to ignore programs that show ~ or / instead of the actual working directory + [ "$cwd" != "$HOME" ] && [ "$cwd" != '/' ] && break +done +[ "$PWD" != "$cwd" ] && [ -d "$cwd" ] && { cd "$cwd" || exit 1; } +"$TERMINAL" -- cgit v1.2.3