OS

OS related functions

cwd?

Gets the current working directory.

none

returns uri representing the current working directory

cc os
print cwd?
ls |for { .print }
ls\ 'files |for { .print }
host-info? -> "hostname" |print
load-avg? -> "1" |print
virtual-memory? -> "total" |print
disk-usage? |print
processes? |first |print


does-exist

Checks if a file or directory exists.

Args: 1

path uri representing the file or directory to check

returns boolean: true if exists, false if not

cc os does-exist %main.rye
; returns true

cd

Changes the current working directory.

Args: 1

path uri representing the directory to change to

returns the same uri if successful

env?

Gets the value of an environment variable.

Args: 1

variable_name string containing the name of the environment variable

returns string containing the value of the environment variable

mkdir

Creates a new directory.

Args: 1

path uri representing the directory to create

returns the same uri if successful

mktmp

Creates a new temporary directory.

none

returns uri representing the created temporary directory

rm

Removes a file or empty directory.

Args: 1

path uri representing the file or empty directory to remove

returns the uri if successfulTags: #file #delete

rmdir

Removes a directory and all its contents recursively.

Args: 1

path uri representing the directory to remove (including contents)

returns the uri if successfulTags: #file #delete

cp

Copies a file to a new location.

Args: 2

source uri representing the source file

destination uri representing the destination file

returns destination uri if successfulTags: #file #copy

file-info?

Gets detailed information about a file or directory.

Args: 1

path uri representing the file or directory

returns dict with keys: name, size, mode, mod-time, is-dirTags: #file #info

is-dir

Checks if a path is a directory. Fails if the path does not exist.

Args: 1

path uri representing the path to check

returns boolean: true if path is a directory, false otherwise. Fails if the path does not exist.Tags: #file #check

is-file

Checks if a path is a regular file (not a directory). Fails if the path does not exist.

Args: 1

path uri representing the path to check

returns boolean: true if path is a regular file, false otherwise. Fails if the path does not exist.Tags: #file #check

home-dir?

Gets the current user's home directory.

none

returns uri representing the user's home directoryTags: #file #directory

tmp-dir?

Gets the system's default temporary directory.

none

returns uri representing the system's temporary directoryTags: #file #directory

glob

Returns files matching a glob pattern.

Args: 1

pattern string containing a glob pattern (e.g., "*.txt", "data/*.csv")

returns block of uris matching the patternTags: #file #search

mv

Moves or renames a file or directory.

Args: 2

source uri representing the source file or directory

destination uri representing the destination file or directory

returns destination uri if successful

ls

Lists files and directories in the current directory.

none

returns block of uris representing files and directories in the current directory

ls\

Lists files or directories with absolute paths when possible. If argument is a file-uri, lists that directory (or returns failure if not a directory). Otherwise filters current directory: 'dirs' for directories only, 'files' for files only, a string for partial name matching, or a regexp to match names.

Args: 1

filter file-uri to list directory, word 'dirs' or 'files' to filter by type, string for partial name matching, or regexp to match names

returns block of uris representing filtered files or directories in the specified directory or current directory

ls\dirs

Lists only directories in the current directory.

none

returns block of uris representing directories in the current directory

ls\files

Lists only files (non-directories) in the current directory.

none

returns block of uris representing files (non-directories) in the current directory

ls\dirs\

Lists directories in the current directory with filtering. Use a string for partial name matching, or a regexp to match names.

Args: 1

filter string for partial name matching, or regexp to match names

returns block of uris representing filtered directories in the current directory

ls\files\

Lists files (non-directories) in the current directory with filtering. Use a string for partial name matching, or a regexp to match names.

Args: 1

filter string for partial name matching, or regexp to match names

returns block of uris representing filtered files (non-directories) in the current directory

symlink

Creates a symbolic link.

Args: 2

path uri representing source path

link uri representing link path to create

returns link uri if successfulTags: #file #link

is-symlink

Checks if a path is a symbolic link. Fails if the path does not exist.

Args: 1

path uri representing a path to check

returns boolean: true if path is a symbolic linkTags: #file #check

readlink

Reads the target of a symbolic link.

Args: 1

path uri representing a symbolic link

returns uri representing the target of the symlinkTags: #file #link

chmod

