Copy working directory from one terminator screen to another

1k views Asked by At

How can one copy with keyboard shortcuts the working directory of one terminator screen to another ?

For example, I have two split windows (thanks to Ctrl+Shift+E). One of them has its working directory (wd) set to ~ and the other has its wd set to ~/work/old/project/foo/bidule/version-2.6.7-a-beta/empty/test/latest. I would like to change the wd of the first to wd of the second.

First method, type cd ~/work/old/… on the first split window. This works, but its a difficult task because the directory name is long and hard to type.

Second method, type cd on the first split window, then copy and paste the path from the prompt of the second terminal (or from pwd if the prompt does not contain the complete path). This works, but we need to copy and paste a text from a terminal with the mouse, which is a difficult task for someone who has always his hands on the keyboard. :)

Is there a way with shortcuts to do the same stuff ?

2

There are 2 answers

2
AAAfarmclub On BEST ANSWER

(I'm running BASH on Debian Jessie derived Bunsen Linux; terminator 0.97)

My default terminator defines Ctrl+Tab as 'Focus the next terminal' and seems to switch the cursor back and forth between split terminals.

You might have to also install xdotool:

$ sudo apt-get install xdotool

Then use the X selection to save the current working directory & paste it over to the other terminal.

echo $PWD | xsel -i; xdotool key Ctrl+Tab; xdotool type 'cd $(xsel -o)'; xdotool key Return

0
audeoudh On

I have found a method that is based on a copy/paste, but that is available on keyboard.

Record two aliases in your .bashrc (or into your shell configuration file, I do not know zsh, csh…):

alias cywd='pwd | xclip -i' # CopY WD
alias pswd='cd "xclip -o"'  # PaSte WD

Then, you are able to copy the current working from a terminal by typing cywd and go to this folder by typing pswd into another terminal.

This solution is not perfect, mainly because is not easily available if a program is launched on the terminal you want to copy the WD from (for example vim or emacs -nw). However, it works. Waiting for better…