/ de-omarchy / bin / omarchy-cmd-terminal-cwd
swadhinbiswas Initial de-omarchy: Omarchy UI layer for Arch-based distros · 8/22/2026
9f393b2
28 lines · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash

# omarchy:summary=Print the current working directory of the active terminal window
# omarchy:hidden=true

terminal_pid=$(hyprctl activewindow | awk '/pid:/ {print $2}')
kitty_socket="$XDG_RUNTIME_DIR/omarchy-kitty-$terminal_pid"
cwd=""

if [[ -S $kitty_socket ]]; then
  cwd=$(kitten @ --to "unix:$kitty_socket" ls --match "state:focused" 2>/dev/null |
    jq -r '.[].tabs[].windows[].cwd // empty')
else
  shell_pid=$(pgrep -P "$terminal_pid" | tail -n1)

  if [[ -n $shell_pid ]]; then
    cwd=$(readlink -f "/proc/$shell_pid/cwd" 2>/dev/null)
    shell=$(readlink -f "/proc/$shell_pid/exe" 2>/dev/null)
    grep -Fqsx "$shell" /etc/shells || cwd=""
  fi
fi

if [[ -d $cwd ]]; then
  echo "$cwd"
else
  echo "$HOME"
fi