Standard Library - Misc Functions

execute

fn execute str... -> {
    wait_for -> (fn -> num)
}

Description

Executes the given command in a new process. Returns an object with a wait_for method that waits for the process to finish and returns its exit code.

Example

print execute("echo", "Hello, World!")::wait_for() # 0

times

sub times num, fn

Description

Calls the given function the given number of times.

Example

3.times do i
    print i
end

set_dir

sub set_dir str

Description

Sets the current working directory to the given path.

Example

set_dir "/home/user"

get_dir

fn get_dir -> str

Description

Returns the current working directory.

Example

print get_dir() # /home/user

in_dir

sub in_dir str, callable

Description

Sets the current working directory to the given path, calls the given callable, and then restores the previous working directory.

Example

set_dir "/foo/bar"
print get_dir() # /foo/bar

in_dir "/home/user" do
    print get_dir() # /home/user
end

print get_dir() # /foo/bar