Skip to content

Latest commit

 

History

History
865 lines (716 loc) · 29.7 KB

File metadata and controls

865 lines (716 loc) · 29.7 KB

xt – Complete Command Reference, Scripting Guide, and Architecture

xt is a zero-dependency, standalone native terminal and shell written in 100% pure Rust. It ships with a hardware-accelerated/software GDI graphical window, a multithreaded typed execution runtime, strict command isolation, an independent environment system, and a comprehensive suite of Unix primitives.


Table of Contents

  1. Architecture & Design Principles
  2. Window Controls & Display
  3. Command Isolation & Security Model
  4. Environment & Configuration (.xtrc)
  5. Complete Command Reference
  6. XT to SH Bridge (xtsh) & Bash Engine Reference
  7. Hardware & Architecture Diagnostics (xtenv)
  8. Scripting Language Reference
  9. Cross-Platform & Android Support

1. Architecture & Design Principles

  • Zero External Dependencies: xt has zero crate dependencies in Cargo.toml. Every subsystem—Win32 GUI, ClearType font rendering, ANSI parser, virtual screen, pipeline engine, SHA-256, MD5, Base64, Tar archive packer, and raw HTTP client—is implemented from scratch in pure Rust.
  • Multithreaded Runtime: Automatic thread pool sizing based on available CPU cores (std::thread::available_parallelism()). Background jobs, worker pipelines, and parallel command evaluations run concurrently.
  • Independent Execution Environment: Native host OS executables are strictly isolated from the bare shell prompt. Only builtins and binaries explicitly located in the .xtrc internal PATH can be executed bare.
  • DPI-Aware Typography: Per-Monitor DPI Awareness (V2) with ClearType natural subpixel anti-aliasing on Consolas typography ensures crisp, pixel-perfect text rendering at any display scaling (100%, 125%, 150%, 200%).

2. Window Controls & Display

Dynamic Font Scaling Shortcuts

Keybinding Action
Ctrl + + or Ctrl + = Increase font size by +2pt (up to 48pt)
Ctrl + - Decrease font size by -2pt (down to 10pt)
Ctrl + 0 Reset font size to default (18pt)

Navigation & Scrolling

Keybinding Action
Page Up / Page Down Scroll terminal viewport up or down by 5 lines
Mouse Wheel Scroll terminal viewport up or down smoothly
Ctrl + C Cancel current command input buffer
Ctrl + L Clear screen and redraw the cyan banner
Up / Down Arrow Navigate command history
Tab Inserts 4 spaces indentation (Autocomplete disabled for lean shell performance)

Prompt Design & Auto-Centering Viewport

  • Single-Line Prompt: Formatted as xt <path> $ <input>. CWD is displayed in yellow (with ~ shortening for home directory), prompt marker $ in bold green, and user input in white.
  • Auto-Centering on Input: If the user scrolls up into history and the prompt moves out of the viewport, typing any character or backspace immediately auto-scrolls the screen so the prompt is positioned vertically at the exact middle of the window.
  • Viewport Width Awareness & Dynamic Wrapping:
    • xt calculates the active viewport column width: max_cols = ((width - padding_x * 2) / char_width).max(10).
    • Both command output lines and prompt/input lines wrap automatically at max_cols so content never overflows past the window border.
    • The cursor coordinate is mapped in 2D (col = cursor_idx % max_cols, row = cursor_idx / max_cols), ensuring cursor rendering stays aligned with wrapped text.
    • COLUMNS and LINES environment variables are automatically kept in sync in runtime.env on every paint and resize.

3. Command Isolation & Security Model

xt enforces strict separation between internal shell execution and host operating system binaries:

3.1 Command Resolution Order

When any command name is executed bare:

PATH -> builtin -> not_found

When executed like xtsh ... (or within bash scripts):

