<<< Date Index >>>     <<< Thread Index >>>

[patch] chdir.1 (Re: saving attachment to directory)



Re: To Mutt Users in <20040415191135.GH2670@xxxxxxxx>
> Not exactly, he wants a (global) default directory, which is a little
> different from "save all tagged attachments to the same directory". But
> a "cd" command in Mutt has also been requested some time ago.

Here comes patch-1.5.6.cb.chdir.1...

Christoph
-- 
cb@xxxxxxxx | http://www.df7cb.de/
diff -ur ../MUTT/mutt/PATCHES mutt/PATCHES
--- ../MUTT/mutt/PATCHES        2002-12-09 18:44:54.000000000 +0100
+++ mutt/PATCHES        2004-04-15 22:35:57.000000000 +0200
@@ -0,0 +1 @@
+patch-1.5.6.cb.chdir.1
diff -ur ../MUTT/mutt/doc/manual.sgml.head mutt/doc/manual.sgml.head
--- ../MUTT/mutt/doc/manual.sgml.head   2004-04-12 23:51:08.000000000 +0200
+++ mutt/doc/manual.sgml.head   2004-04-15 23:00:37.000000000 +0200
@@ -963,6 +963,17 @@
 name="reference">.  The special function <tt/noop/ unbinds the specified key
 sequence.
 
+
+<sect1>Changing the current working directory <label id="cd">
+<p>
+Usage: <tt/cd/ &lsqb; <em/directory/ &rsqb;
+
+The <tt/cd/ command changes Mutt's current working directory.
+This affects commands and functions like <tt/source/, 
+<tt/change-folder/, and <tt/save-entry/ that use relative paths.
+Using <tt/cd/ without directory changes to your home directory.
+
+
 <sect1>Defining aliases for character sets <label id="charset-hook">
 <p>
 Usage: <tt/charset-hook/ <em/alias/ <em/charset/<newline>
@@ -2995,6 +3006,8 @@
 <item>
 <tt><ref id="bind" name="bind"></tt> <em/map/ <em/key/ <em/function/
 <item>
+<tt><ref id="cd" name="cd"></tt> <em/cd/ &lsqb; <em/directory/ &rsqb;
+<item>
 <tt><ref id="charset-hook" name="charset-hook"></tt> <em/alias/ <em/charset/
 <item>
 <tt><ref id="color" name="color"></tt> <em/object/ <em/foreground/ 
<em/background/ &lsqb; <em/regexp/ &rsqb;
diff -ur ../MUTT/mutt/init.c mutt/init.c
--- ../MUTT/mutt/init.c 2004-04-12 21:55:24.000000000 +0200
+++ mutt/init.c 2004-04-15 22:27:03.000000000 +0200
@@ -1442,6 +1442,35 @@
   return (source_rc (path, err));
 }
 
+static int parse_cd (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
+{
+  char path[_POSIX_PATH_MAX];
+
+  if (mutt_extract_token (tmp, s, 0) != 0)
+  {
+    snprintf (err->data, err->dsize, _("cd: error at %s"), s->dptr);
+    return (-1);
+  }
+  if (MoreArgs (s))
+  {
+    strfcpy (err->data, _("cd: too many arguments"), err->dsize);
+    return (-1);
+  }
+  strfcpy (path, tmp->data, sizeof (path));
+  mutt_expand_path (path, sizeof (path));
+  if (!*path) {
+    char *home = getenv("HOME");
+    if (home)
+      strfcpy (path, home, sizeof (path));
+  }
+  if (chdir(path) != 0) {
+    snprintf (err->data, err->dsize, _("cd: %s"), strerror(errno));
+    return (-1);
+  }
+  return (0);
+}
+
+
 /* line                command to execute
 
    token       scratch buffer to be used by parser.  caller should free
diff -ur ../MUTT/mutt/init.h mutt/init.h
--- ../MUTT/mutt/init.h 2004-04-15 21:15:15.000000000 +0200
+++ mutt/init.h 2004-04-15 21:41:58.000000000 +0200
@@ -2765,6 +2765,7 @@
 static int parse_ignore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_unignore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_source (BUFFER *, BUFFER *, unsigned long, BUFFER *);
+static int parse_cd (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_set (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_my_hdr (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 static int parse_unmy_hdr (BUFFER *, BUFFER *, unsigned long, BUFFER *);
@@ -2787,6 +2788,7 @@
   { "auto_view",       parse_list,             UL &AutoViewList },
   { "alternative_order",       parse_list,     UL &AlternativeOrderList},
   { "bind",            mutt_parse_bind,        0 },
+  { "cd",              parse_cd,               0 },
   { "charset-hook",    mutt_parse_hook,        M_CHARSETHOOK },
 #ifdef HAVE_COLOR
   { "color",           mutt_parse_color,       0 },

Attachment: signature.asc
Description: Digital signature