Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Builtins Overview

AetherShell provides a rich set of built-in commands that return structured data for pipeline processing.

Core Philosophy

Unlike traditional shells where commands return text, AetherShell builtins return typed Value objects:

# Traditional shell: ls returns text
# AetherShell: ls returns Array[Record]

ls "."
# Returns: [
#   { name: "file.txt", size: 1234, modified: "2024-01-01T12:00:00Z", is_dir: false },
#   { name: "src", size: 4096, modified: "2024-01-01T10:00:00Z", is_dir: true },
#   ...
# ]

This enables powerful pipeline operations:

ls "."
  | where(fn(f) => f.size > 1000)
  | sort_by("modified", "desc")
  | take(5)
  | select("name", "size")

Categories

File System

CommandDescriptionReturns
ls pathList directoryArray[Record]
cat fileRead file contentsString
read fileRead file (alias)String
write file contentWrite to fileBool
mkdir pathCreate directoryBool
rm pathRemove file/dirBool
mv src dstMove/renameBool
cp src dstCopyBool
pwdCurrent directoryString
cd pathChange directory()

Data Processing

CommandDescriptionReturns
map(fn)Transform each elementArray
filter(fn)Keep matching elementsArray
reduce(fn, init)Fold to single valueAny
sort_by(field, dir)Sort by fieldArray
where(fn)Filter (alias)Array
select(fields...)Pick fieldsArray[Record]
take(n)First n elementsArray
skip(n)Skip n elementsArray
flatten()Flatten nested arraysArray
unique()Remove duplicatesArray
group_by(field)Group by fieldRecord

Text Processing

CommandDescriptionReturns
grep pattern pathSearch in filesArray[Record]
split str delimSplit stringArray[String]
join arr delimJoin to stringString
trim strRemove whitespaceString
replace old new strReplace textString
uppercase strTo uppercaseString
lowercase strTo lowercaseString

Network

CommandDescriptionReturns
http_get urlGET requestRecord
http_post url bodyPOST requestRecord
http_put url bodyPUT requestRecord
http_delete urlDELETE requestRecord

JSON/Data

CommandDescriptionReturns
json_parse strParse JSONAny
json_stringify valSerialize to JSONString
csv_parse strParse CSVArray[Array]
csv_stringify dataSerialize to CSVString

System

CommandDescriptionReturns
envAll env varsRecord
env_get nameGet env varString?
env_set name valSet env var()
exec cmd argsRun commandRecord
which nameFind executableString?
psProcess listArray[Record]

Math

CommandDescriptionReturns
sum arrSum of numbersNumber
avg arrAverageFloat
min arrMinimumNumber
max arrMaximumNumber
abs nAbsolute valueNumber
floor nFloorInt
ceil nCeilingInt
round nRoundInt
sqrt nSquare rootFloat

Type Conversion

CommandDescriptionReturns
int valConvert to intInt
float valConvert to floatFloat
string valConvert to stringString
bool valConvert to boolBool
array valConvert to arrayArray

Output

CommandDescriptionReturns
print valPrint value()
println valPrint with newline()
debug valDebug output()
format str args...Format stringString

AI

CommandDescriptionReturns
ai prompt opts?AI queryString
agent prompt opts?Create agentAgent

Return Value Structure

File System Records

# ls returns:
{
    name: String,      # File name
    path: String,      # Full path
    size: Int,         # Size in bytes
    modified: String,  # ISO timestamp
    is_dir: Bool,      # Is directory
    is_file: Bool,     # Is file
    extension: String, # File extension
    permissions: String # Unix permissions
}

HTTP Response

# http_get/post returns:
{
    status: Int,       # HTTP status code
    headers: Record,   # Response headers
    body: String,      # Response body
    ok: Bool          # status >= 200 && status < 300
}

Grep Match

# grep returns:
{
    file: String,      # File path
    line: Int,         # Line number
    content: String,   # Matching line
    match: String      # Matched text
}

Pipeline Examples

# Find large Rust files
ls "src"
  | where(fn(f) => f.extension == "rs" && f.size > 10000)
  | sort_by("size", "desc")
  | select("name", "size")

# API data processing
http_get("https://api.example.com/users")
  | json_parse()
  | where(fn(u) => u.active)
  | map(fn(u) => { name: u.name, email: u.email })
  | take(10)

# Log analysis
cat("app.log")
  | split("\n")
  | where(fn(line) => line.contains("ERROR"))
  | map(fn(line) => {
      let parts = split(line, " ")
      { timestamp: parts[0], message: join(skip(parts, 2), " ") }
  })