Implementation of Unix tools in OCaml a fun project to learn some functional programming principles. The project focuses on:
- functional architecture,
- lazy stream processing,
- composable pipelines,
- custom parsers and evaluators,
- some GADT
- grep
- sed
- git
- find
- pipeline
grep:
grep PATTERN – wypisuje linie pasujące do wzorca.
grep -v PATTERN – wypisuje linie niepasujące.
sed:
sed s PATTERN REPL – zamienia wszystkie linie pasujące do wzorca na REPL.
sed d PATTERN – usuwa linie pasujące do wzorca.
sed i PATTERN REPL – wstawia linię REPL po każdej linii pasującej do wzorca.
find:
Name "filename" – szuka plików o danej nazwie.
SizeGt N – pliki większe niż N bajtów.
SizeLt N – pliki mniejsze niż N bajtów.
Kombinacje logiczne: And, Or, Not.
git:
init – tworzy nowe repozytorium .mini_git.
add FILE1 FILE2 ... – dodaje pliki do staging.
commit "MESSAGE" – tworzy commit ze staging.
branch NAME – tworzy nową gałąź.
checkout NAME – przełącza bieżącą gałąź.
status – pokazuje aktualną gałąź i pliki w staging.
show ID – pokazuje nazwy plików w commit o danym ID.
examples:
grep echo -e "a\nb\naa\nabc" | dune exec -- ./src/cli/grep_cli.exe -- "a"
grep -v echo -e "a\nb\naa\nabc" | dune exec -- ./src/cli/grep_cli.exe -- "a" -v
sed substitute echo -e "a\nb\naa\nabc" | dune exec ./src/cli/sed_cli.exe a s X
sed delete echo -e "a\nb\naa\nabc" | dune exec ./src/cli/sed_cli.exe a d
sed insert echo -e "a\nb\naa\nabc" | dune exec ./src/cli/sed_cli.exe a i INSERTED
dune exec -- ./src/cli/find_cli.exe ./src/core/find "eval.ml"
echo -e "abc\ndef\nabcd\nxyz" | dune exec -- ./src/cli/pipeline_cli.exe -- "grep:a|sed:s:a:X|grep_not:d"
run mini-git: ./_build/default/src/cli/git_cli.exe
inside CLI:
init
add file1.txt file2.txt
commit "Initial commit"
branch feature
checkout feature
status
show 1
exit
run tests: ./test_all.sh