diff --git a/src/Std/Directory.cs b/src/Std/Directory.cs
index f4af070..8d6264d 100644
--- a/src/Std/Directory.cs
+++ b/src/Std/Directory.cs
@@ -9,5 +9,5 @@ static class Directory
{
[ElkFunction("exists")]
public static RuntimeBoolean Exists(RuntimeString path, ShellEnvironment env)
- => RuntimeBoolean.From(System.IO.Directory.Exists(env.GetAbsolutePath(path.Value)));
+ => RuntimeBoolean.From(System.IO.Directory.Exists(ShellEnvironment.GetAbsolutePath(path.Value)));
}
\ No newline at end of file
diff --git a/src/Std/Environment/Environment.cs b/src/Std/Environment/Environment.cs
index 3915f33..43c040b 100644
--- a/src/Std/Environment/Environment.cs
+++ b/src/Std/Environment/Environment.cs
@@ -51,7 +51,7 @@ public static void Cd(RuntimeString? path = null, ShellEnvironment? env = null)
var absolutePath = path.Value == "-"
? System.Environment.GetEnvironmentVariable("OLDPWD") ?? ""
- : env!.GetAbsolutePath(path.Value);
+ : ShellEnvironment.GetAbsolutePath(path.Value);
if (!System.IO.Directory.Exists(absolutePath))
throw new RuntimeException($"cd: The directory \"{path}\" does not exist");
diff --git a/src/Std/Environment/Path.cs b/src/Std/Environment/Path.cs
index a14882d..eb53bbc 100644
--- a/src/Std/Environment/Path.cs
+++ b/src/Std/Environment/Path.cs
@@ -4,6 +4,7 @@
using Elk.Exceptions;
using Elk.Std.Attributes;
using Elk.Std.DataTypes;
+using Elk.Vm;
#endregion
@@ -23,7 +24,8 @@ public static class Path
[ElkFunction("add")]
public static void Add(RuntimeString path)
{
- System.IO.File.AppendAllText(CommonPaths.PathFile, $"{path}\n");
+ var absolutePath = ShellEnvironment.GetAbsolutePath(path.Value);
+ System.IO.File.AppendAllText(CommonPaths.PathFile, $"{absolutePath}\n");
// Reload the path variable
var pathVar = System.Environment.GetEnvironmentVariable("PATH") ?? "";
diff --git a/src/Std/File.cs b/src/Std/File.cs
index 4713bee..a35f98a 100644
--- a/src/Std/File.cs
+++ b/src/Std/File.cs
@@ -9,7 +9,7 @@ static class File
{
[ElkFunction("exists")]
public static RuntimeBoolean Exists(RuntimeString path, ShellEnvironment env)
- => RuntimeBoolean.From(System.IO.File.Exists(env.GetAbsolutePath(path.Value)));
+ => RuntimeBoolean.From(System.IO.File.Exists(ShellEnvironment.GetAbsolutePath(path.Value)));
[ElkFunction("executableExists")]
public static RuntimeBoolean ExecutableExists(RuntimeString path)
diff --git a/src/Std/IO.cs b/src/Std/IO.cs
index 32b9cef..a6417eb 100644
--- a/src/Std/IO.cs
+++ b/src/Std/IO.cs
@@ -28,7 +28,7 @@ static class IO
/// Text content of the file at the provided path.
[ElkFunction("read", Reachability.Everywhere)]
public static RuntimeString ReadFile(RuntimeString path, ShellEnvironment env)
- => new(System.IO.File.ReadAllText(env.GetAbsolutePath(path.Value)));
+ => new(System.IO.File.ReadAllText(ShellEnvironment.GetAbsolutePath(path.Value)));
/// Writes the provided text to a file, overwriting any previous content.
/// Text that should be written to the file
@@ -37,7 +37,7 @@ public static RuntimeString ReadFile(RuntimeString path, ShellEnvironment env)
[ElkFunction("write", Reachability.Everywhere, ConsumesPipe = true)]
public static void WriteToFile(RuntimeObject content, RuntimeString path, ShellEnvironment env)
{
- var absolutePath = env.GetAbsolutePath(path.Value);
+ var absolutePath = ShellEnvironment.GetAbsolutePath(path.Value);
if (content is RuntimePipe runtimePipe)
{
var fileInfo = new FileInfo(absolutePath);
@@ -73,7 +73,7 @@ public static void WriteToFile(RuntimeObject content, RuntimeString path, ShellE
[ElkFunction("append", Reachability.Everywhere)]
public static void AppendToFile(RuntimeObject content, RuntimeString path, ShellEnvironment env)
{
- var absolutePath = env.GetAbsolutePath(path.Value);
+ var absolutePath = ShellEnvironment.GetAbsolutePath(path.Value);
var fileInfo = new FileInfo(absolutePath);
if (content is RuntimePipe runtimePipe)
@@ -118,7 +118,7 @@ public static void AppendToFile(RuntimeObject content, RuntimeString path, Shell
/// nil
[ElkFunction("appendEnd", Reachability.Everywhere)]
public static void AppendEnd(RuntimeString content, RuntimeString path, ShellEnvironment env)
- => System.IO.File.AppendAllText(env.GetAbsolutePath(path.Value), content.Value);
+ => System.IO.File.AppendAllText(ShellEnvironment.GetAbsolutePath(path.Value), content.Value);
/// Reads the next line from the standard input stream. This is used to get input from the user in a terminal.
/// Text that should be printed before the input prompt
diff --git a/src/Vm/ShellEnvironment.cs b/src/Vm/ShellEnvironment.cs
index d4069c8..4368551 100644
--- a/src/Vm/ShellEnvironment.cs
+++ b/src/Vm/ShellEnvironment.cs
@@ -28,7 +28,7 @@ public static string WorkingDirectory
public string? ScriptPath { get; set; } = scriptPath;
- public string GetAbsolutePath(string relativePath)
+ public static string GetAbsolutePath(string relativePath)
=> Path.GetFullPath(Path.Combine(WorkingDirectory, relativePath));
}
\ No newline at end of file