crys
crys
A Crystal one-liner tool.
It does four things only.
- decide how input is iterated
- decide what each record sees
- decide what to require
- decide how output is emitted
It does not add dependency management or a custom DSL. It is a thin wrapper around plain Crystal code.
Installation
Build:
shards build
Binary:
bin/crys
Move it somewhere on your PATH if needed.
Usage
Basic form:
crys [options] 'CRYSTAL_CODE' [file ...]
Process stdin line by line:
printf 'a\nb\n' | crys -n 'puts line.upcase'
Assign the result back to line and print it:
printf 'a\nb\n' | crys -p 'line.upcase'
Auto-split input:
printf 'a:b\nc:d\n' | crys -a -F: 'puts f[1]'
Slurp all input:
printf '{"a":1}' | crys -r json -g 'puts JSON.parse(input)["a"].as_i'
Run setup and teardown code:
printf '1\n2\n3\n' | crys --init 'sum = 0' -n 'sum += line.to_i' --final 'puts sum'
Edit files in place:
crys -pi.bak 'line.gsub("foo", "bar")' file.txt
crys -i 'line.upcase' file.txt
Inspect generated code:
crys --dump -p 'line.upcase'
Options
-n: read input line by line. Exposeslineandnr-p: same as-n, but assigns the body result back tolineand prints it-a: auto-splitlineintof-F SEP: field separator for-a-g,--slurp: read all input intoinput-i[SUFFIX]: edit files in place.-i.bakcreates backups-r LIB: addrequire "LIB". Repeatable--init CODE: insert code before the main body or loop--final CODE: insert code after the main body or loop--dump: print the generated Crystal code and exit-O LEVEL: build with optimization level (0,1,2,3,s,z)--release: build withcrystal build --release--error-trace: build withcrystal build --error-trace-h,--help: show help
Implicit variables:
line: current line, always chompedf: split fields, only with-anr: record numberinput: full slurped input, only with-gor--slurppath: current file path when reading files or editing in place
Generated programs are cached under CRYS_HOME/cache and reused when the generated code and Crystal flags are unchanged.
Constraints:
-g/--slurpcannot be combined with-n/-p-irequires at least one file
Development
Run unit tests:
crystal spec
Run integration tests:
bash spec/integration_test.sh
Build locally:
crystal build src/main.cr -o bin/crys
Repository
crys
Owner
Statistic
- 0
- 0
- 2
- 0
- 0
- about 3 hours ago
- March 29, 2026
License
MIT License
Links
Synced at
Sun, 29 Mar 2026 08:17:53 GMT
Languages