aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-04-16 19:12:27 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-04-16 19:12:27 -0400
commit39b463ff60ea172d5f538310ec4e26b2a5427fb7 (patch)
tree67f548ae3aefdc6548414abf6e482344c6a55584
parent6ccbd79d4db03ed803e828ccd0664895e96f70a8 (diff)
Add Path.current_dir() as exposed method
-rw-r--r--docs/paths.md20
-rw-r--r--src/environment.c1
2 files changed, 21 insertions, 0 deletions
diff --git a/docs/paths.md b/docs/paths.md
index 99891671..6cf986a7 100644
--- a/docs/paths.md
+++ b/docs/paths.md
@@ -49,6 +49,7 @@ intended. Paths can be created from text with slashes using
- [`func child(path: Path, child:Text -> Path)`](#child)
- [`func children(path: Path, include_hidden=no -> [Path])`](#children)
- [`func create_directory(path: Path, permissions=0o755[32] -> Void)`](#create_directory)
+- [`func current_dir(-> Path)`](#current_dir)
- [`func exists(path: Path -> Bool)`](#exists)
- [`func expand_home(path: Path -> Path)`](#expand_home)
- [`func extension(path: Path, full=yes -> Text)`](#extension)
@@ -357,6 +358,25 @@ Nothing.
---
+### `current_dir`
+Creates a new directory at the specified path with the given permissions. If
+any of the parent directories do not exist, they will be created as needed.
+
+```tomo
+func current_dir(-> Path)
+```
+
+**Returns:**
+The absolute path of the current directory.
+
+**Example:**
+```tomo
+>> Path.current_dir()
+= (/home/user/tomo)
+```
+
+---
+
### `exists`
Checks if a file or directory exists at the specified path.
diff --git a/src/environment.c b/src/environment.c
index 9605707a..bf012286 100644
--- a/src/environment.c
+++ b/src/environment.c
@@ -305,6 +305,7 @@ env_t *global_env(bool source_mapping)
{"children", "Path$children", "func(path:Path, include_hidden=no -> [Path])"},
{"concatenated_with", "Path$concat", "func(a,b:Path -> Path)"},
{"create_directory", "Path$create_directory", "func(path:Path, permissions=Int32(0o755))"},
+ {"current_dir", "Path$current_dir", "func(->Path)"},
{"exists", "Path$exists", "func(path:Path -> Bool)"},
{"expand_home", "Path$expand_home", "func(path:Path -> Path)"},
{"extension", "Path$extension", "func(path:Path, full=yes -> Text)"},