* @param value Current value of the config item
* @param initial Initial value of the config item
* @param flags Flags, e.g. #CS_DUMP_ONLY_CHANGED
+ * @param fp File pointer to write to
*/
-void dump_config_mutt(struct ConfigSet *cs, struct HashElem *he,
- struct Buffer *value, struct Buffer *initial, int flags)
+void dump_config_mutt(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value,
+ struct Buffer *initial, int flags, FILE *fp)
{
const char *name = he->key.strkey;
{
if ((value->data[0] == 'y') || ((value->data[0] == '"') && (value->data[1] == 'y')))
{
- printf("%s is set\n", name);
+ fprintf(fp, "%s is set\n", name);
}
else
{
- printf("%s is unset\n", name);
+ fprintf(fp, "%s is unset\n", name);
}
}
else
{
- printf("%s=%s\n", name, value->data);
+ fprintf(fp, "%s=%s\n", name, value->data);
}
}
* @param value Current value of the config item
* @param initial Initial value of the config item
* @param flags Flags, e.g. #CS_DUMP_ONLY_CHANGED
+ * @param fp File pointer to write to
*/
-void dump_config_neo(struct ConfigSet *cs, struct HashElem *he,
- struct Buffer *value, struct Buffer *initial, int flags)
+void dump_config_neo(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value,
+ struct Buffer *initial, int flags, FILE *fp)
{
const char *name = he->key.strkey;
{
const struct ConfigDef *cdef = he->data;
const char *syn = (const char *) cdef->initial;
- printf("# synonym: %s -> %s\n", name, syn);
+ fprintf(fp, "# synonym: %s -> %s\n", name, syn);
return;
}
bool show_value = !(flags & CS_DUMP_HIDE_VALUE);
if (show_name && show_value)
- printf("set ");
+ fprintf(fp, "set ");
if (show_name)
- printf("%s", name);
+ fprintf(fp, "%s", name);
if (show_name && show_value)
- printf(" = ");
+ fprintf(fp, " = ");
if (show_value)
- printf("%s", value->data);
+ fprintf(fp, "%s", value->data);
if (show_name || show_value)
- printf("\n");
+ fprintf(fp, "\n");
if (flags & CS_DUMP_SHOW_DEFAULTS)
{
const struct ConfigSetType *cst = cs_get_type_def(cs, he->type);
if (cst)
- printf("# %s %s %s\n", cst->name, name, value->data);
+ fprintf(fp, "# %s %s %s\n", cst->name, name, value->data);
}
}
/**
- * dump_config - Write all the config to stdout
+ * dump_config - Write all the config to a file
* @param cs ConfigSet to dump
* @param style Output style, e.g. #CS_DUMP_STYLE_MUTT
* @param flags Display flags, e.g. #CS_DUMP_ONLY_CHANGED
+ * @param fp File to write config to
*/
-bool dump_config(struct ConfigSet *cs, int style, int flags)
+bool dump_config(struct ConfigSet *cs, int style, int flags, FILE *fp)
{
if (!cs)
return false;
}
if (style == CS_DUMP_STYLE_MUTT)
- dump_config_mutt(cs, he, value, initial, flags);
+ dump_config_mutt(cs, he, value, initial, flags, fp);
else
- dump_config_neo(cs, he, value, initial, flags);
+ dump_config_neo(cs, he, value, initial, flags, fp);
}
FREE(&list);
#define CS_DUMP_SHOW_DISABLED (1 << 6) /**< Show disabled config items, too */
#define CS_DUMP_SHOW_SYNONYMS (1 << 7) /**< Show synonyms and the config items their linked to */
-void dump_config_mutt(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value, struct Buffer *initial, int flags);
-void dump_config_neo(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value, struct Buffer *initial, int flags);
-bool dump_config(struct ConfigSet *cs, int style, int flags);
+void dump_config_mutt(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value, struct Buffer *initial, int flags, FILE *fp);
+void dump_config_neo(struct ConfigSet *cs, struct HashElem *he, struct Buffer *value, struct Buffer *initial, int flags, FILE *fp);
+bool dump_config(struct ConfigSet *cs, int style, int flags, FILE *fp);
int elem_list_sort(const void *a, const void *b);
size_t escape_string(struct Buffer *buf, const char *src);
struct HashElem **get_elem_list(struct ConfigSet *cs);
#include "version.h"
// clang-format off
+static enum CommandResult icmd_set(struct Buffer *, struct Buffer *, unsigned long, struct Buffer *);
+
/**
* ICommandList - All available informational commands
*
* @note These commands take precendence over conventional mutt rc-lines
*/
const struct ICommand ICommandList[] = {
+ { "set", icmd_set, 0 },
{ NULL, NULL, 0 },
};
// clang-format on
FREE(&expn.data);
return rc;
}
+
+/**
+ * icmd_set - Parse 'set' command to display config - Implements ::icommand_t
+ */
+static enum CommandResult icmd_set(struct Buffer *buf, struct Buffer *s,
+ unsigned long data, struct Buffer *err)
+{
+ char tempfile[PATH_MAX];
+ mutt_mktemp(tempfile, sizeof(tempfile));
+
+ FILE *fpout = mutt_file_fopen(tempfile, "w");
+ if (!fpout)
+ {
+ mutt_buffer_addstr(err, _("Could not create temporary file"));
+ return MUTT_CMD_ERROR;
+ }
+
+ if (mutt_str_strcmp(s->data, "set all") == 0)
+ {
+ dump_config(Config, CS_DUMP_STYLE_NEO, 0, fpout);
+ }
+ else if (mutt_str_strcmp(s->data, "set") == 0)
+ {
+ dump_config(Config, CS_DUMP_STYLE_NEO, CS_DUMP_ONLY_CHANGED, fpout);
+ }
+ else
+ {
+ mutt_file_fclose(&fpout);
+ return MUTT_CMD_ERROR;
+ }
+
+ fflush(fpout);
+ mutt_file_fclose(&fpout);
+
+ struct Pager info = { 0 };
+ if (mutt_pager("set", tempfile, 0, &info) == -1)
+ {
+ mutt_buffer_addstr(err, _("Could not create temporary file"));
+ return MUTT_CMD_ERROR;
+ }
+
+ return MUTT_CMD_SUCCESS;
+}