NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
commands.c
Go to the documentation of this file.
1
22
28
29#include "config.h"
30#include <stdio.h>
31#include "mutt/lib.h"
32#include "core/lib.h"
33#include "parse/lib.h"
34#include "ifdef.h"
35#include "mailboxes.h"
36#include "parse.h"
37#include "setenv.h"
38#include "source.h"
39
43const struct Command CommandsCommands[] = {
44 // clang-format off
45 { "cd", CMD_CD, parse_cd,
46 N_("Change NeoMutt's current working directory"),
47 N_("cd [ <directory> ]"),
48 "configuration.html#cd" },
49 { "echo", CMD_ECHO, parse_echo,
50 N_("Print a message to the status line"),
51 N_("echo <message>"),
52 "advancedusage.html#echo" },
53 { "finish", CMD_FINISH, parse_finish,
54 N_("Stop reading current config file"),
55 N_("finish"),
56 "optionalfeatures.html#ifdef" },
57 { "ifdef", CMD_IFDEF, parse_ifdef,
58 N_("Conditionally include config commands if symbol defined"),
59 N_("ifdef <symbol> '<config-command> [ <args> ... ]'"),
60 "optionalfeatures.html#ifdef" },
61 { "ifndef", CMD_IFNDEF, parse_ifdef,
62 N_("Conditionally include if symbol is not defined"),
63 N_("ifndef <symbol> '<config-command> [ <args> ... ]'"),
64 "optionalfeatures.html#ifdef" },
65 { "mailboxes", CMD_MAILBOXES, parse_mailboxes,
66 N_("Define a list of mailboxes to watch"),
67 N_("mailboxes [ -label <label> ] [ -notify ] [ -poll ] <mailbox> [ ... ]"),
68 "configuration.html#mailboxes" },
69 { "named-mailboxes", CMD_NAMED_MAILBOXES, parse_mailboxes,
70 N_("Define a list of labelled mailboxes to watch"),
71 N_("named-mailboxes [ -notify ] [ -poll ] <label> <mailbox> [ ... ]"),
72 "configuration.html#mailboxes" },
73 { "reset", CMD_RESET, parse_set,
74 N_("Reset a config option to its initial value"),
75 N_("reset <variable> [ <variable> ... ]"),
76 "configuration.html#set" },
77 { "set", CMD_SET, parse_set,
78 N_("Set a config variable"),
79 N_("set [ no | inv | & ] <variable> [?] | <variable> [=|+=|-=] <value> [...]"),
80 "configuration.html#set" },
81 { "setenv", CMD_SETENV, parse_setenv,
82 N_("Set an environment variable"),
83 N_("setenv { <variable>? | <variable>=<value> }"),
84 "advancedusage.html#setenv" },
85 { "source", CMD_SOURCE, parse_source,
86 N_("Read and execute commands from a config file"),
87 N_("source <filename> [ <filename> ... ]"),
88 "configuration.html#source" },
89 { "toggle", CMD_TOGGLE, parse_set,
90 N_("Toggle the value of a boolean/quad config option"),
91 N_("toggle <variable> [ ... ]"),
92 "configuration.html#set" },
93 { "unmailboxes", CMD_UNMAILBOXES, parse_unmailboxes,
94 N_("Remove mailboxes from the watch list"),
95 N_("unmailboxes { * | <mailbox> ... }"),
96 "configuration.html#mailboxes" },
97 { "unset", CMD_UNSET, parse_set,
98 N_("Reset a config option to false/empty"),
99 N_("unset <variable> [ <variable> ... ]"),
100 "configuration.html#set" },
101 { "unsetenv", CMD_UNSETENV, parse_setenv,
102 N_("Unset an environment variable"),
103 N_("unsetenv <variable>"),
104 "advancedusage.html#setenv" },
105 { "version", CMD_VERSION, parse_version,
106 N_("Show NeoMutt version and build information"),
107 N_("version"),
108 "advancedusage.html#version" },
109
110 { NULL, CMD_NONE, NULL, NULL, NULL, NULL, CF_NONE },
111 // clang-format on
112};
113
120const struct Command *command_find_by_id(const struct CommandArray *ca, enum CommandId id)
121{
122 if (!ca || (id == CMD_NONE))
123 return NULL;
124
125 const struct Command **cp = NULL;
126 ARRAY_FOREACH(cp, ca)
127 {
128 const struct Command *cmd = *cp;
129
130 if (cmd->id == id)
131 return cmd;
132 }
133
134 return NULL;
135}
136
145const struct Command *command_find_by_name(const struct CommandArray *ca, const char *name)
146{
147 if (!ca || !name)
148 return NULL;
149
150 const struct Command **cp = NULL;
151 ARRAY_FOREACH(cp, ca)
152 {
153 const struct Command *cmd = *cp;
154
155 if (mutt_str_equal(cmd->name, name))
156 {
157 // If this is a synonym, look up the real Command
158 if ((cmd->flags & CF_SYNONYM) && cmd->help)
159 {
160 const char *real_name = cmd->help;
161 // Search for the real command (non-recursive, single pass)
162 const struct Command **rp = NULL;
163 ARRAY_FOREACH(rp, ca)
164 {
165 const struct Command *real_cmd = *rp;
166 if (mutt_str_equal(real_cmd->name, real_name) && !(real_cmd->flags & CF_SYNONYM))
167 return real_cmd;
168 }
169 return NULL; // Real command not found
170 }
171 return cmd;
172 }
173 }
174
175 return NULL;
176}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
@ CF_SYNONYM
Command is a synonym for another command.
Definition command.h:50
@ CF_NONE
No flags are set.
Definition command.h:49
CommandId
ID of Command.
Definition command.h:61
@ CMD_CD
:cd
Definition command.h:71
@ CMD_IFNDEF
:ifndef
Definition command.h:87
@ CMD_SETENV
:setenv
Definition command.h:112
@ CMD_IFDEF
:ifdef
Definition command.h:86
@ CMD_SOURCE
:source
Definition command.h:116
@ CMD_ECHO
:echo
Definition command.h:76
@ CMD_VERSION
:version
Definition command.h:150
@ CMD_NONE
No Command.
Definition command.h:62
@ CMD_MAILBOXES
:mailboxes
Definition command.h:94
@ CMD_FINISH
:finish
Definition command.h:80
@ CMD_UNSETENV
:unsetenv
Definition command.h:146
@ CMD_UNMAILBOXES
:unmailboxes
Definition command.h:139
@ CMD_RESET
:reset
Definition command.h:106
@ CMD_NAMED_MAILBOXES
:named-mailboxes
Definition command.h:101
@ CMD_TOGGLE
:toggle
Definition command.h:125
@ CMD_UNSET
:unset
Definition command.h:145
@ CMD_SET
:set
Definition command.h:111
const struct Command * command_find_by_name(const struct CommandArray *ca, const char *name)
Find a NeoMutt Command by its name.
Definition commands.c:145
const struct Command CommandsCommands[]
General NeoMutt Commands.
Definition commands.c:43
const struct Command * command_find_by_id(const struct CommandArray *ca, enum CommandId id)
Find a NeoMutt Command by its CommandId.
Definition commands.c:120
Parse Simple Commands.
Convenience wrapper for the core headers.
enum CommandResult parse_finish(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'finish' command - Implements Command::parse() -.
Definition ifdef.c:150
enum CommandResult parse_echo(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'echo' command - Implements Command::parse() -.
Definition parse.c:96
enum CommandResult parse_cd(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'cd' command - Implements Command::parse() -.
Definition parse.c:59
enum CommandResult parse_setenv(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'setenv' and 'unsetenv' commands - Implements Command::parse() -.
Definition setenv.c:67
enum CommandResult parse_version(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'version' command - Implements Command::parse() -.
Definition parse.c:125
enum CommandResult parse_unmailboxes(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'unmailboxes' command - Implements Command::parse() -.
Definition mailboxes.c:440
enum CommandResult parse_ifdef(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'ifdef' and 'ifndef' commands - Implements Command::parse() -.
Definition ifdef.c:89
enum CommandResult parse_mailboxes(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'mailboxes' command - Implements Command::parse() -.
Definition mailboxes.c:349
enum CommandResult parse_source(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'source' command - Implements Command::parse() -.
Definition source.c:227
enum CommandResult parse_set(const struct Command *cmd, struct Buffer *line, const struct ParseContext *pc, struct ParseError *pe)
Parse the 'set' family of commands - Implements Command::parse() -.
Definition set.c:488
Parse Ifdef Commands.
Parse Mailboxes Commands.
Convenience wrapper for the library headers.
#define N_(a)
Definition message.h:32
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
Text parsing functions.
Parse Setenv Commands.
Parse Source Commands.
CommandFlags flags
Command flags, e.g. CF_SYNONYM.
Definition command.h:187
const char * help
One-line description of the Command.
Definition command.h:183
const char * name
Name of the Command.
Definition command.h:162
enum CommandId id
ID of the Command.
Definition command.h:163