aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-12-21 19:37:15 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-12-21 19:38:07 -0500
commit082786bf79b2672114c5d14dc22d91ba5a90923b (patch)
treeae925a3599e4e47e139ab624c00731c72074ddc3
parent4b976138dce395af734ad4f6a310191ac690e922 (diff)
More sensible REPL-like behavior if run without any args
-rw-r--r--CHANGES.md4
-rw-r--r--src/tomo.c26
2 files changed, 30 insertions, 0 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 0393cecf..e609509b 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,9 @@
# Version History
+## v2025-12-21.6
+
+- Add smarter default behavior if run without any args (REPL-like script runner)
+
## v2025-12-21.5
- Various fixes for versioning and builds.
diff --git a/src/tomo.c b/src/tomo.c
index 1517259e..5ebd6663 100644
--- a/src/tomo.c
+++ b/src/tomo.c
@@ -397,6 +397,32 @@ int main(int argc, char *argv[]) {
run_files = normalize_tm_paths(run_files);
+ if (run_files.length == 0 && format_files.length == 0 && format_files_inplace.length == 0 && parse_files.length == 0
+ && transpile_files.length == 0 && compile_objects.length == 0 && compile_executables.length == 0
+ && run_files.length == 0 && uninstall_libraries.length == 0 && libraries.length == 0) {
+ Path_t path = Path$from_str(String("~/.local/tomo/state/tomo@", TOMO_VERSION, "/run.tm"));
+ path = Path$expand_home(path);
+ Path$create_directory(Path$parent(path), 0755, true);
+ if (!Path$exists(path)) {
+ Path$write(path,
+ Text("# This is a handy Tomo REPL-like runner\n" //
+ "# Normally you would run `tomo ./file.tm` to run a script\n" //
+ "# See `tomo --help` for full usage\n" //
+ "\n" //
+ "func main()\n" //
+ " # Put your code here:\n" //
+ " pass\n" //
+ "\n" //
+ "# Save and exit to run\n"),
+ 0644);
+ }
+ List$insert(&run_files, &path, I(0), sizeof(path));
+ const char *editor = getenv("EDITOR");
+ if (!editor || editor[0] == '\0') editor = "vim";
+ int status = system(String(editor, " ", path));
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) return 1;
+ }
+
// Compile runnable files in parallel, then execute in serial:
for (int64_t i = 0; i < (int64_t)run_files.length; i++) {
Path_t path = *(Path_t *)(run_files.data + i * run_files.stride);