问HN:可扩展的Shell命令?
我经常遇到这样的情况:在终端中启动一个长时间运行的进程,然后想要进行一些后续操作,这时再在命令行末尾添加 `&& foo || bar` 就太晚了。
简单的例子:下载这个 Linux ISO……哦,还要把它写入我的 USB 驱动器……哦,还要检查一下 shasum……哦,完成后要显示一个通知。
然后,下次我想要稍微变动一下更复杂的操作时,每次我都在权衡第一个进程的运行时间与输入或修改第二部分所需的时间。
我可以打开一个单独的终端,启动第二个进程,等待第一个进程完成,但这样做的开销通常不值得。
所以我希望能有一个“可链式的终端”或“动态提示”,在这个环境中,我可以在最后一个命令仍在前台运行时,输入接下来的命令。根据程序的不同,我注意到这在某种程度上已经可以实现,当一个阻塞进程完成后,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 process 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?