PATH -> xtsh -> builtin -> not_found
  1. PATH (Highest Priority): Searched within directories configured in runtime.xt_path (from .xtrc or installed via xtpkg into ~/.xt/pkg/bin). Custom executables or package binaries take top precedence.
  2. builtin (Exported Builtins: xtsh exports + native builtins): When running bare, all 32 exported commands resolve directly as builtins:
    • Exported from xtsh (12): alias, cd, echo, exit, help, history, kill, printf, pwd, set, unalias, unset.
    • Native XT builtins (20): cat, clear, cp, env, head, ls, mkdir, mv, ps, rm, select, sleep, sort, syscmd, tail, touch, where, xtenv, xtpkg, xtsh.
  3. xtsh (Only active when executed like xtsh ...): Under xtsh ..., resolution follows PATH -> xtsh -> builtin. Commands strictly isolated to xtsh (e.g. dirs, caller, compgen, test, [, grep, sed, awk, cut, uniq, wc, tr, tee, chmod, ln, rmdir, du, df, base64, sha256, md5, uname) resolve via the xtsh engine.
  4. not_found: If not matched, returns xt: command not found: <name>. If <name> is an xtsh applet, provides a helpful guidance hint: (available in xtsh: 'xtsh <name>'). The host system's PATH variable is never checked for bare commands.

3.2 Help Command Output

Running help prints strictly:

  1. List of all xtsh applets
  2. List of exported (xtsh exports + builtins) ones And nothing else.

3.3 Direct Execution (No -c Required)

Both xt and xtsh support executing commands and scripts directly without requiring -c:

  • CLI Direct Execution:
    xt pwd
    xt echo hello world
    xt xtsh for x in 1 2 3; do echo $x; done
  • xtsh Direct Execution:
    xtsh pwd
    xtsh echo "hello"
    xtsh for x in 1 2 3; do echo $x; done
  • -c remains fully supported for backward compatibility (e.g., xt -c pwd, xtsh -c "echo hello").

3.4 Native Host OS Bridge (syscmd)

To invoke any host operating system executable or command-prompt utility, use the syscmd primitive:

syscmd ping 127.0.0.1
syscmd notepad file.txt
syscmd git status
syscmd dir

4. Environment & Configuration (.xtrc)

xt initializes its environment from .xtrc. It automatically searches:

  1. Current working directory (./.xtrc)
  2. User home directory (~/.xtrc or %USERPROFILE%\.xtrc)

If no .xtrc exists, xt generates a default file in the current directory.

Configuration Format

# Internal execution PATH (bracketed colon-separated paths)
PATH=</bin:/usr/bin:C:\xt\bin>

# Internal dynamic library search path
LD_PATH=</lib:/usr/lib:C:\xt\lib>

# Custom aliases
alias ll=ls
alias cls=clear

# Environment variables
EDITOR=xt
SHELL=xt
CUSTOM_VAR=value
  • PATH=<path1:path2:...>: Sets the isolated lookup directories for bare commands. Supports Unix format (</bin:/usr/bin>) and Windows format (<C:\xt\bin:D:\tools>).
  • LD_PATH=<path1:path2:...>: Configures LD_LIBRARY_PATH and library resolution for spawned processes.

5. Complete Command Reference

Host System Bridge (syscmd)

syscmd

Executes a native host operating system command using the host system's environment and PATH.

  • Usage: syscmd <command> [<args>...]
  • Examples:
    syscmd git clone https://github.com/example/repo
    syscmd cmd /c dir
    syscmd ping -n 3 127.0.0.1

Text & Stream Primitives

grep

Searches for patterns in input streams or files.

  • Usage: grep [-i] [-v] [-n] [-c] [-w] PATTERN [FILE...]
  • Options:
    • -i: Case-insensitive matching.
    • -v: Invert match (select non-matching lines).
    • -n: Prefix lines with 1-based line number.
    • -c: Output only the count of matching lines.
    • -w: Match whole words only.
  • Examples:
    cat src/main.rs | grep fn
    grep -i -n "error" log.txt
    ls | grep -v "\.tmp$"

sed

Stream editor for search and replace or line filtering.

  • Usage: sed 's/pattern/replacement/[g]' [FILE...]
  • Examples:
    echo "hello world" | sed s/world/xt/g
    cat file.txt | sed s/DEBUG/INFO/
    cat file.txt | sed /#comment/d

awk

Column extraction and formatted pattern scanning.

  • Usage: awk [-F delim] '{print $1, $2, ...}' [FILE...]
  • Options:
    • -F <delim>: Sets field separator (default: whitespace).
  • Examples:
    ps | awk '{print $1, $2}'
    echo "root:x:0:0" | awk -F : '{print $1, $3}'

cut

Extracts sections from lines of text.

  • Usage: cut -d DELIM -f FIELDS [FILE...] or cut -c CHARS [FILE...]
  • Options:
    • -d: Field delimiter (default: Tab).
    • -f: 1-based field indices or ranges (1,3, 1-4, 2-).
    • -c: 1-based character column ranges.
  • Examples:
    echo "a,b,c,d" | cut -d , -f 2,4
    cat /etc/passwd | cut -d : -f 1

uniq

Filters adjacent duplicate lines from input.

  • Usage: uniq [-c] [-d] [-u] [-i] [FILE]
  • Options:
    • -c: Prefix lines by the number of occurrences.
    • -d: Only print duplicate lines.
    • -u: Only print unique lines.
    • -i: Ignore case differences.
  • Examples:
    cat words.txt | sort | uniq -c

wc

Word, line, and byte count.

  • Usage: wc [-l] [-w] [-c] [-m] [FILE...]
  • Options:
    • -l: Count lines.
    • -w: Count words.
    • -c / -m: Count bytes/characters.
  • Examples:
    cat src/main.rs | wc -l
    wc -w document.txt

tr

Translates or deletes characters from stream input.

  • Usage: tr [-d] SET1 [SET2]
  • Options:
    • -d: Delete characters matching SET1.
  • Examples:
    echo "hello world" | tr a-z A-Z
    echo "abc 123" | tr -d "0-9"

diff

Compares two files line by line.

  • Usage: diff [-u] FILE1 FILE2
  • Options:
    • -u: Output in unified diff format.
  • Examples:
    diff -u old.txt new.txt

tee

Reads from stdin and writes simultaneously to stdout and files.

  • Usage: tee [-a] FILE...
  • Options:
    • -a: Append to files rather than overwriting.
  • Examples:
    echo "status check" | tee -a log.txt

Filesystem Primitives

ls

Lists directory contents with file metadata. Supports single and combined POSIX flags:

  • Usage: ls [-l] [-a] [-A] [-h] [-t] [-r] [-S] [-1] [-F] [-R] [-d] [PATH...]
  • Options:
    • -l: Long listing format displaying permissions (drwxr-xr-x, -rw-r--r--), hard links, owner user/group, size in bytes, modification date, and filename.
    • -a: Include hidden entries (. and .. and dotfiles).
    • -A: Almost all: include hidden files, but omit . and ...
    • -h: Human-readable file sizes (e.g. 4.2K, 12M, 1.5G).
    • -t: Sort by modification time (newest first).
    • -r: Reverse sorting order.
    • -S: Sort by file size (largest first).
    • -1: List one file per line.
    • -F: Append indicators (/ for directories, * for executables).
    • -R: List subdirectories recursively.
    • -d: List directory entries themselves, not their contents.
  • Examples:
    ls -la
    ls -lh /var/log
    ls -lrt src/

cd

Changes current working directory.

  • Usage: cd [-L] [-P] [PATH | -]
  • Behavior:
    • cd without arguments changes to home directory ($HOME or $USERPROFILE).
    • cd - switches back to the previous working directory ($OLDPWD) and prints the new directory path.
    • -P: Resolves symbolic links to physical directories.
    • Updates $PWD and $OLDPWD in the shell environment.

pwd

Prints current working directory path.

  • Usage: pwd [-L] [-P]

cat

Concatenates and displays file contents or stdin.

  • Usage: cat [-n] [-b] [-s] [-E] [-T] [-A] [FILE...]
  • Options:
    • -n: Number all output lines starting at 1.
    • -b: Number non-empty output lines only.
    • -s: Squeeze consecutive blank lines into a single blank line.
    • -E / -e: Display $ at the end of each line.
    • -T / -t: Display TAB characters as ^I.
    • -A / -v: Show all non-printing characters.
  • Examples:
    cat -n Cargo.toml
    cat file1.txt file2.txt > combined.txt
    cat < input.txt

head

Outputs the beginning of files or streams (default: first 10 lines).

  • Usage: head [-n COUNT] [-c BYTES] [-q] [-v] [FILE...]
  • Options:
    • -n <N> or -<N>: Print first N lines.
    • -c <N>: Print first N bytes.
    • -q: Never print headers giving file names.
    • -v: Always print headers giving file names.

tail

Outputs the end of files or streams (default: last 10 lines).

  • Usage: tail [-n COUNT] [-c BYTES] [-q] [-v] [FILE...]
  • Options:
    • -n <N> or -<N>: Print last N lines.
    • -c <N>: Print last N bytes.
    • -q: Suppress file header banners.
    • -v: Always display file header banners.

mkdir

Creates directories with optional parent creation.

  • Usage: mkdir [-p] [-v] [-m MODE] DIRECTORY...
  • Options:
    • -p: Make parent directories as needed without erroring if they exist.
    • -v: Verbose output printing each created directory.
    • -m: Set file mode (permissions).

rmdir

Removes empty directories.

  • Usage: rmdir [-p] [-v] DIRECTORY...

rm

Removes files or directories.

  • Usage: rm [-r|-R] [-f] [-v] [-d] PATH...
  • Options:
    • -r / -R: Remove directories and their contents recursively.
    • -f: Force removal; ignore nonexistent files without warning or error.
    • -v: Verbose output explaining what is being removed.
    • -d: Remove empty directories.

cp

Copies files or directories.

  • Usage: cp [-r|-R] [-f] [-v] [-p] [-u] SRC... DST
  • Options:
    • -r / -R: Copy directories recursively.
    • -f: Force overwrite of existing destination files.
    • -v: Verbose output showing each copied file.
    • -p: Preserve file timestamps.
    • -u: Update only: copy only when SRC is newer than DST or DST is missing.

mv

Moves or renames files or directories.

  • Usage: mv [-f] [-v] [-u] SRC... DST
  • Options:
    • -f: Do not prompt before overwriting.
    • -v: Verbose output showing move operations.
    • -u: Move only when source is newer than destination.

touch

Updates access and modification timestamps, or creates empty files if they do not exist.

  • Usage: touch [-a] [-m] [-c] FILE...

chmod

Changes file permissions.

  • Usage: chmod [-R] [-v] MODE FILE...
  • Options:
    • Octal modes (e.g. 755, 644) or symbolic modes (+r, -w, +x).

ln

Creates links between files.

  • Usage: ln [-s] [-f] [-v] TARGET LINK_NAME
  • Options:
    • -s: Create a symbolic link instead of a hard link.

du

Calculates disk usage for files and directory trees.

  • Usage: du [-h] [-s] [-a] [PATH...]
  • Options:
    • -h: Human-readable format (K, M, G).
    • -s: Display only a total summary for each argument.
    • -a: Show sizes for all files, not just directories.

df

Reports file system disk space usage and free capacity for all mounted drives.

  • Usage: df [-h]

Process Management & Diagnostics

ps

Lists active processes as structured objects with PID, Name, CPU, Memory, and Status.

  • Usage: ps
  • Output: Structured stream compatible with where, select, sort, first, and last.

kill

Terminates a process by numeric PID.

  • Usage: kill [-s SIGNAL] PID...

sleep

Suspends execution for specified duration.

  • Usage: sleep SECONDS

clear

Clears terminal screen buffer and restores cyan banner.

  • Usage: clear

Package Manager (xtpkg)

xt follows a lean architecture philosophy: the builtin list contains only the absolute minimal primitives a system needs to function, while xtpkg provides a native, built-in package manager to pull and install additional utilities (e.g. top, tar, curl, wget, custom scripts) strictly to ~/.xt/pkg.

~/.xt/pkg/bin is automatically prepended to the shell's internal execution PATH, making all installed packages immediately available as bare commands.

Directory Structure

  • ~/.xt/pkg/bin/: Installed executable binaries and wrappers.
  • ~/.xt/pkg/packages/: Package trees, custom scripts, and manifests.
  • ~/.xt/pkg/repos.txt: Configured repository URLs (default: official repository).
  • ~/.xt/pkg/installed.txt: Database of installed packages and versions.

Commands

xtpkg install <package | script>

Installs a package from configured repositories or directly from a local .xt / shell script.

xtpkg install top
xtpkg install tar
xtpkg install ./custom_tool.xt
xtpkg remove <package>

Uninstalls a package, removing its binary from bin/ and deregistering it.

xtpkg remove top
xtpkg list

Displays all currently installed packages, versions, and installation paths.

xtpkg list
xtpkg search [query]

Searches available packages in the repository catalog.

xtpkg search
xtpkg search curl
xtpkg update

Refreshes package indexes and manifests from all configured repositories.

xtpkg update
xtpkg upgrade [package]

Upgrades an individual package or all installed packages to their latest versions.

xtpkg upgrade
xtpkg upgrade top
xtpkg repo <add|list|remove> [url]

Manages upstream package repositories.

xtpkg repo list
xtpkg repo add https://raw.githubusercontent.com/xpert0/xt-packages/main/index.txt
xtpkg repo remove https://example.com/repo.txt

Data Encoding & Hashing

base64

Encodes or decodes Base64 data (RFC 4648) from stdin or files with zero external libraries.

  • Usage: base64 [-d|--decode] [FILE]
  • Examples:
    echo -n "secret" | base64
    echo -n "c2VjcmV0" | base64 -d

sha256 / sha256sum

Calculates FIPS 180-4 SHA-256 cryptographic checksums with zero external libraries.

  • Usage: sha256 [FILE...]

md5 / md5sum

Calculates RFC 1321 MD5 checksums with zero external libraries.

  • Usage: md5 [FILE...]

Shell Builtins

echo

Prints arguments to stdout with full escape sequence interpretation.

  • Usage: echo [-n] [-e] [-E] [ARGS...]
  • Options:
    • -n: Do not output trailing newline.
    • -e: Enable interpretation of backslash escape characters:
      • \n: Newline
      • \t: Horizontal tab
      • \r: Carriage return
      • \\: Backslash
      • \a: Alert (bell)
      • \b: Backspace
      • \f: Form feed
      • \v: Vertical tab
      • \e or \033: Escape character
      • \0NNN: Octal byte value
      • \xHH: Hexadecimal byte value
    • -E: Disable escape sequence interpretation (default).
  • Examples:
    echo -e "Line 1\tTabbed\nLine 2"
    echo -n "No trailing newline"

printf

Formatted printing supporting width modifiers and format specifiers.

  • Usage: printf FORMAT [ARGS...]
  • Specifiers:
    • %s: String
    • %d / %i: Signed decimal integer
    • %u: Unsigned decimal integer
    • %x / %X: Lowercase / Uppercase hexadecimal
    • %c: Character
    • %%: Literal %
    • Field width and left-alignment: %-15s, %10d
  • Examples:
    printf "User: %-10s ID: %05d\n" "admin" 42

test and [

Evaluates conditional expressions and returns standard POSIX exit status (0 for true, 1 for false).

  • Usage: test EXPRESSION or [ EXPRESSION ]
  • File Tests:
    • -e FILE: True if file/directory exists.
    • -f FILE: True if file exists and is a regular file.
    • -d FILE: True if path exists and is a directory.
    • -s FILE: True if file exists and has size greater than zero.
    • -r FILE: True if file exists and is readable.
    • -w FILE: True if file exists and is writable.
    • -x FILE: True if file exists and is executable.
    • -L / -h FILE: True if file exists and is a symbolic link.
  • String Tests:
    • -z STRING: True if string length is zero.
    • -n STRING: True if string length is non-zero.
    • STR1 = STR2 or STR1 == STR2: True if strings are equal.
    • STR1 != STR2: True if strings are not equal.
  • Numeric Tests:
    • N1 -eq N2: True if equal.
    • N1 -ne N2: True if not equal.
    • N1 -lt N2: True if N1 < N2.
    • N1 -le N2: True if N1 <= N2.
    • N1 -gt N2: True if N1 > N2.
    • N1 -ge N2: True if N1 >= N2.
  • Boolean Operators:
    • ! EXPR: Logical NOT.
    • EXPR1 -a EXPR2: Logical AND.
    • EXPR1 -o EXPR2: Logical OR.
  • Examples:
    [ -f Cargo.toml ] && echo "Found Cargo.toml"
    test $count -gt 10 && echo "High count"

true and false

Return exit status 0 (success) and 1 (failure) respectively.

  • Usage: true, false

export

Sets and exports environment variables to current session and child processes.

  • Usage: export [NAME[=VALUE]...] or export -p
  • Examples:
    export MY_FLAG=1
    export PATH
    export -p

read

Reads a line from standard input into shell variables.

  • Usage: read [-r] [-p PROMPT] [VARIABLE...]
  • Options:
    • -r: Raw input without interpreting backslash escapes.
    • -p <PROMPT>: Print prompt string without trailing newline before reading.
  • Examples:
    read -p "Enter your name: " name

type

Displays information about a command type (builtin, alias, or external binary).

  • Usage: type [-t] [-a] NAME...

which

Locates an executable in internal PATH.

  • Usage: which [-a] NAME...

env

Displays or modifies the runtime environment.

  • Usage: env [-i] [-u NAME] [NAME=VALUE...] [COMMAND [ARGS...]]

set / unset

Lists or removes shell environment variables.

  • Usage: set, unset VARIABLE...

alias / unalias

Defines, lists, or removes command aliases.

  • Usage: alias [NAME=VALUE], unalias NAME

history

Displays numbered command history.

  • Usage: history [-c]

exit

Terminates the terminal session with optional exit code.

  • Usage: exit [CODE]

6. XT to SH Bridge (xtsh) & Bash Engine Reference

xtsh ("XT to SH Bridge") is the dedicated gateway between XT and standard UNIX/POSIX shells. While XT maintains a lean built-in command set for core terminal operations, xtsh provides complete POSIX compatibility, all 61 standard GNU/Bash builtins, and a portable bash script parser/runner.

6.1 Invocation Syntax

xtsh runs commands and scripts directly without requiring -c:

# Execute any UNIX/POSIX builtin directly
xtsh <builtin_or_cmd> [arguments...]

# Execute arbitrary bash commands directly (no -c needed)
xtsh echo hello world
xtsh for x in 1 2 3; do echo $x; done
xtsh [ -f Cargo.toml ]

# Execute a bash script file (.sh or .bash)
xtsh script.sh [arg1 arg2...]

# Backwards compatibility: -c is accepted
xtsh -c "<commands>"

# Show xtsh interactive help
xtsh help

6.2 All 61 Bash Builtins Supported in xtsh

xtsh implements every single builtin found in standard bash (cross-checked against bash.txt):

Category Builtins Description
Control & Flow :, true, false, break, continue, return, exit, logout Status returns, loop control, and session termination
Scripts & Execution ., source, eval, exec, builtin, command, caller Script sourcing, dynamic evaluation, execution bypass, stack introspection
Testing & Evaluation [, test, let Conditional expressions (files, strings, arithmetic) and arithmetic evaluation
Environment & Variables export, declare, typeset, local, readonly, set, unset, shift Variable attributes, scoping, array/read-only definitions, positional shifting
I/O & Reading echo, printf, read, readarray, mapfile Formatted output and stream line parsing into variables/arrays
Directory Stack pwd, cd, pushd, popd, dirs Directory navigation and stack manipulation
Job & Process Control jobs, fg, bg, disown, kill, wait, suspend, times Background process management and timing statistics
Alias & Shell Options alias, unalias, shopt, enable, hash Alias mapping, shell option toggles, command hash table management
Completion & Keybinding compgen, complete, compopt, bind Programmable completion queries and editing bindings
Signals & Limits trap, ulimit, umask Signal handling, system resource limits, and file creation masks
History & Interactive history, fc, getopts, help History listing, command editing, argument flag parsing, help lookup

6.3 POSIX Utilities Bridged in xtsh

The following core POSIX utilities can be invoked directly through xtsh:

  • File Utilities: xtsh ls, xtsh cat, xtsh head, xtsh tail, xtsh touch, xtsh cp, xtsh mv, xtsh rm, xtsh mkdir, xtsh rmdir, xtsh chmod, xtsh ln, xtsh du, xtsh df
  • Text Processing: xtsh grep, xtsh sed, xtsh awk, xtsh cut, xtsh uniq, xtsh wc, xtsh tr, xtsh tee
  • Encoding & Hashes: xtsh base64, xtsh sha256, xtsh sha256sum, xtsh md5, xtsh md5sum

6.4 Portable Bash Scripting Engine

xtsh executes standard .sh bash scripts without requiring an external bash interpreter or WSL.

Supported Bash Constructs:

  1. Shebang & Comments: #!/bin/bash, #!/bin/sh, # comment line
  2. Variable Expansions: $VAR, ${VAR}, ${VAR:-default}, ${VAR:=default}
  3. Positional Parameters: $0, $1..$9, $# (count), $@ and $* (all args), $? (exit code), $$ (PID)
  4. Command Substitution: $(command) and `command`
  5. Control Flow:
    • if [ condition ]; then ... elif [ condition ]; then ... else ... fi
    • for var in item1 item2 ...; do ... done
    • while [ condition ]; do ... done
    • until [ condition ]; do ... done
    • Supports both multi-line formatting and single-line syntax (; do ...; done, ; then ...; fi)
  6. User Functions & Scoping:
    my_func() {
        local LOCAL_VAR="$1"
        echo "Processing $LOCAL_VAR"
    }
    my_func "argument"
  7. Pipes & I/O Redirections: | (stream piping), > (truncate write), >> (append), 2> (stderr), < (input from file)
  8. Chaining: && (execute on success), || (execute on failure), ; (sequential execution)

7. Hardware & Architecture Diagnostics (xtenv)

xtenv is a built-in platform introspection command that outputs a single delimited system signature string:

$ xtenv
windows x86_64 8/16

Format: "platform arch physical/logical"

  • platform: Operating system platform (windows, linux, macos, android)
  • arch: Processor architecture (x86_64, aarch64, arm, x86)
  • physical: Physical CPU cores (e.g. 8)
  • logical: Logical execution cores / threads (e.g. 16)

7.1 Scripting with xtenv

Portable cross-platform script example:

# Query the platform signature string:
SIG=$(xtenv)
echo "System Signature: $SIG"

# Split platform details in a portable script:
read -r PLATFORM ARCH CORES <<< $(xtenv)
echo "Platform: $PLATFORM, Architecture: $ARCH, Cores (phys/log): $CORES"

8. Scripting Language Reference

xt includes a full imperative scripting language with first-class variables, expressions, conditionals, loops, and functions.

Variables & Expressions

let greeting = "Hello"
let port = 8080
let is_active = true
let full_msg = $greeting + " from xt!"

Conditionals

let count = 5
if $count > 0 {
    echo "Positive count"
} else {
    echo "Non-positive"
}

Loops

# For loop over list
for item in ["apple", "banana", "cherry"] {
    echo "Item: " + $item
}

# While loop
let i = 0
while $i < 3 {
    echo "Iteration " + $i
    let i = $i + 1
}

User-Defined Functions

fn greet(user) {
    echo "Welcome, " + $user
    return true
}

greet("developer")

Redirection & Chaining

# Standard output redirection
echo "log entry" > output.txt

# Append redirection
echo "another entry" >> output.txt

# Standard error redirection
syscmd unknown 2> error.log

# Standard input redirection
cat < input.txt

# Pipeline chaining
cat access.log | grep 404 | cut -d " " -f 1 | sort | uniq -c

# Conditional execution (AND / OR)
[ -f Cargo.toml ] && echo "Cargo.toml exists"
[ -d build ] || mkdir -p build

# Command sequential execution
echo "step 1"; echo "step 2"

9. Cross-Platform & Android Support

xt runs identically across Windows, Linux, macOS, and Android:

Windows

  • Standalone Win32 native window using Direct ClearType GDI rendering.
  • Dark mode native title bar integration (DwmSetWindowAttribute).
  • Full DPI awareness with dynamic scaling.

Linux / macOS

  • Native terminal rendering with high-speed ANSI virtual screen buffer.
  • Linux /proc process metrics and macOS sysctl integrations.

Android

  • Located in the android/ directory:
    • Standalone Android App (in.xpert0.xt): Termux-style interface with accessory key bar (ESC, TAB, CTRL, ALT, -, /, |, ~, ↑, ↓), monospace typography, and exact cyan banner.
    • JNI Native Bridge: Connects UI directly to libxt.so.
    • Termux CLI Binary: Compiles via cargo build --target aarch64-linux-android --release for direct execution inside Termux terminal environments.