How to open the same directory in a new iTerm2 window or tab
Sometimes I want the same directory in multiple terminals, such as when I’m editing a site’s code in Neovim in one tab while having the site loaded and hot reloading in another tab.
However, to have x number of terminals with the same directory open, I would have to make a new tab/window and cd into that directory x amount of times. How many times would I possibly have to do this? God knows, but any more than once seems inefficient to me.
I didn’t want to modify profiles, haven’t dove into that segment of iTerm2 yet, so these solutions avoid doing that.
The most basic method I found was to just run:
open . -a iterm2 # You could actually replace "iterm2" with "terminal" to use the native one, if you want
This does about what you’d expect, opens the same directory in a new terminal window. Quite convenient.
But if you want to open the same directory in a new tab, there’s actually a very handy menu option to do so. (Shell > Duplicate Tab)
You can set a keybinding for Duplicate Tab in (Preferences > Keys > +)
No more excessive cd
’ing! Lovely.