diff options
Diffstat (limited to '')
-rw-r--r-- | terminal.vala | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/terminal.vala b/terminal.vala index 4a2e676..dfe8130 100644 --- a/terminal.vala +++ b/terminal.vala @@ -28,6 +28,7 @@ class Terminal : Gtk.Overlay { [GtkChild] unowned Gtk.Menu hyperlink_context_menu; [GtkChild] unowned Gtk.MenuItem copy_item_text; [GtkChild] unowned Gtk.MenuItem copy_item_html; + [GtkChild] unowned Gtk.MenuItem open_terminal_item; [GtkChild] unowned Gtk.MenuItem open_directory_item; [GtkChild] unowned Gtk.Revealer search_revealer; [GtkChild] unowned Gtk.ScrolledWindow scrolled_window; @@ -329,6 +330,48 @@ class Terminal : Gtk.Overlay { adjust_font_scale(vte.get_font_scale() / FONT_SCALE_FACTOR); } + string? get_local_directory_path() { + var uri = vte.get_current_directory_uri(); + if (uri == null) + return null; + + string uri_hostname; + string path = null; + try { + path = Filename.from_uri(uri, out uri_hostname); + } catch (Error e) { + warning(e.message); + return null; + } + + char hostname[256]; // SUSv2 says 255 is max length, +1 for terminator + Posix.gethostname(hostname); + + // If the path URI points to another computer, return null + if (uri_hostname != (string)hostname) + return null; + + return path; + } + + [GtkCallback] + void open_terminal() { + var cwd = get_local_directory_path(); + if (cwd == null) + return; + + Pid child; + + try { + Process.spawn_async(cwd, {PROGRAM_NAME}, Environ.get(), SpawnFlags.SEARCH_PATH, null, out child); + } catch (Error e) { + warning(e.message); + infobar_show(e.message, Gtk.MessageType.ERROR); + } + + Process.close_pid(child); + } + [GtkCallback] void open_directory() { uri_open(vte.get_current_directory_uri()); @@ -358,6 +401,7 @@ class Terminal : Gtk.Overlay { } else { copy_item_text.set_sensitive(vte.get_has_selection()); copy_item_html.set_sensitive(vte.get_has_selection()); + open_terminal_item.set_sensitive(get_local_directory_path() != null); open_directory_item.set_sensitive(vte.get_current_directory_uri() != null); standard_context_menu.popup_at_pointer(event); } @@ -408,6 +452,11 @@ class Terminal : Gtk.Overlay { return true; } + if (match_key(event, CONTROL_MASK | SHIFT_MASK, Gdk.Key.T)) { + open_terminal(); + return true; + } + if (match_key(event, CONTROL_MASK | SHIFT_MASK, Gdk.Key.O)) { open_directory(); return true; |