diff options
Diffstat (limited to 'artix/home/.local/bin/spawn-alacritty-cwd')
| -rwxr-xr-x | artix/home/.local/bin/spawn-alacritty-cwd | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/artix/home/.local/bin/spawn-alacritty-cwd b/artix/home/.local/bin/spawn-alacritty-cwd new file mode 100755 index 0000000..dcadff8 --- /dev/null +++ b/artix/home/.local/bin/spawn-alacritty-cwd @@ -0,0 +1,31 @@ +#!/bin/bash + +ACTIVE_WINDOW_INFO=$(hyprctl activewindow -j) + +CLASS=$(echo "$ACTIVE_WINDOW_INFO" | jq -r '.class') +PID=$(echo "$ACTIVE_WINDOW_INFO" | jq -r '.pid') + +if [[ "$CLASS" == "Alacritty" ]]; then + + if [[ -z "$PID" || "$PID" == "null" ]]; then + alacritty + exit 0 + fi + + CHILD_PID=$(pgrep -P "$PID" | head -n 1) + + if [[ -z "$CHILD_PID" ]]; then + alacritty + exit 0 + fi + + if [[ -e "/proc/$CHILD_PID/cwd" ]]; then + SHELL_CWD=$(readlink -f "/proc/$CHILD_PID/cwd") + alacritty --working-directory "$SHELL_CWD" + else + alacritty + fi + +else + alacritty +fi |
