Hello,

I made a small patch to add the following behaviour to the tabbed
extension:

* When a new tab is opened, its working directory is the same as the
  currently opened tab.

I don't have any claims that this is a good patch.
I'm just posting it here, so that other people that want this behaviour
can have it as I didn't find it when I needed it.
The patch is linux specific (AFAIK) because it uses the /proc/pid/cwd
symlink.

If anyone know a portable way to do the same thing,
I'll be happy to know it.

All the best,

Emil Stanchev.
diff -rup ../../../rxvt-original/rxvt-unicode-9.07/src/perl/tabbed ./src/perl/tabbed
--- ../../../rxvt-original/rxvt-unicode-9.07/src/perl/tabbed	2008-06-15 17:52:47.000000000 +0300
+++ ./src/perl/tabbed	2010-05-24 12:20:01.000000000 +0300
@@ -65,9 +65,15 @@ sub new_tab {
 
    push @urxvt::TERM_EXT, urxvt::ext::tabbed::tab::;
 
+   my $chd = "";
+   if ($self->{cur}!=undef) {
+       $chd = $self->{cur}->cwd;
+   }
+
    my $term = new urxvt::term
       $self->env, $urxvt::RXVTNAME,
       -embed => $self->parent,
+      -chdir => $chd,
       @argv,
    ;
 }
 
diff -rup ../../../rxvt-original/rxvt-unicode-9.07/src/rxvt.h ./src/rxvt.h
--- ../../../rxvt-original/rxvt-unicode-9.07/src/rxvt.h	2009-05-30 11:48:11.000000000 +0300
+++ ./src/rxvt.h	2010-05-24 12:20:01.000000000 +0300
@@ -1131,6 +1131,22 @@ struct rxvt_term : zero_initialized, rxv
     XSelectInput (dpy, vt, vt_emask | vt_emask_perl | vt_emask_xim | vt_emask_mouse);
   }
 
+  char * cwd(char * cwd_buffer) const
+  {
+    char proc_path[PATH_MAX];
+    snprintf (proc_path, PATH_MAX, "/proc/%d/cwd", cmd_pid);
+
+    ssize_t len;
+    if((len=readlink (proc_path, cwd_buffer, PATH_MAX)) != -1) {
+      cwd_buffer[len]='\0';
+      return cwd_buffer;
+    }
+    else {
+      perror (proc_path);
+      return NULL;
+    }
+  }
+
 #if ENABLE_TRANSPARENCY || ENABLE_PERL
   void rootwin_cb (XEvent &xev);
   xevent_watcher rootwin_ev;

diff -rup ../../../rxvt-original/rxvt-unicode-9.07/src/rxvtperl.xs ./src/rxvtperl.xs
--- ../../../rxvt-original/rxvt-unicode-9.07/src/rxvtperl.xs	2009-12-26 11:39:42.000000000 +0200
+++ ./src/rxvtperl.xs	2010-05-24 12:20:01.000000000 +0300
@@ -1158,6 +1158,16 @@ rxvt_term::pty_ev_events (int events = e
 	OUTPUT:
         RETVAL
 
+SV *
+rxvt_term::cwd ()
+	CODE:
+	char * tmp_buffer = (char*)rxvt_malloc(PATH_MAX);
+	THIS->cwd (tmp_buffer);
+	RETVAL = sv_2mortal (newSVpv (tmp_buffer, 0));
+	free (tmp_buffer);
+	OUTPUT:
+	RETVAL
+
 int
 rxvt_term::pty_fd ()
 	CODE:
_______________________________________________
rxvt-unicode mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/rxvt-unicode

Reply via email to