hosh-shell.github.io

Hosh

Features

Hosh is an experimental shell, featuring:

¹ it is not intended to conform to IEEE POSIX P1003.2/ISO 9945.2 Shell and Tools standard

² much more design and work is needed in this area

Downloads

Binary releases:

Getting started

Requirements: JDK17+

$ java -jar hosh-0.2.0.jar
hosh> echo "hello world!"
hello world!
hosh>

Examples

Sorting

Sorting is always performed using a well-defined key:

hosh> ls
# unsorted, following local file-system order
...
hosh> ls | schema
path size
hosh> ls | sort size
# files sorted by size
...
hosh> ls | sort path
# files sorted by alphanum algorithm
...

Find top-n files by size

Walk is able to recursively walk a directory and its subdirectories, providing file name and size:

hosh> walk . | schema
path size
...

By sorting the output of walk it is trivial to detect the biggest files:

hosh> walk . | sort size desc | take 5
aaa 2,5MB
bbb 1MB
ccc 1MB
ddd 1MB
eee 1MB

HTTP

Stream line by line a TSV file via HTTPS, take first 10 lines, split each line by tab yielding a 1-indexed record and finally show a subset of keys.

Bash + wget + awk:

bash$ wget -q -O - -- https://git.io/v9MjZ | head -n 10 | awk -v OFS='\t' '{print $10, $1, $12}'

Hosh (no external commands):

hosh> http https://git.io/v9MjZ | take 10 | split text '\\t' | select 10 1 12

Glob expansion and lambda blocks

To recursively remove all .class files in target:

hosh> walk target/ | glob '*.class' | { path -> rm ${path}; echo removed ${path} }

{ path -> ... } is lambda syntax, inside this scope is possible to use ${path}.

Parsing

It is possible to create records by using regex built-in with capturing groups:

hosh> git config -l | schema
text
...
hosh> git config -l | regex text '(?<key>.+)=(?<value>.+)' | take 2
key                value
credential.helper  osxkeychain
user.name          Davide Angelocola
hosh> hosh> git config -l | regex text '(?<key>.+)=(?<value>.+)' | take 2 | schema
key value
key value

Inspired by

And some nice UI features from:

License

MIT License

Sponsors

JetBrains YourKit SonarCloud