[PATCH] to get gnome-terminal to save/restore cwd.
- From: kevin lyda <kevin suberic net>
- To: gnome-devel-list gnome org
- Subject: [PATCH] to get gnome-terminal to save/restore cwd.
- Date: Sun, 13 Aug 2000 06:29:05 +0100
(apologies to the list admin - i didn't subscribe before the first
posting. could someone let me know if this list allows pgp signing and
mime posts? it would be easier to send pathces that way.)
this is a patch on the helix-code version of gnome-terminal (the gnome-core
version 1.2.1-0_helix_3 rpm). i'm sorry, i just don't have the bandwidth
for cvs. :(
here's the deal, it now accepts a --cwd flag that sets the current
working directory, it will save to a gnome-terminal session file a
config option called cwd, and on restarting the session it changes back
to that dir.
i think that if you specify --cwd on the commandline it will override
the session setting, but since i'm not really planning on using the
--cwd thingy, i don't really care. :)
i'd like to thank kenn humborg for pestering me to do this. if he
hadn't i would have done something useless from 3 to 6 this morning.
like sleep... (ok, i also cooked some food, made tea, did some dishes
and hacked on everybuddy in that time so i can't blame him for all the
time i spent up...)
i apologise if i'm sending this to the wrong places. i sent it to the
folks most recently in the changelog, the gnome-dev list and the other
person who wants this feature.
-------------------------snip-------------------------------
--- gnome-core-1.2.1.cwd-patch/gnome-terminal/gnome-terminal.c Sat May 20 05:38:07 2000
+++ gnome-core-1.2.1/gnome-terminal/gnome-terminal.c Sun Aug 13 06:06:06 2000
@@ -17,6 +17,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <sys/param.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
@@ -1733,7 +1734,7 @@
{
GnomeApp *app = GNOME_APP (gtk_widget_get_toplevel (GTK_WIDGET (data)));
- close_app (app);
+ close_app ((GtkWidget *)app);
}
/* called for "title_changed" event. Use it to change the window title */
@@ -2327,9 +2328,16 @@
int num_terms, i;
gboolean def;
gchar *file;
+ char *wd;
file = gnome_client_get_config_prefix (gnome_master_client());
+ wd = g_malloc(MAXPATHLEN + 1);
+ if (!getcwd(wd, MAXPATHLEN)) {
+ g_free(wd);
+ wd = NULL;
+ }
+
gnome_config_push_prefix (file);
num_terms = gnome_config_get_int_with_default ("dummy/num_terms",
&def);
@@ -2345,6 +2353,7 @@
int argc;
char *prefix = g_strdup_printf ("%s%d/", file, i);
int termid;
+ char *cwd;
gnome_config_push_prefix (prefix);
@@ -2385,10 +2394,18 @@
if (termid!=-1)
terminal_id = termid;
+ if (wd && (cwd = gnome_config_get_string("cwd"))) {
+ chdir(cwd);
+ g_free(cwd);
+ }
+
g_free(class);
gnome_config_pop_prefix();
new_terminal_cmd (argv, cfg, geom, terminal_id++);
+ if (wd) {
+ chdir(wd);
+ }
g_free(cfg);
g_free (geom);
@@ -2400,6 +2417,7 @@
g_strfreev (argv);
}
}
+ g_free(wd);
return TRUE;
}
@@ -2425,6 +2443,7 @@
GtkWidget *top;
char *prefix;
char *ctmp;
+ char *proccwd, *cwd;
top = gtk_widget_get_toplevel (GTK_WIDGET (list->data));
prefix = g_strdup_printf ("%s%d/", file, i);
@@ -2445,6 +2464,16 @@
*/
gdk_window_get_origin (top->window, &x, &y);
+ proccwd = g_strdup_printf("/proc/%d/cwd",
+ term->vx->vt.childpid);
+ cwd = g_malloc(MAXPATHLEN + 1);
+ memset(cwd, 0, MAXPATHLEN + 1);
+ if (readlink(proccwd, cwd, MAXPATHLEN) > 0) {
+ gnome_config_set_string("cwd", cwd);
+ }
+ g_free(cwd);
+ g_free(proccwd);
+
width =
(GTK_WIDGET (term)->allocation.width -
(GTK_WIDGET (term)->style->klass->xthickness * 2)) /
@@ -2548,8 +2577,9 @@
TERM_KEY = -14,
START_FACTORY_KEY= -15,
USE_FACTORY_KEY = -16,
- DOLASTLOG_KEY = -17,
- DONOLASTLOG_KEY = -18,
+ CWD_KEY = -17,
+ DOLASTLOG_KEY = -18,
+ DONOLASTLOG_KEY = -19,
};
static struct poptOption cb_options [] = {
@@ -2612,6 +2642,9 @@
{ "use-factory", '\0', POPT_ARG_NONE, NULL, USE_FACTORY_KEY,
N_("Try to create the terminal with the TerminalFactory"), NULL },
+ { "cwd", '\0', POPT_ARG_STRING, NULL, CWD_KEY,
+ N_("Set the cwd"), N_("CWD") },
+
{ NULL, '\0', 0, NULL, 0}
};
@@ -2728,6 +2761,9 @@
break;
case USE_FACTORY_KEY:
use_terminal_factory = TRUE;
+ break;
+ case CWD_KEY:
+ chdir(arg);
break;
default:
break;
-------------------------snip-------------------------------
kevin
--
kevin@suberic.net moo
fork()'ed on 37058400 moo
meatspace place: home http://suberic.net/~kevin/ yank? www.votenader.com
>>protect privacy: www.gnupg.org or www.pgp.com. encrypted mail preferred<<
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]