diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fe85d41..69dd4cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ **scrollback-indicator-format** options in `footrc` (https://codeberg.org/dnkl/foot/issues/42). * Key bindings in _scollback search_ mode are now configurable. +* `--check-config` command line option. ### Deprecated diff --git a/completions/zsh/_foot b/completions/zsh/_foot index ac8e6e8e..ae8d34b1 100644 --- a/completions/zsh/_foot +++ b/completions/zsh/_foot @@ -3,6 +3,7 @@ _arguments \ -s -S -C \ '(-c --config)'{-c,--config}'[path to configuration file (XDG_CONFIG_HOME/footrc)]:config:_files' \ + '--check-config[verify configuration and exit with 0 if ok, otherwise exit with 1]' \ '(-f --font)'{-f,--font}'[font name and style in fontconfig format (monospace)]:font:->fonts' \ '(-t --term)'{-t,--term}'[value to set the environment variable TERM to (foot)]:term:->terms' \ '--title[initial window title]:()' \ diff --git a/doc/foot.1.scd b/doc/foot.1.scd index c22eea70..b8e5593a 100644 --- a/doc/foot.1.scd +++ b/doc/foot.1.scd @@ -15,6 +15,10 @@ arguments, to execute (instead of the default shell). *-c*,*--config*=_PATH_ Path to configuration file. Default: *XDG_CONFIG_HOME/footrc*. +*--check-config* + Verify configuration and then exit with 0 if ok, otherwise exit + with 1. + *-f*,*--font*=_FONT_ Comma separated list of fonts to use, in fontconfig format (see *FONT FORMAT*). diff --git a/main.c b/main.c index 590e01c0..6523907b 100644 --- a/main.c +++ b/main.c @@ -46,6 +46,7 @@ print_usage(const char *prog_name) "\n" "Options:\n" " -c,--config=PATH load configuration from PATH (XDG_CONFIG_HOME/footrc)\n" + " --check-config verify configuration, exit with 0 if ok, otherwise exit with 1\n" " -f,--font=FONT comma separated list of fonts in fontconfig format (monospace)\n" " -t,--term=TERM value to set the environment variable TERM to (foot)\n" " --title=TITLE initial window title (foot)\n" @@ -142,6 +143,7 @@ main(int argc, char *const *argv) static const struct option longopts[] = { {"config", required_argument, NULL, 'c'}, + {"check-config", no_argument, NULL, 'C'}, {"term", required_argument, NULL, 't'}, {"title", required_argument, NULL, 'T'}, {"app-id", required_argument, NULL, 'a'}, @@ -161,6 +163,7 @@ main(int argc, char *const *argv) {NULL, no_argument, NULL, 0}, }; + bool check_config = false; const char *conf_path = NULL; const char *conf_term = NULL; const char *conf_title = NULL; @@ -181,7 +184,7 @@ main(int argc, char *const *argv) bool log_syslog = true; while (true) { - int c = getopt_long(argc, argv, "+c:t:a:Lf:g:s::Pp:l::Svh", longopts, NULL); + int c = getopt_long(argc, argv, "+c:Ct:a:Lf:g:s::Pp:l::Svh", longopts, NULL); if (c == -1) break; @@ -190,6 +193,10 @@ main(int argc, char *const *argv) conf_path = optarg; break; + case 'C': + check_config = true; + break; + case 't': conf_term = optarg; break; @@ -320,6 +327,11 @@ main(int argc, char *const *argv) return ret; } + if (check_config) { + config_free(conf); + return EXIT_SUCCESS; + } + setlocale(LC_CTYPE, ""); LOG_INFO("locale: %s", setlocale(LC_CTYPE, NULL)); if (!locale_is_utf8()) {