Thanks for your patch.
I, however, found that the patch is not portable.
Since getting cwd from pid is OS-specific stuff, I'd suggest
encapsulate this in a function, and do some conditional compilation
for different OSes inside.

For example:

char* get_cwd_for_pid(pid_t pid)
{
    char* cwd = NULL;
#ifdef __linux__
    /* read cwd from /proc/... */
#elif defined(some_other_OS)
   /* some OS-specific code here */
#elif defined(yet_another_OS)
   /* some OS-specific code here */
#endif
    return cwd;
}

You can find how to do this in the source code of gnome-terminal,
roxterm, or sakura (patched by me previously).

On Mon, Nov 16, 2009 at 10:09 PM, CHENG Renquan <[email protected]> wrote:
> Here add a pid_t to record 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 2145)
> +++ src/lxterminal.c    (working copy)
> @@ -357,7 +357,19 @@ static void terminal_newtab(GtkWidget *w
>  {
>        LXTerminal *terminal = (LXTerminal *)data;
>
> -       Term *term = terminal_new(terminal, _("LXTerminal"), 
> g_get_current_dir(), NULL, NULL);
> +       const gchar *pwd;
> +       char cwd_file[64], buf[PATH_MAX+1];
> +       int len;
> +
> +       Term *curr_term = g_ptr_array_index(terminal->terms, 
> gtk_notebook_get_current_page(GTK_NOTEBOOK(terminal->notebook)));
> +       g_snprintf(cwd_file, sizeof cwd_file, "/proc/%d/cwd", curr_term->pid);
> +       len = readlink(cwd_file, buf, (sizeof buf) - 1);
> +       if (len > 0 && buf[0] == '/')
> +               pwd = g_strndup(buf, len);
> +       else
> +               pwd = 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);
> @@ -675,10 +687,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 2145)
> +++ src/lxterminal.h    (working copy)
> @@ -62,6 +62,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
>
>

------------------------------------------------------------------------------
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

Reply via email to