Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Open in Terminal" from Files when Terminal instance already running #776

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,18 @@ public class Terminal.Application : Gtk.Application {

protected override int handle_local_options (VariantDict options) {
unowned string working_directory;
string sanitized_path;
unowned string[] args;

if (options.lookup ("working-directory", "^&ay", out working_directory)) {
if (working_directory != "\0") {
Environment.set_current_dir (
Utils.sanitize_path (working_directory, Environment.get_current_dir (), false)
); // will be sent via platform-data
sanitized_path = Utils.sanitize_path (working_directory, Environment.get_current_dir (), false);
Environment.set_current_dir (sanitized_path); // will be sent via platform-data
// We need to keep the -w option so that it works from a different app when Terminal is already running
// In this case the Environment of the other app is not passed in platform-data
options.insert ("working-directory","^&ay", sanitized_path);
options.insert ("new-tab", "b", true);
}

options.remove ("working-directory");
}

if (options.lookup (OPTION_REMAINING, "^a&ay", out args)) {
Expand Down Expand Up @@ -236,8 +237,18 @@ public class Terminal.Application : Gtk.Application {
window = new MainWindow (this, is_first_window);
}

unowned string? option_working_directory;
string working_directory;
options.lookup ("working-directory", "^&ay", out option_working_directory);

// If a specified working directory is not requested, use the current working directory from the commandline
unowned var working_directory = command_line.get_cwd ();
if (option_working_directory == null) {
working_directory = command_line.get_cwd (); // In the Environment of the primary Terminal app instance
} else {
// Need to copy the unowned string to prevent corruption of the parameter passed to MainWindow
working_directory = option_working_directory.dup ();
}

unowned string[] commands;
unowned string command;
bool new_tab, minimized;
Expand Down
3 changes: 2 additions & 1 deletion src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ namespace Terminal.Utils {
parts_sep[index] = construct_parent_path (shell_location);
}

var result = escape_uri (scheme + string.joinv (Path.DIR_SEPARATOR_S, parts_sep).replace ("//", "/"));
// Terminal does not need an escaped uri
var result = scheme + string.joinv (Path.DIR_SEPARATOR_S, parts_sep).replace ("//", "/");
return result;
}

Expand Down
Loading