在unix shell中获得REPL的便利有什么途径? (或反之亦然)

发布于 2024-11-24 23:44:28 字数 469 浏览 5 评论 0原文

我使用很多命令通过子命令提供某种 API。例如,

git push
bzr push
apt-get install

过了一段时间,我厌倦了写git推送,git提交,git一些东西......因为我知道唯一的事情我现在使用的“提交”、“推送”等都是 git。

在使用过提供 REPL 的语言(Ruby、Python 等)之后,我失去了打字的便利性。

$ git pus...           ## arrgh!
$ from git import *
$ push                 ## yes!

我发现 git 之类的命令与预见的编程语言中的命名空间或模块之间存在明显的对称性。

那么,问题是:如何才能在 SHELL 中支持命名空间?反之亦然,如何才能让这些语言取代 SHELL?

I use a lot of commands providing exposing a sort of API via subcommands. For instance,

git push
bzr push
apt-get install

After a while, I get tired of writing git push, git commit, git something... because I know the only thing I'm using to 'commit', 'push', etc. is git at this moment.

Having played with languages providing a REPL (Ruby, Python, etc.) I was missing the convenience of typing.

$ git pus...           ## arrgh!
$ from git import *
$ push                 ## yes!

I see a clear symmetry between commands like git and namespaces or modules in the forementined programming languages.

So, the question is: what does it take to have support for namespaces in SHELL? or vice-versa, What does it take to have these language replace the SHELL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彼岸花似海 2024-12-01 23:44:28

一般来说,这很难做到。但是,您可以近似类似的东西...

#!/usr/bin/env bash

cmd="${1-echo}"

history -r
while read -p"$cmd\$ " -e -r -a input ; do
    history -s -- "${input[@]}"
    "$cmd" "${input[@]}"
done

使用命令名称调用,例如

./wrapper apt-get

现在,当您说例如 install foo 时,您实际上会执行 apt-get install foo

其他改进(例如更智能的选项卡完成)是可能的,但肯定需要特定于命令的代码。

This would be extremely hard to do generically. However, you can approximate something similar...

#!/usr/bin/env bash

cmd="${1-echo}"

history -r
while read -p"$cmd\$ " -e -r -a input ; do
    history -s -- "${input[@]}"
    "$cmd" "${input[@]}"
done

Invoke with the name of the command, e.g.

./wrapper apt-get

And now when you say e.g. install foo you will actually execute apt-get install foo.

Additional improvements, such as more intelligent tab completion, are possible but would certainly require command-specific code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文