COSHは連結コマンドラインシェルです。
ls
、 ps
、 stat
などの基本的なシェル操作は、テキストストリームを返す実行可能ファイルに依存するのではなく、ファーストクラスの値を返す関数として実装されます。これにより、結果の作業がより簡単になります。
文字列に一致するファイルパスを見つけ、それらのファイルをデータの検索
sh | 探す 。 -iname '*test*' -print0 | Xargs -0 GREPデータ |
コス | LSR; [テストM] grep; [f <; [データM] Grep]マップ |
500mを超えるメモリを使用してすべてのプロセスを見つけます。
sh | ps -no-headers aux | awk '$ 6> 500000' |
コス | PS; [MEM GET; 1000 1000 *; 500 *; >]グレップ |
汎用性の高いプリミティブの小さなセットは、典型的なシェルと比較した場合、覚えておく必要がないことを意味します(たとえば、 cut(1)
のさまざまなフラグを参照)。
CSVファイルの各行から2番目と3番目の列を取得します。
sh | Cut -D、-F2,3 Test -Data/CSV |
コス | test-data/csv f <; [chomp; 、 スプリット; (1 2)取得]マップ |
変更時間ごとにファイルを並べ替えます:
sh | LS -TR |
コス | ls; [[stat; mtime get] 2適用; <=>] SORTP |
算術演算子とXML/JSON/YAML/CSVエンコード/デコード関数は、よりフル機能のプログラミング言語またはサードパーティの実行可能ファイルを使用する必要がある回数を減らします。
ファイル内の浮動小数点数を増やす:
sh | SED 'S/$/+10/' nums |紀元前 |
コス | nums f <; [chomp; 10 +]マップ |
JSONファイルの「ZXCV」アレイメンバーから最初の値を取得します。
sh | jq .zxcv [0] test-data/json2 |
コス | test-data/json2 f <; jsonから; zxcv get; 0 get |
また、外部実行可能な呼び出しと統合されます。
印刷証明書データ:
バッシュ | 私のために `find。 -iname '*.pem'`; opensSl x509 -in $ i -text -noout;終わり |
コス | LSR; [pem $ m] grep; [{opensSl x509 -in {} -text -noout}] Map; |
詳細については、完全なドキュメントをご覧ください。
これはLinux(Debian 12)でテストされていますが、錆を構築できるLinux/macos/BSDシステムで動作するはずです。
make
make test
sudo make install
Core cosh
実行可能ファイルとは別に、これはCore関数のコンパイルされたライブラリ( rt.chc
)もインストールします。
user@host:/$ cosh
/$ hello println;
hello
各例は、リポジトリクローンディレクトリから始まります。
指定されたディレクトリにファイルをリストします。
cosh$ test-data ls
v[gen (
0: test-data/cert.der
1: test-data/json-bigint
2: test-data/json2
3: test-data/json1
4: test-data/readfile
5: test-data/yaml1.yml
6: test-data/test.ch
7: test-data/csv
8: test-data/split
9: test-data/readlines
)]
cosh$
指定されたディレクトリでファイルをアルファベット順にソートします。
cosh$ test-data ls; sort
(
0: test-data/cert.der
1: test-data/csv
2: test-data/json-bigint
3: test-data/json1
4: test-data/json2
5: test-data/readfile
6: test-data/readlines
7: test-data/split
8: test-data/test.ch
9: test-data/yaml1.yml
)
cosh$
外部コマンドは、スペースを使用してコマンドをプレフィックスすることで実行できます。
cosh$ vim test-data/csv
...
ファイルをメモリに読む:
cosh$ test-data/csv f<;
v[gen (
0: "1,2,3,4n"
1: "5,6,7,8n"
2: "9,10,11,12n"
)]
cosh$
CSVファイルの各行について、Newlineを削除してコンマで分割します。
cosh$ test-data/csv f<; [chomp; , split] map;
v[gen (
0: (
0: 1
1: 2
2: 3
3: 4
)
1: (
0: 5
1: 6
2: 7
3: 8
)
2: (
0: 9
1: 10
2: 11
3: 12
)
)]
cosh$
JSONファイルをメモリに読みます:
cosh$ test-data/json2 f<; from-json;
h(
"asdf": 1
"qwer": 2
"tyui": h(
"asdf": 5
)
"zxcv": (
0: 3
1: 4
)
)
cosh$
JSONファイルからフィールド名を取得し、標準の出力に印刷します。
cosh$ test-data/json2 f<; from-json; keys; println for;
asdf
qwer
tyui
zxcv
cosh$
与えられたregexに一致するフィールド名を見つけます:
cosh$ test-data/json2 f<; from-json; keys; [.{4} m] grep;
v[gen (
0: asdf
1: qwer
2: tyui
3: zxcv
)]
cosh$
cosh$ test-data/json2 f<; from-json; keys; [a..f m] grep;
v[gen (
0: asdf
)]
cosh$
新しい関数を定義して使用します。
cosh$ : add-5 5 +; ,,
cosh$ (1 2 3) add-5 map;
(
0: 6
1: 7
2: 8
)
cosh$
正規表現を使用して値をキャプチャします:
cosh$ test-data ls;
v[gen (
0: test-data/json-bigint
1: test-data/json2
2: test-data/json1
3: test-data/readfile
4: test-data/csv
5: test-data/split
)]
cosh$ test-data ls; ["/.*" c; shift] map;
v[gen (
0: /json-bigint
1: /json2
2: /json1
3: /readfile
4: /csv
5: /split
)]
cosh$
特定の形式でパスの変更時間を印刷します。
cosh$ test-data stat; mtime get; from-epoch; %F strftime;
2023-01-20
cosh$
一連のドメイン名のping時間を並行して見つけます。
cosh$ (sourcehut.org github.com gitlab.com) [dup; A dig; answer.0.sdata.address get; 1 pingn; 0 get; 2 mlist] pmap;
v[channel-gen (
0: (
0: gitlab.com
1: h(
"icmp_seq": 1
"ttl": 58
"time_ms": 11.6
)
)
1: (
0: github.com
1: h(
"icmp_seq": 1
"ttl": 115
"time_ms": 28.4
)
)
2: (
0: sourcehut.org
1: h(
"icmp_seq": 1
"ttl": 52
"time_ms": 346
)
)
)]
cosh$
一連のIPアドレス範囲でホストの総数を取得します。
cosh$ (1.0.0.0/24 2.0.0.0/14 3.0.0.0/8) [ip; ip.size] map; sum
17039616
cosh$
新しいSQLiteデータベースを作成し、データベースにテーブルを追加し、テーブルにレコードを追加します。
cosh$ mydb touch
cosh$ mydb sqlite db.conn; c var; c !
cosh$ c @; "create table test (id, num)" db.prep; () db.exec
()
cosh$ c @; "insert into test values (?, ?)" db.prep; (1 2) db.exec
()
cosh$ c @; "select * from test" db.prep; () db.exec
(
0: h(
"id": 1
"num": 2
)
)
cosh$
ドキュメント
ライセンスを参照してください。