~kevin8t8/mutt

c44f0ce5de6865495d3fe61072a4245039476157 — Kevin McCarthy 6 months ago b3ab8ca
Add cd command to change the current working directory.

Original Author: Christoph Berg <myon@debian.org>
Use cases are saving attachments to some other place and others.

Modified by Kevin McCarthy:
- Fix up documentation to use cmdsynopsis/command/arg.
- Add muttrc.man entry.
- Fix compilation error.
- Clean up the parse_cd() function to use buffers and remove new
  translation strings.
4 files changed, 61 insertions(+), 0 deletions(-)

M doc/manual.xml.head
M doc/muttrc.man.head
M init.c
M init.h
M doc/manual.xml.head => doc/manual.xml.head +31 -0
@@ 2778,6 2778,28 @@ specified key sequence.

</sect1>

<sect1 id="cd">
<title>Changing the current working directory</title>

<para>Usage:</para>

<cmdsynopsis>
<command>cd</command>
<arg choice="plain">
<replaceable class="parameter">directory</replaceable>
</arg>
</cmdsynopsis>

<para>
The <literal>cd</literal> command changes Mutt's current working directory.
This affects commands and functions like <literal>source</literal>,
<literal>change-folder</literal>, and <literal>save-entry</literal> that use
relative paths. Using <literal>cd</literal> without directory changes to your
home directory.
</para>

</sect1>

<sect1 id="charset-hook">
<title>Defining Aliases for Character Sets</title>



@@ 10808,6 10830,15 @@ The following are the commands understood by Mutt:

<listitem>
<cmdsynopsis>
<command><link linkend="cd">cd</link></command>
<arg choice="plain">
<replaceable class="parameter">directory</replaceable>
</arg>
</cmdsynopsis>
</listitem>

<listitem>
<cmdsynopsis>
<command><link linkend="charset-hook">charset-hook</link></command>
<arg choice="plain">
<replaceable class="parameter">alias</replaceable>

M doc/muttrc.man.head => doc/muttrc.man.head +3 -0
@@ 486,6 486,9 @@ the generated message.  By default the list contains only
Prints \fImessage\fP to the message window. After printing the
message, echo will pause for the number of seconds specified by
$sleep_time.
.TP
\fBcd\fP \fIdirectory\fP
Changes the current working directory.
.SH PATTERNS
.PP
In various places with mutt, including some of the above mentioned

M init.c => init.c +25 -0
@@ 2865,6 2865,31 @@ int mutt_parse_rc_line (const char *line, BUFFER *err)
  return rc;
}

static int parse_cd (BUFFER *tmp, BUFFER *s, union pointer_long_t udata, BUFFER *err)
{
  mutt_extract_token (tmp, s, 0);
  mutt_buffer_expand_path (tmp);
  if (!mutt_buffer_len (tmp))
  {
    if (Homedir)
      mutt_buffer_strcpy (tmp, Homedir);
    else
    {
      mutt_buffer_strcpy (err, _("too few arguments"));
      return -1;
    }
  }

  if (chdir (mutt_b2s (tmp)) != 0)
  {
    mutt_buffer_printf (err, "cd: %s", strerror (errno));
    return (-1);
  }

  return (0);
}


/* line		command to execute

   token	scratch buffer to be used by parser.

M init.h => init.h +2 -0
@@ 4585,6 4585,7 @@ static int parse_echo (BUFFER *, BUFFER *, union pointer_long_t, BUFFER *);
static int parse_ignore (BUFFER *, BUFFER *, union pointer_long_t, BUFFER *);
static int parse_unignore (BUFFER *, BUFFER *, union pointer_long_t, BUFFER *);
static int parse_source (BUFFER *, BUFFER *, union pointer_long_t, BUFFER *);
static int parse_cd (BUFFER *, BUFFER *, union pointer_long_t, BUFFER *);
static int parse_set (BUFFER *, BUFFER *, union pointer_long_t, BUFFER *);
static int parse_setenv (BUFFER *, BUFFER *, union pointer_long_t, BUFFER *);
static int parse_my_hdr (BUFFER *, BUFFER *, union pointer_long_t, BUFFER *);


@@ 4625,6 4626,7 @@ const struct command_t Commands[] = {
  { "auto_view",	parse_list,		{.p=&AutoViewList} },
  { "alternative_order",	parse_list,	{.p=&AlternativeOrderList} },
  { "bind",		mutt_parse_bind,	{.l=0} },
  { "cd",		parse_cd,		{.l=0} },
  { "charset-hook",	mutt_parse_hook,	{.l=MUTT_CHARSETHOOK} },
#ifdef HAVE_COLOR
  { "color",		mutt_parse_color,	{.l=0} },