For the last couple of weeks I’ve been playing around with tmux as kind of an alternative/addon/… to iTerm2 and my
terminal-focused work-style in general. One things that drove me nuts again and again is that – for some reason – I
could never get the split-window command to respect my current working directory. I tried the first two solutions
mentioned on the ArchLinux-wiki
but the second simply did clash too much with how I’m using split-window and the first solution didn’t work at all (for
some reason PWD didn’t propagate correctly and so default-path always defaulted back to the cwd of tmux’ parent shell).

With all other options gone I started to look into the third solution.
This one involved extracting the PWD from the pane’s shell from the outside via /proc. But since I’m working on OSX,
this doesn’t work quite like this.

The main differences here are that I can’t use /proc to look for the PWD but have to rely on lsof and that ps
doesn’t have a forest-rendering. So the resulting script looks like this:

Gist
Thankfully, getting access to a process' PWD is pretty straight forward with `lsof -d cwd` and `ps` has a nice shortcut
for filtering for a specific tty. And yes, I know that the tty-scanning is really rocky up there and this is probably
the one part of this script that will evolve over time. The solution for the missing "--forest" support is also not
perfect yet, but so far it works just fine for me :-)
So, once you've put this script somewhere in your path (for me that ~/.local/bin/split-in-cwd.rb) and made it
executable, all that is left to do, is to add it to your split-window bindings: