cosh is a concatenative command-line shell.
Basic shell operations like ls
, ps
, stat
, and so on are
implemented as functions that return first-class values, as opposed to
relying on executables that return text streams. This makes working
with the results simpler:
-
Find files matching a path, and search them for data:
- sh:
find . -iname '*test*' -print0 | xargs -0 grep data
- cosh:
lsr; [test m] grep; [f<; [data m] grep] map
- sh:
-
Find the total size of all files in the current directory:
- sh:
ls | xargs stat -c %s | awk '{s+=$1} END {print s}' -
- cosh:
ls; [is-dir; not] grep; [stat; size get] map; sum
- sh:
A small set of versatile primitives means that less needs to be
remembered when compared with typical shells (see e.g. the various
flags for cut(1)
), though some commands may be longer as a result:
-
Get the second and third columns from each row of a CSV file:
- sh:
cut -d, -f2,3 test-data/csv
- cosh:
test-data/csv f<; [chomp; , split; (1 2) get] map
- sh:
-
Sort files by modification time:
- sh:
ls -tr
- cosh:
ls; [[stat; mtime get] 2 apply; <=>] sortp
- sh:
Arithmetical operators and XML/JSON/CSV encoding/decoding functions reduce the number of times that it becomes necessary to use a more full-featured programming language or a third-party executable:
-
Increment floating-point numbers in file:
- sh:
sed 's/$/+10/' nums | bc
- cosh:
nums f<; [chomp; 10 +] map;
- sh:
-
Get the first value from the "zxcv" array member of a JSON file:
- sh:
jq .zxcv[0] test-data/json2
- cosh:
test-data/json2 f<; from-json; zxcv get; 0 get
- sh:
It also integrates with external executable calls, where that is necessary:
- Print certificate data:
- bash:
for i in `find . -iname '*.pem'`; do openssl x509 -in $i -text -noout; done
- cosh:
lsr; [pem$ m] grep; [{openssl x509 -in {} -text -noout}] map;
- bash:
This has been tested on Linux (Debian 12), but should work on any Linux/macOS/BSD system where Rust can be built.
make
make test
sudo make install
Apart from the core cosh
executable, this will also install a
compiled library of core functions (rt.chc
).
user@host:/$ cosh
/$ hello println;
hello
See LICENCE.