Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Depends which terminal you are using? –  Robert Massaioli May 4 '13 at 10:11
    
Urxvt is a little tricky but this feature is built straight into gnome terminal. –  Robert Massaioli May 4 '13 at 12:21

3 Answers 3

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.

share|improve this answer
    
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 May 7 '13 at 17:56
2  
Just ask: pushd and popd ;-) –  StreakyCobra May 7 '13 at 19:23
    
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 May 7 '13 at 19:28

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).

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.