Changes file or directory permissions.

Args: 2

path uri representing file or directory path

mode integer representing file mode (e.g., 0755)

returns path uri if successfulTags: #file #permissions

abs-path

Returns the absolute path for a given path.

Args: 1

path uri representing file or directory

returns string representing the absolute pathTags: #file #path

dirname

Returns the directory part of a path.

Args: 1

path uri representing a path

returns uri representing the directory containing the pathTags: #file #path

basename

Returns the filename part of a path.

Args: 1

path uri representing a path

returns string representing the filename part of the pathTags: #file #path

file-ext

Returns the file extension of a path (including the dot).

Args: 1

path uri representing a file path

returns string representing the file extension (including the dot)Tags: #file #path

join-path

Joins path elements into a single path.

Args: 1

paths uri or block of uris to join

returns uri representing the joined pathTags: #file #path

whoami

Returns the current user's username.

none

returns string representing the current user's usernameTags: #system #user

which

Finds the path to an executable command.

Args: 1

command string representing the command to check

returns uri representing the path to the executable, or error if not foundTags: #system #command

cp-r

Recursively copies a directory and all its contents.

Args: 2

source uri representing source directory

destination uri representing destination directory

returns destination uri if successfulTags: #file #copy #recursive

mkdir-p

Creates a directory and any necessary parent directories.

Args: 1

path uri representing directory path to create

returns path uri if successfulTags: #file #directory

host-info?

Gets information about the host system.

none

returns dictionary containing information about the host system (hostname, uptime, OS, etc.)

users?

Gets information about users currently logged into the system.

none

returns table containing information about users (user, terminal, host, started)

load-avg?

Gets the system load average over the last 1, 5, and 15 minutes.

none

returns dictionary with keys "1", "5", and "15" representing load averages

virtual-memory?

Gets information about virtual memory usage.

none

returns dictionary containing information about virtual memory (total, free, used-percent)

disk-usage?

Gets disk usage information for all partitions.

none

returns table containing disk usage information for all partitions

pids?

Gets a list of all process IDs currently running.

none

returns block of integers representing process IDs

processes?

Gets detailed information about all running processes.

none

returns table containing detailed information about all running processes

process

Gets detailed information about a specific process by PID.

Args: 1

pid integer process ID

returns dictionary containing detailed information about the specified process

lookup-address

Performs a reverse DNS lookup to get hostnames for an IP address.

Args: 1

ip string containing an IP address

returns block of strings containing hostnames associated with the IP

lookup-ip

Performs a DNS lookup to get IP addresses for a hostname.

Args: 1

hostname string containing a hostname

returns block of strings containing IP addresses associated with the hostname

write\clipboard

Writes a string value to the system clipboard.

Args: 1

value string to write to the clipboard

returns the same string if successful

read\clipboard

Reads the current contents of the system clipboard.

none

returns string containing the current contents of the clipboard

tgz

Creates a .tar.gz archive from a file or directory.

Args: 2

source uri representing the file or directory to archive

destination uri representing the output .tar.gz file

returns destination uri if successfulTags: #archive #compress

un-tgz

Extracts a .tar.gz archive to a directory.

Args: 2

source uri representing the .tar.gz file

destination uri representing the output directory

returns destination uri if successfulTags: #archive #extract

zip

Creates a .zip archive from a file or directory.

Args: 2

source uri representing the file or directory to archive

destination uri representing the output .zip file

returns destination uri if successfulTags: #archive #compress

unzip

Extracts a .zip archive to a directory.

Args: 2

source uri representing the .zip file

destination uri representing the output directory

returns destination uri if successfulTags: #archive #extract

find

Creates a new file finder starting from the given path(s).

Args: 1

path uri or block of uris representing starting paths

returns native finder objectTags: #find #files

finder//min-depth!

Sets the minimum depth for file traversal.

Args: 2

finder native finder object

depth integer minimum depth

returns native finder object (for chaining)Tags: #find #filter

finder//max-depth!

Sets the maximum depth for file traversal.

Args: 2

finder native finder object

depth integer maximum depth

returns native finder object (for chaining)Tags: #find #filter

finder//type

Filters results by type: 'file (or "f") for files, 'dir (or "d") for directories.

Args: 2

