ycwd – helps replace xcwd on Wayland compositors
Given the process ID of a terminal emulator, returns its current working directory. This allows you to quickly open a new terminal in the same directory as the currently focused one.
Example usage:
$ ycwd 323994
/home/blinry/wip/ycwdSpecifically, ycwd returns the deepest child process of the given process that is still attached to a tty. This means that it will work for sub-shells in many scenarios.
cargo install ycwd
Look up how to start your terminal emulator in a specific directory. We're assuming that $term is your terminal emulator (examples: kitty or foot), and that it has a --working-directory option.
You will need to find a way to find the correct process ID, how to do that depends on your compositor:
Add a key binding like this (requires jq):
Mod+Return { spawn "bash" "-c" "$term --working-directory=\"$(ycwd $(niri msg --json focused-window | jq .pid))\""; }
Add a key binding like this (requires jq):
bindsym $mod+Return exec $term --working-directory="$(ycwd $(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | .pid'))"
ycwd also works on X.org! Run it like this (requires xdotool):
ycwd $(xdotool getwindowfocus getwindowpid)On XFCE specifically, configure a keybinding that runs
sh -c 'exec exo-open --launch TerminalEmulator --working-directory="$(ycwd $(xdotool getwindowfocus getwindowpid))"'I'd be happy about a pull request!