Xmonad open terminal in same directory

6

Is it possible to have Xmonad open a new terminal in the same directory as the active terminal (if the active window is a terminal or a program like vim running in one)? As it is, all my terminals open in $HOME. It does not matter to me if this happens if I open a new terminal in a different workspace. This would be a huge productivity gain because otherwise I would have to cd all the way up to the directory I am working in.

If this is not possible to do directly using Xmonad, I am interested in alternative solutions to this. The only thing I can think of is to overload PROMPT_COMMAND to write out the current directory to a file and have my .bashrc look at this file to determine where to go. But this is a very imperfect solution that would work for many cases, but will leave a good majority incorrect.

Thomas Eding

Posted 2013-05-04T00:13:14.250

Reputation: 233

Depends which terminal you are using? – Robert Massaioli – 2013-05-04T10:11:46.993

Urxvt is a little tricky but this feature is built straight into gnome terminal. – Robert Massaioli – 2013-05-04T12:21:18.063

Answers

2

I haven't messed with the defaults much and ctrl+shift+n does it for me.

chevett

Posted 2013-05-04T00:13:14.250

Reputation: 308

I never though of using my terminal's controls to do so (as opposed to X-Monad's controls). This works for me. – Thomas Eding – 2014-10-03T16:25:28.093

2

That doesn't really answers your question, but I have an alternative that can save your time and solve your problem: autojump

This is a software that saves your habits when navigating between folders in the terminal. Every time you cd in a folder, it increase the associated likelihood. For example on my system it has now something like:

343368.3820292514   /home/fb
66.1004508305352    /home/fb/documents
65.2439790325514    /home/fb/workspace/MyProject
55.78935025659235   /very/long/path/boring/to/join/Folder
51.78935025659235   /home/fb/master-thesis
49.150383518340945  /usr/share/opencv
43.1282216187962    /home/fb/.dotvim
...

Then afterward, when you want to go in a folder, you can give only a part of the name and it will go to the most probable folder that corresponds. Usually the command j is associated with autojump. For instance in your case the usage will be as follow.

  1. Open a terminal
  2. (First time only) Go with cd to the folder /very/long/path/boring/to/join/Folder
  3. Do some work
  4. Later, when you need another terminal, open a new one
  5. Entering j fol<ENTER> will bring your directly to /home/fb/very/long/path/boring/to/join/Folder

Of course this only work if the folder you want to join is a folder where you often go.

StreakyCobra

Posted 2013-05-04T00:13:14.250

Reputation: 411

That sounds like a cool utility. I'd like to see if there is a utility that pushes a directory that you can pop back later... or if not, create one myself: pwd > ~/poo -> cd \cat ~/poo`` – Thomas Eding – 2013-05-07T17:56:02.453

2Just ask: pushd and popd ;-) – StreakyCobra – 2013-05-07T19:23:47.623

Also to switch quickly between two folders: cd -. A common workflow is cd my/directory/one, then work on it until another folder is needed: cd /etc/httpd/. Then to go back to previous one: cd -, what mark current directory as previous, making another cd - to switch back to it. – StreakyCobra – 2013-05-07T19:28:17.523

1

I set the my directory on a per workspace basis. Then all the terminals I open in that workspace open in that directory. This is done using the workspacedir extension: http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Layout-WorkspaceDir.html

Basically I bound a key to changeDir. When I press that key a prompt pops up that allows you to set the directory (with working tab completion).

user236456

Posted 2013-05-04T00:13:14.250

Reputation: 11

0

If you can get PID of shell running in current window you can than do something like executing urxvt -cd $(readlink /proc/$PID/cwd) (or something similar for different terminal). Don't know how to get pid of current window in XMonad though.

Vladimir Still

Posted 2013-05-04T00:13:14.250

Reputation: 101

-1

You could use the X window id from withWindowSet and query xprop for PID, from which to extract CWD.

I've been using this approach for some time now (with success), on a Linux machine. It should work on most Unix-like OSes granted you tweak your logic for extracting CWD from PID.

mewa

Posted 2013-05-04T00:13:14.250

Reputation: 99