Repositories / jai.git

jai.git

Clone (read-only): git clone http://git.guha-anderson.com/git/jai.git

Branch

make .conf optional for the `-C` option

Author
David Mazieres <dm@uun.org>
Date
2026-03-20 20:56:52 -0700
Commit
6a49a4679db2001fcae05c04b1e1686499092f79
jai.1.md
index 2358040..928811c 100644
--- a/jai.1.md
+++ b/jai.1.md
@@ -178,7 +178,11 @@ opencode`):
 
 `-C` *file*, `--conf `*file*
 : Specifies the configuration file to read.  If *file* does not
-  contain a `/`, the file is relative to `$HOME/.jai`.
+  contain a `/`, the file is relative to `$HOME/.jai`.  Also, if
+  *file* resides in `$HOME/.jai` and does not contain a `/`, you can
+  omit any `.conf` extension.  So `-C default` is equivalent to `-C
+  default.conf` (assuming you don't have a file `default` in addition
+  to `default.conf`).
 
   If no configuration file is specified, the default is based on the
   *cmd* argument.  If *cmd* contains no slashes and does not start
jai.cc
index 2cae277..efeb509 100644
--- a/jai.cc
+++ b/jai.cc
@@ -124,6 +124,13 @@ bool
 Config::parse_config_file(path file, Options *opts)
 {
   bool slash = std::ranges::distance(file.begin(), file.end()) > 1;
+
+  if (struct stat sb; !slash && file.extension() != ".conf" &&
+      fstatat(home_jai(), file.c_str(), &sb, 0) && errno == ENOENT &&
+      ~fstatat(home_jai(), cat(file, ".conf").c_str(), &sb, 0) &&
+      S_ISREG(sb.st_mode))
+    file += ".conf";
+
   auto ld = (slash ? cwd() : homejaipath_) / file;
   if (auto [_it, ok] = config_loop_detect_.insert(ld); !ok)
     err<Options::Error>("configuration loop");