Ask HN: 可扩展的 Shell 命令?
1 分•作者: baobun•18 天前
我经常发现自己处于这样的情况:我在 shell 中启动一个长时间运行的进程,然后想在它之后做一些事情,但此时再在命令行的末尾添加 `&& foo || bar` 就为时已晚了。
简单例子:下载这个 Linux ISO... 哦,然后把它刷到我的 USB 驱动器上... 哦,然后检查 shasum... 哦,完成后显示通知。
然后,下次我想对某些更复杂的东西进行稍微的修改时,我每次都要权衡第一个进程的运行时间与输入或修改第二部分的时间。
我可以打开一个单独的 shell 并生成一个等待第一个进程完成的第二个进程,但这样做很少值得付出开销。
所以,我想要的是一个“可链式 shell”或“活提示符”,我可以在最后一个 shell 命令已经在前台运行的情况下,输入接下来要做的任何事情。根据程序的不同,我注意到这种方式已经有点作用了,bash 实际上会在阻塞进程的输出中间运行我输入的任何内容,一旦它完成。但仅适用于某些程序。
受到 https://news.ycombinator.com/item?id=46231293 的启发——从 stdout/stderr 管道输出会非常酷,但我们在这里只需要退出代码。
感觉这击中了我们大多数人,并且应该可以在 bash/zsh 中实现一些东西。但我从未见过任何类似的东西。
有人已经编写或找到了类似的东西,他们想分享吗?
查看原文
I often find myself in the situation where I fire off a long-running process in the shell and then want to do something as a follow-up, at which point it is too late to add that '&& foo || bar' at the end of the line.<p>Simple example: Download this Linux ISO.. Oh, and flash it to my USB drive... Oh, and check the shasum... Oh, and show a notification when done.<p>Then the next time I want a slight variation of something more complex, every time I'm weighing the running time of the first process vs the time to type out or modify the second part.<p>I could open a separate shell and spawn a second process waiting for the first to finish but rarely worth the overhead of doing that.<p>So what I'd like is a "chainable shell" or "living prompt", where I can type out whatever comes next as the last shell command is already and still running in the foreground. Depending on the program, I noticed this kind-of already works where bash will actually go ahead and run whatever I type in the middle of the output of a blocking proces once it's finished. But only for some programs.<p>Prompted by https://news.ycombinator.com/item?id=46231293 - piping from stdout/stderr would be extra cool but we only really need the exit code here.<p>Feels like something that hits most of us and should be possible to make something in bash/zsh for. Yet I've never seen anything for this.<p>Anyone hacked together or found something like this that they use and would like to share?