On Tue, 4 Dec 2007 16:16:34 -0600, "Jeff Pohlmeyer" yetanothergeek@gmail.com wrote:
I just noticed a little quirk with the "Follow path of current file" option for VTE.
Consider this...
- Open a file in your $HOME directory.
- Open another file from some other directory.
- In vte, type "echo" followed by a space, but don't press return.
- Click the on the tab of the first file you opened.
The resulting command is "echo cd /home/username"
Now imagine if you had typed "rm -rf " instead of "echo "
It's getting really funny if the path of the file is "/" ;-).
Maybe it would be safer to only issue the cd command if there is no other text on the command line. I skimmed through the vte headers and the only thing I see that might work is to call vte_terminal_get_cursor_position() first, and check to make sure the column value is zero.
Yes but checking the column to zero doesn't help because it isn't at all. But we could keep the cursor position after a sent command(e.g. cd ...) and then compare it to the current cursor position just before sending any command to the VTE. This works in theory, but while testing it I noticed another problem: we send "cd ..." to the VTE using vte_terminal_feed_child() and after that we retrieve the current cursor position. But we get the "old" position because vte_terminal_feed_child() works asynchronously and so the code to retrieve the cursor position is executed before the cd command was actually executed. And I don't see a way to detect when the executed command within the VTE has finished.
The only thing I could imagine is to delay the retrieval of the new cursor position so that we can assume the command has finished. But this is somewhat ugly and may cause other errors. Delaying the cursor position retrieval could work for the "cd" command when switching between tabs but will probably fail when using the Run command in the VTE. Attached is a patch to check for changed cursor positions after a delay of 0.5 seconds. It seems to work for the "cd" command but it breaks the auto path changing feature as well as the ability to run commands in the VTE if one runs an open file in the VTE and the duration of the command is longer than the delay (0.5 seconds). All should work again after the VTE is restarted.
I'm not sure at all whether the way I did it in the patch is good, whether we should it in this way or whether there is any better way(I hope so).
Thanks for reporting, good catch.
Regards, Enrico