cosh
v0.3.0
COSH是一個串聯的命令行殼。
ls
, ps
, stat
等基本的外殼操作被用作返回一流值的函數,而不是依賴返回文本流的可執行文件。這使得與結果更加簡單:
查找與字符串匹配的文件路徑,然後搜索這些文件以獲取數據
sh | 尋找 。 -iname'*test*'-print0 | XARGS -0 GREP數據 |
Cosh | LSR; [測試M] GREP; [f <; [數據M] GREP]地圖 |
使用超過500m的內存查找所有過程:
sh | PS - 不輔助輔助|尷尬'$ 6> 500000' |
Cosh | PS; [mem get; 1000 1000 *; 500 *; >] GREP |
一小部分多功能原始圖是與典型的外殼相比,需要記住的較少(例如,請參見cut(1)
),儘管結果可能會更長:結果可能更長:
從CSV文件的每一行獲取第二和第三列:
sh | 剪切-d,-f2,3 test -data/csv |
Cosh | test-data/csv f <; [chomp; , 分裂; (1 2)獲取]地圖 |
通過修改時間對文件進行排序:
sh | LS -Tr |
Cosh | ls; [[Stat; MTIME GET] 2申請; <=>] sortp |
算術運算符和XML/JSON/YAML/CSV編碼/解碼功能減少了使用更完整的編程語言或第三方可執行執行的次數:
文件中的浮點數增加:
sh | SED'S/$/+10/'數字|公元前 |
Cosh | nums f <; [chomp; 10 +]地圖 |
從JSON文件的“ ZXCV”數組成員獲取第一個值:
sh | JQ .ZXCV [0] test-data/json2 |
Cosh | test-data/json2 f <;從傑森ZXCV GET; 0獲取 |
它還與需要的外部可執行電話集成在一起,這是必要的:
打印證書數據:
bash | 因為我在`找到。 -iname'*.pem'`; do openssl x509 -in $ i -text -noout;完畢 |
Cosh | LSR; [PEM $ M] GREP; [{openssl x509 -in {} -text -noout}] |
有關更多詳細信息,請參見完整的文檔。
這已經在Linux(Debian 12)上進行了測試,但應在可以構建生鏽的任何Linux/MacOS/BSD系統上工作。
make
make test
sudo make install
除了核心cosh
可執行文件外,這還將安裝編譯的核心功能庫( 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$
查找與給定的正則匹配的字段名稱:
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$
文件
請參閱許可證。