Index: src/terminal.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.c,v
retrieving revision 1.57
diff -U5 -r1.57 terminal.c
--- src/terminal.c	2 Apr 2003 19:17:58 -0000	1.57
+++ src/terminal.c	21 Jun 2003 02:28:11 -0000
@@ -95,10 +95,11 @@
   int screen_number;
   GList *initial_windows;
   gboolean default_window_menubar_forced;
   gboolean default_window_menubar_state;
   char *default_geometry;
+  char *default_working_dir;
   char **post_execute_args;
 } OptionParsingResults;
 
 static void         sync_profile_list            (gboolean use_this_list,
                                                   GSList  *this_list);
@@ -158,10 +159,11 @@
   OPTION_GEOMETRY,
   OPTION_DISABLE_FACTORY,
   OPTION_STARTUP_ID,
   OPTION_TITLE,
   OPTION_WORKING_DIRECTORY,
+  OPTION_DEFAULT_WORKING_DIRECTORY,
   OPTION_ZOOM,
   OPTION_ACTIVE,
   OPTION_COMPAT,
   OPTION_LAST
 };  
@@ -318,11 +320,19 @@
     NULL,
     OPTION_WORKING_DIRECTORY,
     N_("Set the terminal's working directory"),
     N_("DIRNAME")
   },
-
+  {
+    "default-working-directory",
+    '\0',
+    POPT_ARG_STRING,
+    NULL,
+    OPTION_DEFAULT_WORKING_DIRECTORY,
+    N_("Set the default terminal's working directory. Used internally"),
+    N_("DIRNAME")
+  },
   {
     "zoom",
     '\0',
     POPT_ARG_STRING,
     NULL,
@@ -1017,10 +1027,28 @@
 
         it->working_dir = g_strdup (arg);
       }
       break;
 
+    case OPTION_DEFAULT_WORKING_DIRECTORY:
+      {
+        if (arg == NULL)
+          {
+            g_printerr (_("Option --default-working-directory requires an argument giving the directory\n"));
+            exit (1);
+          }
+
+        if (results->default_working_dir)
+          {
+            g_printerr (_("Two default working directories given for\n"));
+            exit (1);
+          }
+
+        results->default_working_dir = g_strdup (arg);
+      }
+      break;
+
     case OPTION_ZOOM:
       {
         InitialTab *it;            
         double val;
         char *end;
@@ -1118,10 +1146,11 @@
 {
   g_list_foreach (results->initial_windows, (GFunc) initial_window_free, NULL);
   g_list_free (results->initial_windows);
 
   g_free (results->default_geometry);
+  g_free (results->default_working_dir);
 
   if (results->post_execute_args)
     g_strfreev (results->post_execute_args);
 
   g_free (results->display_name);
@@ -1149,10 +1178,11 @@
   int i;
   OptionParsingResults *results;
 
   results = g_new0 (OptionParsingResults, 1);
   results->screen_number = -1;
+  results->default_working_dir = NULL;
   
   /* pre-scan for -x and --execute options (code from old gnome-terminal) */
   results->post_execute_args = NULL;
   i = 1;
   while (i < *argc)
@@ -1280,10 +1310,36 @@
           ++i;
         }
     }
 }
 
+static void
+option_parsing_results_apply_directory_defaults (OptionParsingResults *results)
+{
+  GList *w, *t;
+
+  if (results->default_working_dir == NULL)
+    return;
+
+  for (w = results->initial_windows; w; w = w ->next)
+    {
+      InitialWindow *window;
+
+      window = (InitialWindow*) w->data;
+      
+      for (t = window->tabs; t ; t = t->next)
+        {
+          InitialTab *tab;
+
+          tab = (InitialTab*) t->data;
+
+          if (tab->working_dir == NULL)
+            tab->working_dir = g_strdup (results->default_working_dir);
+        }
+    }
+}
+
 static int
 new_terminal_with_options (OptionParsingResults *results)
 {
   GList *tmp;
   
@@ -1449,12 +1505,12 @@
   textdomain (GETTEXT_PACKAGE);
 
   g_set_application_name (_("Terminal"));
   
   argc_copy = argc;
-  /* we leave empty slots, for --startup-id and --display */
-  argv_copy = g_new0 (char *, argc_copy + 5);
+  /* we leave empty slots, for --startup-id, --display and --default-working-directory */
+  argv_copy = g_new0 (char *, argc_copy + 7);
   for (i = 0; i < argc_copy; i++)
     argv_copy [i] = g_strdup (argv [i]);
   argv_copy [i] = NULL;
 
   results = option_parsing_results_init (&argc, argv);
@@ -1500,13 +1556,16 @@
     {
       g_printerr (_("Invalid argument: \"%s\"\n"),
                   *args);
       return 1;
     }
+
+  option_parsing_results_apply_directory_defaults (results);
   
   if (!terminal_factory_disabled)
     {
+      char *cwd;
       
       if (results->startup_id != NULL)
         {
           /* we allocated argv_copy with extra space so we could do this */
           insert_args (&argc_copy, argv_copy,
@@ -1515,10 +1574,16 @@
 
       /* Forward our display to the child */
       insert_args (&argc_copy, argv_copy,
                    "--display", results->display_name);
       
+      /* Forward out working directory */
+      cwd = g_get_current_dir ();
+      insert_args (&argc_copy, argv_copy,
+                   "--default-working-directory", cwd);
+      g_free (cwd);
+
       if (terminal_invoke_factory (argc_copy, argv_copy))
         return 0;
     }
 
   g_strfreev (argv_copy);
@@ -3226,11 +3291,11 @@
   while (tmp != NULL)
     {
       GList *tabs;
       GList *tmp2;
       TerminalWindow *window = tmp->data;
-      TerminalWindow *active_screen;
+      TerminalScreen *active_screen;
 
       active_screen = terminal_window_get_active (window);
       
       tabs = terminal_window_list_screens (window);
 
@@ -3553,10 +3618,12 @@
 	       poptBadOption (ctx, 0),
 	       poptStrerror (nextopt));
 
   poptFreeContext (ctx);
   options[0].descrip = store;
+
+  option_parsing_results_apply_directory_defaults (results);
 
   new_terminal_with_options (results);
 
   option_parsing_results_free (results);
 }
Index: src/terminal-screen.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal-screen.c,v
retrieving revision 1.74
diff -U5 -r1.74 terminal-screen.c
--- src/terminal-screen.c	24 Apr 2003 14:43:28 -0000	1.74
+++ src/terminal-screen.c	21 Jun 2003 02:28:30 -0000
@@ -156,15 +156,13 @@
 }
 
 static void
 terminal_screen_init (TerminalScreen *screen)
 {
-  char buf[PATH_MAX+1];
-  
   screen->priv = g_new0 (TerminalScreenPrivate, 1);
 
-  screen->priv->working_dir = g_strdup (getcwd (buf, sizeof (buf)));
+  screen->priv->working_dir = g_get_current_dir ();
   if (screen->priv->working_dir == NULL) /* shouldn't ever happen */
     screen->priv->working_dir = g_strdup (g_get_home_dir ());
   screen->priv->child_pid = -1;
 
   screen->priv->recheck_working_dir_idle = 0;
