New window working directory as 1st parameter

Bug #1646034 reported by Massimo
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Terminator
Fix Released
Undecided
Stephen Boddy

Bug Description

Since update to 1.0 the command line parameters seem to have changed incompatible regarding the working directory.

Before I was able to use "Open terminal here" in Xfce's Thunar. Now that opens a terminator always in the home directory.
Using the --working-directory=DIR works fine, but I guess that the old behaviour was passing the working dir as first parameter as Thunar doesn't know about special command line interfaces of different emulations. I guess other file manager are doing this equally.

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

Just FYI:

In gnome-terminal and xfce4-terminal it's --working-directory=DIR, in konsole it's --workdir=DIR, in urxvt it's -cd DIR. Neither of these four recognizes the directory name itself on its own.

Revision history for this message
Massimo (massimo-b) wrote :

Interesting, thanks. Do you have an idea what could have broken the Thunar behaviour?

Revision history for this message
Massimo (massimo-b) wrote :

The "Preferred application" for the terminal in Xfce affects the "Open terminal here" and the "Terminal Emulator" button in the applications menu.

Switching back to xfce4-terminal everything works fine.
For terminator I used to have
'terminator "%s"'

This was working before. Not with DBus enabled by default I see 2 differences. "Terminal Emulator" just jumps to the virtual screen of my first opened terminator without opening another one.
"Open terminal here" also jumps to the other virtual screen but also opens a terminator at $HOME on the current screen.

Using
'terminator'
as command for the terminal I get the "Terminal Emulator" buttons working without jumping but opening a new window. But the "Open terminal here" still does not change to that directory.

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

I've no clue about Thunar or any similar file manager and its way of opening a terminal.

Can you specify 'terminator --working-directory="%s"' to make it work?

Revision history for this message
Massimo (massimo-b) wrote :

No, this didn't work either.

Revision history for this message
Massimo (massimo-b) wrote :

Calling terminator --working-directory="~/Documents" from a terminal does open a terminal at $HOME, the bug is there, here you go...

Revision history for this message
Massimo (massimo-b) wrote :

Sorry, that works:
terminator --working-directory=/home/mb/Documents

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

My expectation is:

"~" as a special character is a convention _for the shell only_ and _only at the beginning of a string_.

The shell where you type "terminator --wor..." expands it only if it's preceded by a space and is not within quites, that is,

  terminator --working-directory="~/Documents"
  terminator --working-directory=~/Documents
  terminator --working-directory "~/Documents"

are expected to leave it as a literal "~", however, replacing "=" by a space and omitting the quotes:

  terminator --working-direcotry ~/Documents

is expected to work because the shell from which you invoke terminator interprets and replaces it with /home/mb/Documents for you.

My reality is:

All of the above do work on my system. I have no clue why :D :D :D

In "ps ax" the first three show a literal "~" whereas the last variant shows the expanded value. Hence either terminator itself, or the shell launched by terminator interprets the leading "~" once again. They should not.

Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

Update: it must terminator doing this hack of interpreting "~", since repeating the same steps with gnome-terminal gives the results I expected.

Note: You have terminator 1.0, I have terminator 1.90. This could be the reason for the difference. If this is the case, the gtk3 branch has introduced a new "misfeature" of expanding the "~" character, which it in my opinion should not do.

Revision history for this message
Stephen Boddy (stephen-j-boddy) wrote :

For the tilde expansion, the code has not changed between gtk2 and gtk3. The line in question is in optionparse.py:
os.chdir(os.path.expanduser(options.working_directory))

And this line is from way, way back in the beginning of 2009, (though originally in the main script, moving to optionparse.py in 2010.) libc also provides for tilde expansion:
https://www.gnu.org/software/libc/manual/html_node/Tilde-Expansion.html#Tilde-Expansion
So it's not *exclusive* to bash, and I don't believe we are doing anything wrong by expanding it ourselves. We just provide a little extra utility over others ;-)

As to the original complaint. The optionparse.py file has not changed a single line (bar the 1st shebang line to spec python2) between the gtk2 and gtk3 versions. At no stage (recently at least) has Terminator accepted non-option arguments. So passing a path on its own will not work, and should never have worked. You will get the message:
terminator: error: Additional unexpected arguments found: ['/usr']

