i3 start new terminal in same directory using ctrl-windows-enter
I like the feature in i3 with which you can open a new terminal using windows-enter. But unfortunately it always starts in ~. A lot of the time I need a second terminal in a directory I'm already working in. Is there a way to get the directory of the currently active terminal and route that to the next one to be opened? Concretely, I would like to start a new terminal in the current directory of the active terminal (~ if the currently active window/split isn't a terminal) and bind that to ctrl-windows-enter.
11 Answer
In my opinion the cleanest way is to bind this functionality to a shortcut in your terminal emulator not in your WM.
Alacritty:
Add the following lines to alacritty.yml. You can then press Ctrl+Shift+Enter.
key_bindings: - { key: Return, mods: Control|Shift, action: SpawnNewInstance }st:
Apply the newterm patch. You can then press Ctrl+Shift+Enter.
But you can still use a script to launch your terminal. This shell script by Luke Smith should work on any window manager for X:
#!/bin/sh
PID=$(xprop -id "$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" | grep -m 1 PID | cut -d " " -f 3)
PID="$(pstree -lpA "$PID" | tail -n 1 | awk -F'---' '{print $NF}' | sed -re 's/[^0-9]//g')"
cd "$(readlink /proc/"$PID"/cwd)" || return 1
"$TERMINAL"You can also use xcwd to get the current working directory or use a Bash solution from this Unix & Linux question.
1