niri: spawn foot deriving cwd from focused window if possible
2 files changed, 7 insertions(+), 7 deletions(-)

M bin/sway-focused-window-cwd => bin/niri-focused-window-cwd
M dot.config/niri/config.kdl
M bin/sway-focused-window-cwd => bin/niri-focused-window-cwd +6 -6
@@ 5,24 5,24 @@ expand_tilde () {
     [ "$p" = "$1" ] && echo "$p" || echo "$HOME$p"
 }
 
-{ read -r app_id; read -r name; read -r pid; } <<EOF
-$(swaymsg -t get_tree \
-    | jq -r 'recurse(.nodes[]) | select(.focused? and .pid?) | [.app_id, .name, .pid] | join("\n")')
+# TODO: somehow obtain pid
+{ read -r app_id; read -r title; } <<EOF
+$(niri msg --json focused-window | jq -r '[.app_id, .title] | join("\n")')
 EOF
 
 path=
 case "$app_id" in
     foot)
         # for terminal emulators, get pwd of the shell from window title
-        path="$(expand_tilde ${name#*: })"  # %n@%m: %~
+        path="$(expand_tilde ${title#*: })"  # %n@%m: %~
         ;;
 esac
 
 print_cwd () {
     if [ -n "$path" -a -d "$path" ]; then
         echo "$path"
-    elif [ -n "$pid" ]; then
-        readlink "/proc/$pid/cwd"
+    #elif [ -n "$pid" ]; then
+    #    readlink "/proc/$pid/cwd"
     else
         echo "$HOME"
     fi

          
M dot.config/niri/config.kdl +1 -1
@@ 309,7 309,7 @@ binds {
     Mod+Shift+Slash { show-hotkey-overlay; }
 
     // Suggested binds for running programs: terminal, app launcher, screen locker.
-    Alt+Return { spawn "foot"; }
+    Alt+Return { spawn "niri-focused-window-cwd" "foot"; }
     Mod+D { spawn "foot" "-afoot-menu" "niri-app-menu"; }
     Super+Alt+L { spawn "swaylock"; }