←  cshw: The C Shell for Windows

Appendix A

The cshw Cheat Sheet

The one-page reference for the things you'll reach for daily. Keep this open in a tab.


Daily-Driver Commands

Command What it does
ls -la / dir List files (long, with hidden)
cd PATH Change directory; cd - flips back; cd alone → home
pushd PATH / popd Push/pop directory stack
grep -n "pat" FILE Search text; -i case, -r recursive, -v invert
find PAT [dir] [/s] Find files by glob pattern; /s recurses
cat FILE / type FILE Display file
head -n N / tail -n N First/last N lines
history [N] Recall past commands; up-arrow walks back
set var = value Set shell variable
set var = `cmd` Capture command output (backtick substitution)
setenv VAR value Set environment variable
source FILE Load script in current shell
fetch URL HTTP GET; -o file, -I headers, -X POST -d data
genai ask "prompt" Ask the AI

Variables

Form Meaning
$var Variable value
${var} Same, with explicit boundaries
`cmd` Command substitution (capture output)
$? Exit status of last command
$result Result of last command that sets it
$1, $2, ... Positional args inside a procedure
$argc, $argv Argument count and list
$coid ID of last-launched coroutine
$genai_result Last genai response

Operators

Operator Meaning
== != Equal / not equal — compares text (5 == 05 is false)
< <= > >= Comparison — compares numbers (5 < 10 is true)
num @ str Cast an operand: read the comparison as numbers / as text
&& || Logical and/or
! Logical not
+ - * / % Arithmetic
-f / -d / -e File exists / is directory / exists
if ( $month == "01" )        # text:    "1" vs "01"  -> false
if ( num $month == "01" )    # numbers:  1  vs  1    -> true
if ( str "10" < str "9" )    # text ordering         -> true

Arithmetic happens inside @ var = EXPR:

@ x = 5 + 3 * 2
@ count = $count + 1

Control Flow

if (COND) then              while (COND) then           foreach v (LIST)
    ...                          ...                         ...
else if (COND) then         end                         end
    ...
else                        do                          loop N
    ...                          ...                         ...
endif                       while (COND)                endloop

                            switch ($var)
                                case "a":  ... breaksw
                                case "b":  ... breaksw
                                default:   ...
                            endsw

break exits a loop. continue skips to next iteration. return [N] exits a procedure.


Pipes and Redirection

Syntax Meaning
cmd1 | cmd2 Pipe stdout of cmd1 to stdin of cmd2
cmd > file Redirect stdout to file (overwrite)
cmd >> file Append to file
cmd < file Read stdin from file
cmd 2> file Redirect stderr to file
cmd 2>> file Append stderr to file
cmd 2>&1 Merge stderr into stdout
cmd > file 2>&1 Both to one file
cmd >& file Both to one file (csh spelling)
cmd >>& file Both appended to one file (csh spelling)
cmd1 |& cmd2 Pipe BOTH streams to cmd2 (csh spelling)
cmd & Run in background (job)

All of these mean the same thing inside a pipeline as outside one.


Glob Patterns

Pattern Matches
* Any string (except /)
? Single character
[abc] Any one of a, b, c
[a-z] Any in range

Quote a pattern ("*.txt") to pass it literally without expansion. cshw uses Win32 FindFirstFile glob semantics — no recursive ** or brace {a,b} alternation; use a command's /s flag for recursion.


Procedures

proc NAME
    # $1, $2, ... are arguments
    # $argc / $argv for full list
    set result = "value"      # becomes $result for caller
    return 0
endproc

NAME arg1 arg2 arg3

Arrays and Hashes

declare -a colors                      # array
array push colors "red"
echo $colors[1]                        # access by index (1-based)
echo $#colors                          # length
foreach c ($colors)
    echo $c
end

declare -A config                      # hash
hash set config name "MyApp"
echo $config[name]                     # access by key
foreach k (`hash keys config`)
    hash get config $k
    echo "$k = $result"
end

Coroutines and Sync

corunproc PROC arg1 arg2     # launch as coroutine; $coid = id
cowait $coid                 # wait for one
cowait /all                  # wait for all running
cowait /any                  # return when any finishes
cowait /timeout:5000 $coid   # wait up to 5s
coresult $coid               # retrieve result into $result
cocancel $coid               # cancel one (or /all)
share name = value           # write through to main's globals
                              # (dash forms `-all`, `-timeout 5000` also accepted)

mutex NAME lock/unlock/trylock
event NAME create/signal/reset/wait/destroy
semcreate NAME INITIAL [MAX] # MAX defaults to INITIAL if omitted
semaphore NAME acquire/release
barrier NAME create COUNT / wait
chancreate NAME [CAPACITY]
channel NAME send/receive/tryreceive/close

coset NAME VALUE             # atomic write
coget NAME                   # atomic read → $result
coincr NAME [BY]             # atomic ++ (returns OLD)
codecr NAME [BY]             # atomic --
cocas NAME EXPECTED NEW      # compare-and-swap