finder native finder object

type word 'file or 'dir (or string "f" or "d")

returns native finder object (for chaining)Tags: #find #filter

finder//name

Filters results by file name using a glob pattern.

Args: 2

finder native finder object

pattern string glob pattern (e.g., "*.go", "test_*")

returns native finder object (for chaining)Tags: #find #filter

finder//whole-name

Filters results by full path using a glob pattern.

Args: 2

finder native finder object

pattern string glob pattern for the whole path

returns native finder object (for chaining)Tags: #find #filter

finder//regex

Filters results by regular expression on the full path.

Args: 2

finder native finder object

regex native regexp object

returns native finder object (for chaining)Tags: #find #filter

finder//empty

Filters for empty files or directories.

Args: 1

finder native finder object

returns native finder object (for chaining)Tags: #find #filter

finder//eval

Executes the find operation and returns matching paths as uris.

Args: 1

finder native finder object

returns block of uris representing found files/directoriesTags: #find #execute

file-size

Gets the size of a file in bytes.

Args: 1

path uri representing the file

returns integer size in bytesTags: #file #size

touch

Creates a file if it doesn't exist, or updates its access time if it does.

Args: 1

path uri representing the file to touch

returns path uri if successfulTags: #file #create

hardlink

Creates a hard link to a file.

Args: 2

source uri representing the source file

link uri representing the hard link to create

returns link uri if successfulTags: #file #link

count-dir

Counts the number of files and directories in a directory.

Args: 1

path uri representing the directory (optional, defaults to current dir)

returns integer count of itemsTags: #file #count

pid

Gets the current process ID.

none

returns integer process IDTags: #system #process

ppid

Gets the parent process ID.

none

returns integer parent process IDTags: #system #process

sleep

Sleeps for the specified number of seconds.

Args: 1

duration integer seconds to sleep

returns integer seconds sleptTags: #system #time

tmux-available?

Checks if tmux is available on the system.

none

returns boolean indicating if tmux is availableTags: #tmux #check

tmux-new-session

Creates a new tmux session with the given name using gotmux library.

Args: 1

session-name string name for the new session

returns native tmux session objectTags: #tmux #session

tmux-list-sessions

Lists all tmux sessions using gotmux library.

none

returns block of native tmux session objectsTags: #tmux #session #list

tmux-get-session

Gets a tmux session by name using gotmux library.

Args: 1

session-name string name of the session to get

returns native tmux session objectTags: #tmux #session

tmux-new-window

Creates a new window in the given tmux session.

Args: 1

session native tmux session object

returns native tmux window objectTags: #tmux #window

tmux-new-window-named

Creates a new window in the given tmux session with a specific name.

Args: 2

session native tmux session object

window-name string name for the window

returns native tmux window objectTags: #tmux #window

tmux-list-windows

Lists all windows in the given tmux session.

Args: 1

session native tmux session object

returns block of native tmux window objectsTags: #tmux #window #list

tmux-get-pane

Gets a pane from a tmux window by index.

Args: 2

window native tmux window object

index integer pane index (0-based)

returns native tmux pane objectTags: #tmux #pane

tmux-split-pane

Splits a tmux pane horizontally.

Args: 1

pane native tmux pane object

returns native tmux pane objectTags: #tmux #pane

tmux-send-keys

Sends keys/command to a tmux pane.

Args: 2

pane native tmux pane object

command string command to send

returns native tmux pane objectTags: #tmux #pane #command

tmux-kill-session

Kills/destroys a tmux session.

Args: 1

session native tmux session object

returns native tmux session objectTags: #tmux #session

net-interface?

Looks up a network interface by name and returns it as a native object.

Args: 1

name String name of the network interface (e.g., "eth0", "tailscale0", "lo")

returns native net-iface object representing the interface, or error if not found

net-iface//Addrs?

Returns a block of network addresses assigned to the interface.

Args: 1

iface Native net-iface object

returns block of native net-addr objects assigned to the interface, or error

; iface: net-interface-by-name "lo"
; addrs: iface .Addrs?

net-addr//IPNet?

Type-asserts a network address to *net.IPNet (CIDR form). Returns failure if the address is not an IP network.

Args: 1

