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$
文档
请参阅许可证。