Networking

fetch URL                                # HTTP GET to stdout
fetch -o FILE URL                        # save to file
fetch -I URL                             # headers only
fetch -X POST -d "DATA" URL              # POST
ftpfetch ftp://host/path                 # FTP transfer

tcpclient host port /send:"X" /recv      # one-shot TCP
tcpserver port HANDLER_PROC              # TCP server

socket create tcp NAME                   # create socket
socket bind NAME port                    # bind to port
socket listen NAME                       # listen
socket accept NAME                       # accept → $result
socket connect NAME host port            # connect
socket send/recv/close NAME [DATA]       # I/O

Server Daemons

tsrvd start PORT HANDLER                  # relay server (script handler)
tsrvd start PORT /dll:smtp.dll /dllcfg:F  # native protocol plugin
tsrvd status/stop ID                      # manage ($result = ID from start)
tsrvd list                                # ID PORT PID STATE RST
tsrvd recv/send/close CONN                # I/O inside a /stream handler
quicsrv start PORT /dllcfg:F              # QUIC/HTTP-3 server (UDP), same config
quicsrv status/stop ID  ;  quicsrv list  # manage QUIC workers
set mail = (SECS PATH ...)                # watch Maildir mailboxes
checkmail                                 # force a mail check now

Bundled plugins: smtp.dll, pop3.dll, imap.dll (mail over a shared Maildir), ftp.dll, http.dll (HTTP/1.1 + HTTP/2, static files + CGI). HTTP/3 is served by the quicsrv worker over QUIC/UDP, through the same static + CGI engine.


AI Integration

genai register NAME TYPE KEY [-m MODEL]  # register provider
                                          # TYPE: openai|anthropic|azure|
                                          #       ollama|lmstudio|custom
genai list / default / test / models     # manage providers
genai ask "prompt"                       # query (accepts pipes)
genai ask -t 0.2 --max-tokens 200 "..."  # with options
genai analyze FILE "prompt"              # analyze a file
genai code -l LANG "prompt"              # code generation
genai settings stream on                 # toggle streaming
echo "..." | genai ask "..."             # pipe input as context
                                          # response in $genai_result

Windows API

rundllproc DLL FUNCTION arg1 arg2 ...    # call a Win32 API
rundllproc --ret:bool user32.dll IsWindow p:0x10010
winapi MessageBox 0 "Hi" "Title" 0       # auto-resolve DLL
dllimport DLL [ALIAS]                    # preload
dlllist / dllunload                      # manage

# Arg type prefixes:
#  i:N    signed int       s:STR  wide string
#  u:N    unsigned         a:STR  ANSI string
#  p:HEX  raw pointer      null   NULL
#  b:0|1  bool             obufw:N  N-wide-char output buffer
#  obufa:N  ANSI buffer    obuf:N   raw N-byte buffer (hex-dumped)
#  obufd:V  in/out DWORD initialized to V
#  obufq:V  in/out QWORD initialized to V

Plugins

rcl PATH [PREFIX] [/prefixonly]    # load plugin DLL
rcl PATH PREFIX -- ARGS...         # pass extra args to plugin's InitializeLibrary
urcl NAME                          # unload plugin (or /all)
cmdliblist [/v]                    # list loaded command libraries

(library is a different command — it loads .cshw script files, not plugin DLLs.)


Job Control

cmd &           # background
jobs            # list jobs
fg %N           # bring to foreground
bg %N           # resume in background
stop %N         # suspend a job
kill %N         # terminate
wait            # wait for all running coroutines (alias for `cowait /all`)
notify on/off   # async completion notifications

Prompt Customization (prompt)

Code Inserts
$P Current working directory
$N Current drive letter
$G >
$L <
$B |
$A &
$Q =
$F )
$C (
$S A space
$T Current time (with seconds and ms)
$D Current date
$V cshw version
$W Windows version
$J The literal string CSHW
$_ Newline (for multi-line prompts)
$H Backspace
$E Escape character (for ANSI sequences)
$$ Literal $

Example: prompt "$J $P $G " → CSHW C:\Projects >


File Locations

Path Contents
~/.cshrc / %APPDATA%\cshw\cshwrc Per-user startup script (aliases, procedures, prompt)
settings.csh (in %APPDATA%\cshw\) Declarative settings; cascades settings.csh → HKCU → HKLM → defaults
%APPDATA%\cshw\ Per-user config (genai providers, history, etc.)
cshw.ini (next to cshw.exe) System-wide config; [CommandLibraries] section for plugin preload

Exit-Status Conventions

$? is set by every command. By convention:

Value Meaning
0 Success
1 General failure
2 Misuse (bad arguments)
124 Timeout (from timeout command)
127 Command not found
Other Command-specific (see man page)

That's the cheat sheet. For the complete catalog of every command in cshw, see Appendix B.