Here add a pid_t to save the result of vte_terminal_fork_command,
when new tab creation, read the current shell's cwd first, then
keep the new tab on consistent curdir with current tab.
Signed-off-by: CHENG Renquan <[email protected]>
Index: src/lxterminal.c
===================================================================
--- src/lxterminal.c (revision 2146)
+++ src/lxterminal.c (working copy)
@@ -353,11 +353,45 @@ static void term_set_swicth_accel(Term *
}
}
+/* some of the logic here is borrowed from gnome-terminal,
+ * currently only support Linux and Solaris >= 10, and if you
+ * want to add more other os support, here is the place.
+ */
+static char *get_cwd_for_pid(pid_t pid)
+{
+ static const char patterns[][18] = {
+ "/proc/%d/cwd", /* Linux */
+ "/proc/%d/path/cwd", /* Solaris >= 10 */
+ };
+ guint i;
+
+ /* Try to get the working directory using various OS-specific
mechanisms */
+ for (i = 0; i < G_N_ELEMENTS (patterns); ++i)
+ {
+ char cwd_file[64];
+ char buf[PATH_MAX + 1];
+ int len;
+
+ g_snprintf (cwd_file, sizeof (cwd_file), patterns[i], pid);
+ len = readlink (cwd_file, buf, sizeof (buf) - 1);
+
+ if (len > 0 && buf[0] == '/')
+ return g_strndup (buf, len);
+ }
+
+ return NULL;
+}
+
static void terminal_newtab(GtkWidget *widget, gpointer data)
{
LXTerminal *terminal = (LXTerminal *)data;
- Term *term = terminal_new(terminal, _("LXTerminal"),
g_get_current_dir(), NULL, NULL);
+ Term *curr_term = g_ptr_array_index(terminal->terms,
gtk_notebook_get_current_page(GTK_NOTEBOOK(terminal->notebook)));
+
+ /* use the g_get_current_dir as fallback */
+ const gchar *pwd = get_cwd_for_pid(curr_term->pid) ?:
g_get_current_dir();
+
+ Term *term = terminal_new(terminal, _("LXTerminal"), pwd, NULL, NULL);
/* add page to notebook */
gtk_notebook_append_page(GTK_NOTEBOOK(terminal->notebook), term->box,
term->label->main);
@@ -725,10 +759,10 @@ static Term *terminal_new(LXTerminal *te
if (exec) {
gchar **command;
g_shell_parse_argv(exec, NULL, &command, NULL);
- vte_terminal_fork_command(VTE_TERMINAL(term->vte), (const char
*)*(command), command, env, pwd, FALSE, TRUE, TRUE);
+ term->pid = vte_terminal_fork_command(VTE_TERMINAL(term->vte),
(const char *)*(command), command, env, pwd, FALSE, TRUE, TRUE);
g_strfreev(command);
} else {
- vte_terminal_fork_command(VTE_TERMINAL(term->vte), NULL, NULL,
env, pwd, FALSE, TRUE, TRUE);
+ term->pid = vte_terminal_fork_command(VTE_TERMINAL(term->vte),
NULL, NULL, env, pwd, FALSE, TRUE, TRUE);
}
/* signal handler */
Index: src/lxterminal.h
===================================================================
--- src/lxterminal.h (revision 2146)
+++ src/lxterminal.h (working copy)
@@ -66,6 +66,7 @@ typedef struct _term {
GtkWidget *vte;
GtkWidget *scrollbar;
GtkWidget *box;
+ pid_t pid;
} Term;
LXTerminal *lxterminal_init(LXTermWindow *lxtermwin, gint argc, gchar **argv,
Setting *setting);
---
CHENG Renquan (ç¨ä»»å
¨), from SMU (Singapore Management University)
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Lxde-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/lxde-list