Nautilus Terminal – Open Folder in Terminal When Using tmux

fedoragnomeshellterminaltmux

I'm using fedora 25 gnome edition, zsh shell. I can right click, open folder in terminal. I configured gnome terminal to start tmux when it gets opened.

Now if I open folder in terminal, the terminal would open the default user directory instead of the actual directory I'm in. How to fix it?

enter image description here

I need to either pass additional parameters to tmux in gnome-terminal, or to Nautilus.

If that works with another file manager please let me know, and I'll consider the possibility of switching, but if it can be done using Nautilus, it's better.

Best Answer

I haven't used Linux as my main driver in a while, but there used to be a program nautilus-open-terminal for doing this, not sure if it's supported on Fedora though. Also, though I don't know if it's possible to install it on non-Ubuntu/Debian systems Canonical's Unity DE has this functionality built in, you could probably replicate the method used there in Gnome.

EDIT: In light of your comment, you might add the lines to your .profile to always open tmux in the current working directory of gnome-terminal as a disowned process (i.e. tmux ./; disown -r && killall gnome-terminal) so that when you right click and open terminal in directory it opens a gnome-terminal, and immediately opens an independant tmux windows, passing the working directory recieved by nautilus as an argument.

UPDATE: Okay, I have found two methods. Now each of these have their own issues, but hopefully one of them will work well enough for you. These methods were tested on a Debian 8.7 installation using Bash as the shell and the program nautilus-open-terminal to launch a terminal window in the current Nautilus/Nemo directory.

Method 1.) Simply add tmux to the very end of your .bashrc file (or in your case .zshrc.). Now any terminal window you open will immediately open tmux as a process in the working directory.

The pro to this method is it is simple and only opens one window.

The major con to this method is it will always run as a nested process in the current shell, so if that's a problem you may want to use the other method instead.

Method 2.) Add the line gnome-terminal -e tmux ./ (no quotes around the process name this time) to your .bashrc or .zshrc file. This will open a new terminal window that contains tmux as the main process.

The pros for this method are that the tmux window will be a detached process, and will still open with the current working directory set to the Nautilus/Nemo window's directory.

The con is that while it opens a tmux dedicated window, exit cannot be added to the .bashrc file or it will kill the tmux window as well. With that said the gnome-terminal that is used to spawn the tmux window can still be closed manually by clicking the x on the window, or running exit directly in the gnome-terminal once tmux has opened.

While the second method is less convenient in that you have to manually close the excess terminal window; it will open a dedicated tmux window in the current directory when the Open In Terminal context menu option is clicked.

Related Question