#plugin #nu #diagnostics #stdio #tracing #shell

app trace_nu_plugin

Nu插件的包装器

2 个版本

0.3.1 2024年5月2日
0.3.0 2024年5月1日

9#nu

每月 29 次下载

MIT/Apache

9KB
113 代码行

trace_nu_plugin

这是一个用于Nu插件的诊断包装器,它将原始插件的stdin和stdout输出到用户家目录中的文件。

这可能只对使用除Rust之外的语言编写插件的开发者有用。

需要Nu的新插件API >= 0.93

使用方法

使用跟踪器作为shell解释器添加插件,使用插件跟踪器和实际插件的完整路径。

> plugin add -s ~/vc/sjg/dev.rust/trace_nu_plugin/target/debug/trace_nu_plugin ~/vc/tesujimath/nu_plugin_bash_env/nu_plugin_bash_env
> plugin use bash_env

输出将出现在以插件命名的文件中,位于用户家目录。

警告:跟踪输出将累积,直到带有跟踪包装器的插件被安装。可能会产生大文件。确保在完成跟踪后使用plugin rm删除插件,并重新安装而不带跟踪包装器。

然后

> cd ~/junk

> echo "export A=123" | bash-env
╭───┬─────╮
│ A │ 123 │
╰───┴─────╯

> cat ~/vc/tesujimath/nu_plugin_bash_env/nu_plugin_bash_env.in.raw
{"Hello":{"protocol":"nu-plugin","version":"0.92.3","features":[{"name":"LocalSocket"}]}}
{"Call":[0,"Signature"]}
"Goodbye"
{"Hello":{"protocol":"nu-plugin","version":"0.92.3","features":[{"name":"LocalSocket"}]}}
{"Call":[0,{"Run":{"name":"bash-env","call":{"head":{"start":131720,"end":131728},"positional":[],"named":[]},"input":{"Value":{"String":{"val":"export A=123","span":{"start":131703,"end":131717}}}}}}]}
"Goodbye"

> cat ~/vc/tesujimath/nu_plugin_bash_env/nu_plugin_bash_env.out.raw
json{"Hello":{"protocol":"nu-plugin","version":"0.92.0","features":[]}}
{"CallResponse":[0,{"Signature":[{"sig":{"name":"bash-env","usage":"get environment variables from Bash format file and/or stdin","extra_usage":"","search_terms":[],"required_positional":[],"optional_positional":[{"name":"path","desc":"path to environment file","shape":"String","var_id":null,"default_value":null}],"rest_positional":null,"named":[{"long":"help","short":"h","arg":null,"required":false,"desc":"Display the help message for this command","var_id":null,"default_value":null}],"input_output_types":[["Nothing","Any"],["String","Any"]],"allow_variants_without_examples":true,"is_filter":true,"creates_scope":false,"allows_unknown_args":false,"category":"Env"},"examples":[]}]}]}
json{"Hello":{"protocol":"nu-plugin","version":"0.92.0","features":[]}}
{"CallResponse":[0,{"PipelineData":{"Value":{"Record":{"val":{"A":{"String":{"val":"123","span":{"start":0,"end":0}}}},"span":{"start":0,"end":0}}}}}]}

注意在字符串“json”每次出现之前都有一个不可见的004字符。

> od -c nu_plugin_bash_env.out.raw | head -1
0000000 004   j   s   o   n   {   "   H   e   l   l   o   "   :   {   "
```

依赖关系

~3–11MB
~111K SLoC