7

Say I have a window in kitty and press ctrl+shift+enter to open a new window.

The new window always uses ~/ as current working directory. I'd like the new window to use the same working directory that the last window used.

Is this possible?

aaguilera
  • 173
  • 1
  • 6

3 Answers3

12

In your kitty.conf, instead of using map ctrl+shift+enter new_window, use map ctrl+shift+enter new_window_with_cwd.

Couldn't find this in the documentation but the author mentions it in this issue.

jqno
  • 236
  • 1
  • 6
1

According to the documentation:

You can open a new window with the current working directory set to the working directory of the current window using:

map ctrl+alt+enter    launch --cwd=current

Works for me in Lubuntu 20.4:

~$ kitty --version
kitty 0.23.1 created by Kovid Goyal
~$ ack 'map ctrl\+shift\+enter' .config/kitty/
.config/kitty/kitty.conf
27:map ctrl+shift+enter launch --cwd=current
user272735
  • 111
  • 2
-1

You could save $PWD into a file and in your .bashrc change to the corresponding folder.

The following code is not a complete implementation but a proof-of-concept (which contains issues (e.g.: it does not handle parameters for cd)).

in .bashrc add following lines:

save_and_change_folder() {
  if [[ -d "$PWD/$1" ]]; then
    echo "$PWD/$1" > cat /home/<user>/.last_folder_visited
  fi
  cd "$1"
}
alias cd="save_and_change_folder"

if [[ -e "/home/<user>/.last_folder_visited" ]]; then
  cd "$(cat /home/<user>/.last_folder_visited)"
fi
noAnton
  • 361
  • 1
  • 6
  • Thanks for the reply. I was thinking more of something limited to kitty configuration options. Your solution is a good idea, but for me it's perhaps too coupled to bash configuration. – aaguilera Apr 02 '20 at 11:04