Key bind that uses active/current window ${PWD}?

Hyprland version
Hyprland 0.51.1 built from branch  at commit 71a1216abcc7031776630a6d88f105605c4dc1c9  ([gha] Nix: update inputs).
Date: Mon Sep 22 20:54:03 2025
Tag: v0.51.1, commits: 6436
built against:
 aquamarine 0.9.5
 hyprlang 0.6.3
 hyprutils 0.10.0
 hyprcursor 0.1.13
 hyprgraphics 0.2.0


no flags were set

Describe your issue / feature…

How do I define a key bind for exec that passes the active window’s current working directory in the command? I’m trying to use $PWD to do it, but none of my attempts work.

I’m running Arch, using uwsm/systemd setup.

Specifically I’m trying to launch yazi via key bind (but in this case, I want to be specific regarding the location.) I can launch yazi just fine if I don’t care about the starting location; I got another key bind for that, looks like this:

bind = $mainMod, E, exec, uwsm app –- $terminal -e $fileManager

(I’m using ghostty for terminal.)

In theory I just need to pass the location to yazi (the fileManager) when I run it, to tell it the starting location i.e.:

yazi ~/Applications or yazi ${PWD} or (if PWD were home dir) yazi ${PWD}/Applications …all valid commands.

So I tried this (and various attempts of the same idea, like using ghostty’s –-comand= instead of -e .):

uwsm app –- $terminal -e $fileManager “${PWD}”

Many of my tried commands worked if I run them from the terminal, but not when executed via the bind. It seems that maybe for some reason $PWD is always my home dir, when using the key bind? If I do this, it starts correctly at the ~/Applications dir:

uwsm app –- $terminal -e $fileManager ‘${PWD}/Applications’

Or, if I do this command:

uwsm app –- $terminal --command=“printf ${PWD}; read -n 1”

I get my home dir.

So I think it’s all technically working, just that PWD value is always home dir. So I guess the real question would then be how do I get the active window’s current working directory so I can pass it that path, in the key bind definition? I feel like it should be pretty simple and I’m just missing something. Anyone can help? Thanks

Create an executable script .sh and parse that with uwsm.

Thanks, yeah that was a good suggestion, but doesn’t seem quite possible currently (well, I don’t see a good way at least.)

So the script would need to (basically):

  1. figure out what the active window is
  2. get that window’s program’s CWD
  3. now you have the dir location, you can use it how however needed (in my case, I could run yazi passing the cwd.)

I don’t know about other terminals, but with ghostty it doesn’t seem to be currently possible. In the steps, step 2 is where the problem mainly is.

For step 1, you can use hyprctl activewindow.

The activewindow output gives various info, but none are all that helpful for this, as a reliable solution. But it does give the PID, which is something you could potentially make use of for step 2.

For step 2, to get the cwd of the program you can do pwdx {PID}.

However, ghostty works as a single background service, and I guess because of that, the PID is always the same one that hyprlctl reports (i.e. hyprctl clients show the same PID for every ghostty window) - the main parent background service, I believe. So using pwdx on that pid doesn’t give you what you want (of course.)

Since that PID is a parent process, we can list the spawned child processes. E.g.:

pgrep -a -P {PID}

However, you don’t have a way to distinguish which of those is of the active window you’re trying to target. I.e. You can get the cwd paths but yeah, you don’t know which one is the one you want. E.g. (there’s two ghostty windows open in this example; one is in ~/bin, the other in ~/Applications. i’m using the ~/bin window to run the commands.):

❯  hyprctl activewindow
Window 559ec31d4dd0 -> hyprctl activewindow :
        ..{snip}..
        class: com.mitchellh.ghostty
        title: hyprctl activewindow
        initialClass: com.mitchellh.ghostty
        initialTitle: Ghostty
        pid: 1262
        ..{snip}..

❯  pgrep -a -P 1262
1451 /usr/bin/bash --posix
31961 /usr/bin/bash --posix

❯  pwdx 1451
1451: /home/arnas/bin

❯  pwdx 31961
31961: /home/arnas/Applications

So, yeah, there isn’t a way to connect the info stuff, that I can see.

You can also maybe do something with looking at this from another angle; the perspective of the terminal. Since ghostty has the cli, so starting a new window would be running ghostty +new-window (which tells the service to create a new window.) And with the window-inherit-working-directory setting, you could maybe get the same functionality… but currently doesn’t look like you can pass commands to the new window at the same time, i.e. this doesn’t work ghostty +new-window -e yazi. Although introducing this feature seems to be planned.

Anyways, guess I’ll leave it for now, but that’s my info on this if anyone else looking into achieving the same thing.

uhhh, get the pid from activewindow then get readlink /proc/pid/cwd?

1 Like

Um, maybe my reply post wasn’t clear; that doesn’t work with ghostty. activewindow reports the main parent process (from what I can tell)… well, I think I explained it all already in that reply, so not sure what else to say about it. I’d just be repeating that post lol.

that means both windows have the same pid, thats it, you cant