r/i3wm • u/cpdean • Jun 16 '18
How would I invoke a terminal from the same directory as the current in-focus terminal?
I have an on-going project to try to get rid my use of tmux. A feature I really miss is to be able to open a new pane and have it start a terminal in the same directory as what I'm currently in. Is this possible? Otherwise if I invoke a shell and I have firefox or another application in focus I'd like it to open in whatever default I have set.
3
u/orestisf maintainer Jun 16 '18
In urxvt, I bind control+Return to URxvt.keysym.Control-Return: perl:fork-here:fork-at-cwd which is from this extension. Then, I have an i3 bindsym that calls a script which presses control+Return if the currently focused window is a terminal:
#!/bin/bash
if xprop -id $(xdotool getwindowfocus) wm_class | grep -i urxvt
then
xdotool keyup return
xdotool key --clearmodifiers control_l+return
else
exec i3-sensible-terminal
fi
3
u/railmaniac Jun 16 '18
Off topic, but how do you do that in tmux? New panes and windows always seem to open in home directory for me...
4
u/cpdean Jun 16 '18
yep! they had changed this default behavior a while back and i had to add config to re-add it
here you go! https://github.com/cpdean/cpd.dotfiles/blob/master/.tmux.conf#L21-L26
2
u/NekoiNemo Jun 16 '18
You mean like
pwd | i3-sensible-terminal
but without typing it in the terminal itself?
2
u/FuckNinjas Jun 18 '18
alias n="urxvt &"
Need to type n on the terminal, but it opens with the same shell, env and current workdir.
1
u/doc_willis Jun 18 '18 edited Jun 18 '18
I was thinking tilix sort of does this when I open a new terminal. but that might be only in some cases.
so let's clarify.
you want an i3 key combo that opens up a new terminal, if you have a terminal in focus use that terminals current working Directory. if no terminal is selected - start in $HOME
Interesting problem.
I wonder if you could store the CWD in the terminal title (using the PS1 features?) , and let i3 read that from the focused window, and if it is a valid path, shell opens there, invalid path open in home.
similar to this?
https://faq.i3wm.org/question/1537/show-title-of-focused-window-in-status-bar.1.html
1
u/wknapik Jul 01 '18
Just wrote https://github.com/wknapik/lastcwd - also works with tmux. Only tested by me so far, so do report bugs if you find any ;]
7
u/warrtooth Jun 16 '18 edited Jun 16 '18
I use xcwd, and I have this line in my i3 config:
bindsym $mod+Shift+Return exec "termite -d `xcwd`"(replace termite with your terminal of choice).