For me Thunar works as expected with two minor wrinkles.
1. When DBus is active the folder requested is ignored for secondary windows (the first is OK), and the new secondary windows inherit the directory of the Terminator processes current working directory. We need to fix it so that options passed with DBus active do not get ignored.
2. When DBus is active the first terminator window opens in front and gets focus. Secondary windows (i.e. ones using DBus to launch) open behind Thunar, and do not get focus.

Nautilus with the addon for opening a folder in a terminal on the other hand, completely ignores my preferred terminal, and hard launches gnome-terminal!

Revision history for this message
Stephen Boddy (stephen-j-boddy) wrote :

In short, as it may not be clear from the previous essay :-) the issue with secondary windows is because we did activate DBus by default recently. It is much gentler on resources, but it does cause this issue for you. The simplest fix for the interim is to simply deactivate it. Your resource usage goes up a little, and you cannot use the remotinator tool. That's pretty much the extent of the impact.

Revision history for this message
Stephen Boddy (stephen-j-boddy) wrote :

Gah! I figured it out. I thought the DBus was broken, but it sort of isn't. If you specify a full path (no ~) for the second window it works with DBus. If you are using a tilde, then we try to pass that string directly to the vte widget as the cwd when spawning the command (i.e. bash). vte does not like the ~ so defaults to the process cwd. So the issue here is that we (terminator) are not expanding the tilde consistently. I've modified the code to apply the expansion to the option, not just setting the processes cwd.

Committed revision 1662. (GTK3)
Committed revision 1768. (GTK2)

Changed in terminator:
status: New → Fix Committed
Revision history for this message
Egmont Koblinger (egmont-gmail) wrote :

Nice catch!

I was really wondering why Massimo's observations were so different from mine. It would have never occurred to me that there's a difference between the first (direct) and subsequent (dbus) invocations.

Revision history for this message
Massimo (massimo-b) wrote :

Anyhow that did not solve the issue.
"Open terminal here" does
1. Open a terminator with $HOME as directory
2. Switch to the virtual desktop where the main terminator is located
Turning back to the previous virtual desktop shows, there was a terminator opened here.

Expected would be:
1. Open a terminator with the passed directory as location.

Revision history for this message
Stephen Boddy (stephen-j-boddy) wrote :

Well at the moment this seems to work for me, but I'll mark this as "In Progress" for now until I find a moment to look into it.

Changed in terminator:
status: Fix Committed → In Progress
assignee: nobody → Stephen Boddy (stephen-j-boddy)
Revision history for this message
Stephen Boddy (stephen-j-boddy) wrote :

OK, I figured out what is going on. The Thunar command is setting "--working-dir" to the folder you click on. But this is just where the python command is run from, it is *not* passed to Terminator as the --working-dir command line option. You almost certainly have the DBus active in Terminator preferences. So this causes the second python instance to detect the first, and it requests a new window and exits. The first instance opens a window, but crucially it has the same working dir as the first. This is because that --working-dir was not passed to the terminator command line. So the second window takes the cwd of the first instance.

If you turn DBus off then the second instance does not find the DBus session, so must run itself. It still doesn't get the --working-dir parameter, but because Thunar has set that as the application cwd, then the second instance has the correct folder.

I'm just trying to figure out if we can detect the cwd and pass it over the DBus which would fix this when DBus was active, but without breaking it for other use cases. i.e. If I use a keyboard shortcut, or an application icon, will it default to the user home dir, or will it default to the system root. (I'm unsure because there's a piece of code to detect root as cwd and changes it to ~). I've committed a small change that does a limited check, only when calling the DBus, and if working_directory is not set, it sets it to the current working directory. This is provisional, as there might be people who want/need it to pick the cwd from the first instance.

Committed revision 1723.

Changed in terminator:
status: In Progress → Fix Committed
Changed in terminator:
status: Fix Committed → Fix Released
Revision history for this message
Massimo (massimo-b) wrote :

Hi, where are these things fixed and how to sync that?
I'm watching http://bazaar.launchpad.net/~gnome-terminator/terminator/gtk3/.

I'm more into hg and git, tried
bzr update && bzr log -l 3
last timestamp from 2016-11-30.

Revision history for this message
Stephen Boddy (stephen-j-boddy) wrote :

"Committed revision 1723."

From an earlier comment. I usually try to put the commit revision number in, unless it is one of those ones that magically fix themselves, in which case I at least try to explain.

http://bazaar.launchpad.net/~gnome-terminator/terminator/gtk3/revision/1723

OK? Or did I misunderstand what you are asking for?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.