addr Native net-addr object (from net-iface//Addrs)

returns native net-ipnet object if the address is an IP network, or failure if it isa plain net.Addr (e.g., a point-to-point address not yet assigned)

; addr: iface .Addrs? |first
; ipnet: addr .IPNet?

net-ipnet//Loopback?

Reports whether the IP address in the IPNet is a loopback address.

Args: 1

ipnet Native net-ipnet object

returns boolean – true if the IP is a loopback address, false otherwise

; ipnet .Loopback?  ; returns true for 127.0.0.1/8

net-ipnet//IPv4?

Reports whether the IP address in the IPNet is an IPv4 address (IP.To4() != nil).

Args: 1

ipnet Native net-ipnet object

returns boolean – true if the IP address is IPv4, false if it is IPv6-only

; ipnet .IPv4?  ; returns true when the address is an IPv4 address

net-ipnet//IP-string?

Returns the IP address contained in the IPNet as a dotted-decimal (or colon-separated) string.

Args: 1

ipnet Native net-ipnet object

returns string representation of the IP address (without the prefix length)

; ipnet .IP-string?  ; returns "100.64.0.1"

SSH

SSH server functions

ssh-server

Creates a new SSH server that listens on the specified address.

Args: 1

address String containing host

returns native SSH server object

server: ssh-server "localhost:2222"
server |Password-auth { pass = "secret123" }
server |Handle fn { session } {
session .Write "Welcome to Rye SSH server!
"
session .Write "Type 'exit' to quit.
"
}
server |Serve


ssh-server//Handle

Sets a handler function for SSH sessions on the server.

Args: 2

server SSH server object

handler Function that receives an SSH session object

returns the SSH server object

ssh-server//Password-auth

Sets a password authentication handler for the SSH server.

Args: 2

server SSH server object

handler Function that receives a password string and returns true/false

returns the SSH server object

ssh-server//Serve

Starts the SSH server, listening for connections.

Args: 1

server SSH server object

returns the SSH server object, or error if unable to serve

ssh-session//Write

Writes a string to an SSH session.

Args: 2

session SSH session object

text String to write to the session

returns the SSH session object

Default

go-with

Executes a function in a separate goroutine, passing the specified value as an argument.

Args: 2

value Object to pass to the goroutine function

function Function to execute in a separate goroutine, receives the value as argument

returns the original value that was passed to the goroutine

x:: 0 , go-with 5 fn { v } { change! v 'x } , sleep 100 , x
; returns 5
y:: 0 , go-with "test" fn { v } { change! length? v 'y } , sleep 100 , y
; returns 4
; Simple goroutine with channel communication
ch: channel 1
go fn { } { ch .Send "Hello from goroutine" }
print ch .Read

; Using waitgroup to coordinate multiple goroutines
wg: waitgroup
results: channel 10
loop 5 { i |
wg .Add 1
go-with i fn { n } { results .Send n * 2 , wg .Done }
}
wg .Wait
results .Close

; Mutex for safe shared state
counter:: 0
mtx: mutex
go fn { } { mtx .Lock , change! counter + 1 'counter , mtx .Unlock }


go

Executes a function in a separate goroutine without passing any arguments.

Args: 1

function Function to execute in a separate goroutine (takes no arguments)

returns the function that was executed

x:: 0 , go fn { } { change! 42 'x } , sleep 100 , x
; returns 42
y:: "unchanged" , go fn { } { change! "changed" 'y } , sleep 100 , y
; returns "changed"

channel

Creates a new channel with the specified buffer size for goroutine communication.

Args: 1

buffer-size Integer specifying the channel buffer size (0 for unbuffered)

returns a new channel native object with the specified buffer size

[Native of kind Rye-channel] Methods (Rye-channel): Close [Builtin(1): Closes a channel, preventing further sends and causing pending/future reads to return an error. (goroutines) (Rye-channel//Close)] Read [Builtin(1): Reads the next value from a channel, blocking until a value is available or the channel is closed. (goroutines) (Rye-channel//Read)] Send [Builtin(2): Sends a value through a channel, blocking if the channel is unbuffered or full. (goroutines) (Rye-channel//Send)]
ch: channel 1 , ch .probe .lg .Send 42 , ch .Read
; returns 42
ch: channel 2 , ch .Send 1 , ch .Send 2 , ch .Read
; returns 1
channel 5 |type?
; returns native

Rye-channel//Read

Reads the next value from a channel, blocking until a value is available or the channel is closed.

Args: 1

channel Channel to read from

returns the next value from the channel, or an error if the channel is closed

ch: channel 1 , ch .Send 123 , ch .Read
; returns 123
ch: channel 1 , ch .Send "test" , ch .Read
; returns "test"
ch: channel 1 , ch .Close , try { ch .Read } |type?
; returns error

Rye-channel//Send

Sends a value through a channel, blocking if the channel is unbuffered or full.

Args: 2

channel Channel to send the value to

value Value to send through the channel

returns the channel object

ch: channel 1 , ch .Send 42 , ch .Read
; returns 42
ch: channel 3 , ch .Send "A" , ch .Send "B" , ch .Read
; returns "A"

Rye-channel//Close

Closes a channel, preventing further sends and causing pending/future reads to return an error.

Args: 1

channel Channel to close

returns the closed channel object

ch: channel 1 , ch .Send 42 , ch .Close , ch |type?
; returns native
ch: channel 1 , ch .Close , ch .Send 123 |disarm |type?
; returns error
ch: channel 2 , ch .Close , ch .Read |disarm |type?
; returns error

mutex

Creates a new mutex for synchronizing access to shared resources between goroutines.

(none)

returns a new mutex native object for synchronization

mutex |type?
; returns native
mtx: mutex , mtx .Lock , mtx .Unlock , mtx |type?
; returns native

waitgroup

Creates a new waitgroup for coordinating multiple goroutines to wait for completion.

(none)

returns a new waitgroup native object for coordinating goroutines

waitgroup |type?
; returns native
wg: waitgroup , wg .Add 1 , wg .Done , wg .Wait , wg |type?
; returns native

Rye-mutex//Lock

Acquires the lock on a mutex, blocking until the lock becomes available.

Args: 1

mutex Mutex to acquire the lock on

returns the mutex object

mtx: mutex , mtx .Lock , mtx |type?
; returns native
mtx: mutex , mtx .Lock , mtx .Unlock , mtx .Lock , mtx |type?
; returns native

Rye-mutex//Unlock

Releases the lock on a mutex, allowing other goroutines to acquire it.

Args: 1

mutex Mutex to release the lock from

returns the mutex object, or error if unlocking an unlocked mutex

mtx: mutex , mtx .Lock , mtx .Unlock , mtx |type?
; returns native
mtx: mutex , mtx .Unlock |disarm |type?
; returns error

Rye-waitgroup//Add

Adds the specified count to the waitgroup counter, indicating how many goroutines to wait for.

Args: 2

waitgroup Waitgroup to add goroutines to

count Number of goroutines to add to the wait counter

returns the waitgroup object

wg: waitgroup , wg .Add 3 , wg |type?
; returns native
wg: waitgroup , wg .Add 1 , wg .Add 2 , wg |type?
; returns native

Rye-waitgroup//Done

Decrements the waitgroup counter by one, indicating that a goroutine has completed.

Args: 1

waitgroup Waitgroup to decrement the counter for

returns the waitgroup object

wg: waitgroup , wg .Add 1 , wg .Done , wg |type?
; returns native
wg: waitgroup , wg .Add 2 , wg .Done , wg .Done , wg |type?
; returns native

Rye-waitgroup//Wait

Blocks until the waitgroup counter reaches zero, meaning all goroutines have completed.

Args: 1

waitgroup Waitgroup to wait on

returns the waitgroup object after all goroutines have completed

wg: waitgroup , wg .Add 1 , wg .Done , wg .Wait , wg |type?
; returns native
wg: waitgroup , wg .Wait , wg |type?
; returns native

select\fn

Performs a select operation on multiple channels, executing functions when channels are ready or a default function.

Args: 1

block Block containing channel-function pairs and optional default function

returns the original block argument

ch1: channel 1 , ch2: channel 1 , ch1 .Send 42 , select\fn { ch1 fn { v } { v } ch2 fn { v } { v + 1 } }
; returns 42
ch: channel 1 , select\fn { ch fn { v } { v * 2 } fn { } { 999 } }
; returns 999