TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How should the CLI be designed today?

85 点作者 danfrost将近 9 年前
I&#x27;ve long thought that the command line is just a bit rubbish, even if it is powerful.<p>If you were redesigning it today (2016), how would you lay it out and what it do?<p>E.g. collapse output. Keep more metadata on history. Built in error hints (e.g. google the error, harvest possibilities).<p>How should the CLI work across microservices and cloud services?<p>What should the graphical design be?<p>This is deliberately open. Looking for pet hates and ideas.

35 条评论

Udo将近 9 年前
My primary complaint about Unix CLI is that the commands try to do two disparate things simultaneously: outputting text for humans and generating data for consumption by other commands. In a properly designed command line ecosystem (it&#x27;s far, far too late for that now), there would be good human readable output in one mode, and tools would exchange structured, already escaped data amongst themselves in another mode. Alternatively, the <i>shell</i> would render the output for humans, and tools would just communicate in machine format.<p>Consider for example executing a compression command on all jpg files in a folder and below. Currently, the syntax goes something like this:<p><pre><code> find . -iname &quot;*jpg&quot; -exec gfxcompress {} \; </code></pre> Naive Unix users would have expected this to be achievable by piping, but no! In reality there is a special syntax of the <i>find</i> command that does this, and it&#x27;s not completely clear how you would deal with file names further down the line, or how you would achieve further chaining. This syntax is also completely unique to the find command. You can&#x27;t just plug in another data source and perform the same operation. In a CLI where tools are <i>designed</i> to be chained, it would look something like this:<p><pre><code> find | match :name=&quot;*jpg&quot; |&gt; gfxcompress :name </code></pre> In this example I used an imaginary |&gt; operator to indicate I want something performed on every item, and I can refer to the &quot;name&quot; field of each directory entry directly. If I wanted to filter by time, for example, I might use the :time field instead, without any need for explicit support. If I wanted to mutate the name somewhere in the chain, I could do it. If I wanted to chain additional commands, it would be obvious how. And it would just work.<p>The same goes for error handling. Imagine a compiler spitting out structured error information which you could use directly in other tools without having to parse and interpret it first.
评论 #12107785 未加载
评论 #12107797 未加载
评论 #12107776 未加载
评论 #12110089 未加载
评论 #12110179 未加载
viraptor将近 9 年前
I&#x27;d basically like to have powershell. Potentially with a better introspection and attributes so that you can build a more interactive CLI. For example output size estimation + tagging local read-only commands to allow showing some output preview as you combine the commands. On-a-side display of help for arguments.<p>My pet hate is that commands themselves cannot tell you things about them in a structured way. There&#x27;s no reason why completion and --help are somehow separate from the execution itself.<p>Love: context aware shell like zsh&#x2F;oh-my-zsh provide. If I&#x27;m in a git project, show me a good git summary for example. If I&#x27;m in python venv, tell me about it. If I&#x27;m in some python project, extract its name from setup.py.
J_Darnley将近 9 年前
People say Windows&#x27; Powershell using some sort of objects rather than a text stream is good.<p>For me I want better control over how my shell records and stores history. I want it to record more and probably not in a flat text file. I don&#x27;t want it to write commands that fail to disk but I do want them in my history so I can correct my typo and run again.<p>I&#x27;d like lines to be rewrapped if I change terminal dimensions. I&#x27;d like more automatic pagination (rather than forgetting to use less and nuking your scrollback). I think is an issue with mintty&#x2F;putty but I&#x27;d like its command history to be printed correctly after changing the terminal width.<p>Pet hates: terminal bells that I didn&#x27;t explicitly ask for; middle click paste; the obscure terminfo file that sometimes controls the features a program uses.
评论 #12107771 未加载
gue5t将近 9 年前
Don&#x27;t google errors. Don&#x27;t network anything that isn&#x27;t explicitly requested to be networked. Don&#x27;t give any built-in affordances for HTTP or other poorly-designed, politically-imposed protocols. I don&#x27;t even know what you&#x27;re talking about with microservices, as that notion only makes sense in the context of implementation details of RPC services (&quot;Cloud APIs&quot; in 2016 parlance).<p>A modern shell would:<p>- Never use text as the interchange format, but rather keep binary representations in memory and link all commands in a given interaction into a single computation, doing inlining and optimization across the boundaries of what are currently separate processes communicating via pipes&#x2F;IPC.<p>- Know about the structure of valid invocations of commands (essentially, their type signature and the algebraic type structure of their parameters), preventing any &quot;invalid invocation&quot; error messages a priori. Only valid options would be permissible for tab-completion, and un-tab-completable options would give error feedback directly without executing the program.<p>- Have a principled, data-race-free alternative to the filesystem for persistent storage of data, which maintains type information without preventing useful generic operations like bytewise encryption.<p>- Support unicode as the only character set for text.<p>- Encourage proportional fonts, so as to make box-drawing characters not work properly. An associated UI system would permits applications to refer neither to character cells nor pixels, but only to a graph of modifiable or immutable values and a set of presentation hints. Platform-specific modules would interpret these based on the capabilities of the local terminal. Full graphical applications over SSH are trivial under this model--no more &quot;I use a shitty 1980&#x27;s-era UI because that&#x27;s the only thing I can export across the network consistently&quot;.<p>- Allow addressing both local and remote system resources (RAM, CPUs, I&#x2F;O devices) via a uniform interface, and allow dynamically attaching and detaching these from running processes, both local and remote.<p>- From a more traditional shell perspective, it seems important to support &quot;by&quot; operations with good ergonomics. This is stuff like &quot;sort all these files <i>based on the output of applying this other file-accepting command to each</i>&quot; or &quot;filter out all paragraphs in a text file containing the string &#x27;foo&#x27;, but only print the last seven characters of each one.&quot;.<p>These would be a start.
jhallenworld将近 9 年前
History should be recorded in non-volatile storage immediately, not just on clean exits (can do this in bash, but it needs to be the default).<p>You should be able to step though history for just arguments (can be done in bash, but needs to be easier).<p>Take a look at TOPS-20: it had &quot;question-mark help&quot;- any time you hit ?, it told you what the next argument is for.<p>The terminal emulator should have inline graphical output- it should not be text only. Someone should define a protocol so that you can have full graphical programs running in the terminal emulator. When you exit the program, the last view remains in the scroll-back history.<p>Some plan9 things are good: network access should be in the filesystem so that you don&#x27;t need special programs like wget: cp &#x2F;net&#x2F;www.google.com&#x2F;http&#x2F;index.html foo<p>Same with local I&#x2F;O: parameters for opening a serial port should be part of the filename when you open, something like: cp foo &#x2F;dev&#x2F;ttyS0:9600n81<p>The filesystem should be extended to also be a database. SQL is ugly, but some kind of relational algebra query language should be built in:<p><pre><code> cat &#x2F;mydatabase&#x2F;name=&quot;joe&quot; is like &#x27;select * from mydatabase where name=&quot;joe&quot;&#x27;</code></pre>
评论 #12110495 未加载
bizzleDawg将近 9 年前
As an aside, in terms of design and little helpers (e.g. git&#x2F;virtualenv) powerline shell really made my terminal much more friendly: <a href="https:&#x2F;&#x2F;github.com&#x2F;banga&#x2F;powerline-shell" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;banga&#x2F;powerline-shell</a><p>Idea: proper graphics for data&#x2F;image&#x2F;video display.<p>I think it&#x27;s an interesting idea that a terminal editor can have text only input, but the ability to draw real high-res graphical output. e.g. a canvas to draw your matplotlib diagram in the terminal output or a more graphical version of htop (with time data graphs etc).
评论 #12107590 未加载
saynsedit将近 9 年前
Would love something that showed you how the current command was going to be parsed as an argument vector before actually submitting the command (pressing return). Would help with spacing and quoting.
seanp2k2将近 9 年前
Do this: <a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;prep&#x2F;standards&#x2F;html_node&#x2F;Command_002dLine-Interfaces.html" rel="nofollow">https:&#x2F;&#x2F;www.gnu.org&#x2F;prep&#x2F;standards&#x2F;html_node&#x2F;Command_002dLin...</a><p>And this: <a href="http:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;basedefs&#x2F;V1_chap12.html" rel="nofollow">http:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;basedefs&#x2F;V1_...</a>
random_upvoter将近 9 年前
In TCC&#x2F;LE (a CMD replacement for Windows by JPSoft) there is one little feature that I miss in Powershell because I got so used to it: if you just enter the name of a folder (as if it&#x27;s a command), you change dir to that folder (so no need to type the &#x27;cd&#x27;).<p>In Powershell you just get an error that this thing is not executable. A waste of semantic space, IMO.
nextweek2将近 9 年前
My biggest pet hate is the single tasking. Which is more to the nature of scripting languages. It would be great to have an event command queue.<p>&lt;rant&gt; Each time I do a npm, apt-get, brew command it irks me that all the downloads happen then they unpack, then they process. Where really it should be put on an event command queue. That way downloads can continue whilst processing is happening.<p>I have the same bug bear about the GUI, if I want to transcode a set of videos and move them to a NAS it&#x27;s a linear process. I keep promising myself I should write a small app to get it done properly. I just wish the operating system was a little better at it. The main pain point is that if I send 10 files to my NAS it will transfer them all at the same time and take forever because of the seek time. What OS&#x27;s should be doing is queuing up these things to make the transfer quicker. &lt;&#x2F;rant&gt;
评论 #12110952 未加载
alexkehayias将近 9 年前
Easier inline editing of command args i.e accidentally executing the script when trying to enter a newline.
评论 #12107926 未加载
woodruffw将近 9 年前
Hyperlinking is good, we should do more of that.<p>I have my urxvt configured to open http(s) URLs in my browser, but it would be nice if I could open URLs of arbitrary protocols via handlers. Similarly, being able to distinguish valid pathnames and open them in $EDITOR&#x2F;$VISUAL (or perhaps via special file-type handlers) would be a nice.<p>Overall, I&#x27;m not particularly dissatisfied with the state of the command line in 2016. My experience has been that I make no more (or fewer) mistakes with command-line interfaces than I do with graphical ones, and that spending a few seconds thinking about what I actually want to do prevents me from using the wrong approach (i.e., a graphical or console program) to a problem.
0x37将近 9 年前
If we could start with having working ctrl-c ctrl-v that would be great :). (I know Windows improved on this with 10 but Linux is still lacking)<p>Other than that I wouldn&#x27;t mind some graphical features, such as being able to display thumbnails of images for example.
评论 #12107732 未加载
评论 #12107710 未加载
评论 #12107789 未加载
评论 #12109906 未加载
评论 #12107919 未加载
评论 #12107744 未加载
评论 #12107735 未加载
majkinetor将近 9 年前
It should look exactly like Powershell. Its simply a space ship compared to any other shell.<p>Since it is comming to Linux you should start learning it now IMO.<p>Xiki also had promiss. Unfortunatelly, it doesnt look like it will become mainstream.
dlitz将近 9 年前
I&#x27;d like to see a good CLI design involving sandboxing-by-default, and handling object-capabilities (e.g. file descriptors) as first-class objects.<p>Right now, &quot;convert a.jpg b.png&quot; passes the strings &quot;a.jpg&quot; and &quot;b.png&quot; to ImageMagick&#x27;s convert command, but that command is free to open whatever files it wants, since there&#x27;s no distinction between strings vs resources such as filenames, network sockets, etc.<p>You can do this with pipes in simple cases, and bash has some support for this, but it&#x27;s very primitive and the syntax is cumbersome.
ubuntourist将近 9 年前
Although, through a long career, I&#x27;ve become accustomed to a wide variety of CLIs, I tend to agree: We&#x27;ve moved beyond 1999 a bit. The fact that a lot of these systems have legacy and tradition isn&#x27;t sufficient. Languages like COBOL also have a long history. But now we have lots of other languages to choose from.<p>First off, as much as possible, I&#x27;d eliminate non-words. I tutor a lot and people think perhaps I have a speech impediment the first time I say &quot;grep&quot;. (Yes, I know, it&#x27;s not technically part of the shell. But okay how about &quot;fi&quot; and &quot;esac&quot;? Really? Why not &quot;enod&quot; then?)<p>I&#x27;d take command completion further: IDEs often have drop-downs and function signature descriptions as you move along coding. In a hypertext world with tooltips, etc, I think there&#x27;s be a lot of room for those types of ideas.<p>I do think the philosophy of &quot;do one thing and one thing only, but do it well&quot; is a good one. Piping stuff together is wonderful. I wonder if it would make sense and be shorter to explain in plain English, if the &quot;water flowed the other way&quot; instead. For example:<p>&quot;sort the output of the find result&quot; = sort | find<p>as opposed to:<p>&quot;take the output of find and sort it&quot; = find | sort<p>(That last bit was just a random thought of the moment, just trying to think a wee bit outside of the box.)
评论 #12109333 未加载
kranner将近 9 年前
I&#x27;d like to leave this cautionary tale against getting too clever from the Jargon File:<p>Warren Teitelman originally wrote DWIM to fix his typos and spelling errors, so it was somewhat idiosyncratic to his style, and would often make hash of anyone else&#x27;s typos if they were stylistically different. Some victims of DWIM thus claimed that the acronym stood for ‘Damn Warren’s Infernal Machine!&#x27;.<p>In one notorious incident, Warren added a DWIM feature to the command interpreter used at Xerox PARC. One day another hacker there typed delete <i>$ to free up some disk space. (The editor there named backup files by appending $ to the original file name, so he was trying to delete any backup files left over from old editing sessions.) It happened that there weren&#x27;t any editor backup files, so DWIM helpfully reported </i>$ not found, assuming you meant &#x27;delete <i>&#x27;. It then started to delete all the files on the disk! The hacker managed to stop it with a Vulcan nerve pinch after only a half dozen or so files were lost.<p>The disgruntled victim later said he had been sorely tempted to go to Warren&#x27;s office, tie Warren down in his chair in front of his workstation, and then type delete </i>$ twice.
tedmiston将近 9 年前
Autocomplete globally for every command and its subcommands
评论 #12107813 未加载
myroon5将近 9 年前
Default support for control-f searching output
评论 #12107651 未加载
评论 #12107721 未加载
josh-wrale将近 9 年前
I&#x27;ve tried using Elixir&#x27;s iex as a login shell. It was an interesting experience. The pipelining in Elixir actually makes it feel a lot like bash. In Elixir, remote shell [1], autocomplete are built in. Strings are binary. Structs help structure output for human vs machine use (e.g. see HTTPoison.get(&quot;<a href="http:&#x2F;&#x2F;example.org&quot;" rel="nofollow">http:&#x2F;&#x2F;example.org&quot;</a>) vs. HTTPoison.get!(&quot;<a href="http:&#x2F;&#x2F;example.org&quot;" rel="nofollow">http:&#x2F;&#x2F;example.org&quot;</a>). Processes are cheap. Functions are compostable. Rock on!<p><a href="http:&#x2F;&#x2F;elixir-lang.org&#x2F;docs&#x2F;stable&#x2F;iex&#x2F;IEx.html#module-remote-shells" rel="nofollow">http:&#x2F;&#x2F;elixir-lang.org&#x2F;docs&#x2F;stable&#x2F;iex&#x2F;IEx.html#module-remot...</a>
modeless将近 9 年前
A standard method for programs to provide help, examples, and tab completion suggestions to the shell. Right now we have man, info, --help, -help, -?, etc, and tab completion is part of the shell rather than the apps. If all of that was standardized the tools could be much better.
lsiebert将近 9 年前
You should have a separate output for humans, instead of having a flag for it, and programs which are the last in a chained series should default to it, but you could also redirect stuff to it in the middle of piping.<p>I&#x27;d love if the bash shell language was less clunky.
jonsg将近 9 年前
A good CLI has to satisfy a number of conditions, IMHO:<p>* Human-friendly interaction:<p>-- Command completion<p>-- Help for all commands<p>-- Doesn&#x27;t need a load of APL-like runes in order to achieve anything<p>-- Intuitively obvious, so far as possible<p>-- Low bar for entry<p>* Not too verbose (something that requires the equivalent of COBOL&#x27;s &quot;ADD A TO B GIVING C&quot; ain&#x27;t gonna roll, sorry!)<p>* Sensible and consistent<p>* Embeds a full programming language - but you don&#x27;t need that language to run straightforward commands<p>* Completely embraces parallelism without pain<p>-- Including being able to spin off and manage daemon processes<p>-- And having a painless way of managing (plumbing, in other words) inputs and outputs of each stage - {Uni,Linu}x shells haven&#x27;t really improved the way they do this in over thirty years, and they didn&#x27;t get it right the first time!<p>* As much as possible of the operating system&#x27;s capability should be exposed, to as deep a level as possible, through the CLI<p>* Not tied to one operating system - inherently capable of being applied to any (or at least any common one)<p>My preference would be that the CLI presents a genuinely object-oriented representation of data and the programs that know how to interpret the data, plus the operating system services as well.<p>Microsoft&#x27;s PowerShell satisfies a lot of these requirements...however, it falls way short of the &quot;Low bar for entry&quot; criterion, as anyone who&#x27;s tried to learn it casually will have discovered the hard way.<p>A Pythonic shell could also be made to work (yes, I&#x27;ve tried using Python as a shell. No, it didn&#x27;t go well), but would require a bit of nurdling to bring it into compliance with most of the requirements above, particularly the human interface ones.<p>A lot of questions here - a lot fewer answers, but I thought I&#x27;d throw out these thoughts for the assembled masses to contemplate, be inspired by, or tear to pieces.
abbasaamer将近 9 年前
It&#x27;d have the features of fish shell (<a href="https:&#x2F;&#x2F;fishshell.com" rel="nofollow">https:&#x2F;&#x2F;fishshell.com</a>) and would be able to pipe structured objects between programs like Windows Power Shell.
y1426i将近 9 年前
I find CLI a great interface. Its just stuck in pre web days! Here are some thoughts on its design &#x2F; UX -<p>- contextual help. if i write a command incorrect, it should suggest correction and link to more help.<p>- cloud storage of all my command history<p>- be more understanding. talk a bit in natural language. Eg. show my ip address -&gt; translated to the right shell command.<p>- learn and grow automatically as the community builds more tools. Like, hey used this command but check this one out!<p>It is not feasible to upgrade all existing scripts to adhere to this but a wrapper shell that can provide this functionality should be very well possible.
55555将近 9 年前
Please build me an app that lets me search &quot;prebuilt commands&quot; from the command line itself. I am always opening Chrome to google &quot;how to grep recursively only files of a certain type to find phone numbers&quot;... why can&#x27;t i just search that from the command line itself and then select from the outputted suggestions?<p>Other than that, some random ideas..:<p>Probable command completion.<p>Possible arguments should be displayed as I type.<p>Syntax highlighting and beautiful margins&#x2F;padding<p>Collapsible threads
xwvvvvwx将近 9 年前
Black Screen has some pretty interesting ideas:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;shockone&#x2F;black-screen" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;shockone&#x2F;black-screen</a>
评论 #12109936 未加载
z1mm32m4n将近 9 年前
If you have a little sense of humor, Gary Bernhardt spoke at length about what effect a better terminal environment could have on things like terminal based editors:<p><a href="https:&#x2F;&#x2F;www.destroyallsoftware.com&#x2F;talks&#x2F;a-whole-new-world" rel="nofollow">https:&#x2F;&#x2F;www.destroyallsoftware.com&#x2F;talks&#x2F;a-whole-new-world</a>
flukus将近 9 年前
I&#x27;d add an easy way for cli apps to expose bindings to be used from other apps. Working in a higher level language and having to rely on executing&#x2F;parsing cli programs isn&#x27;t pleasant.
softEngg将近 9 年前
Plan9?
评论 #12110099 未加载
hellcat84将近 9 年前
<p><pre><code> int main(int argl, byte* argb) </code></pre> For having just a byte* stream, not claiming this is a char, when I just have a byte of a char, and without terminating NUL character.
Koshkin将近 9 年前
Looks like IPython Notebook is almost an ideal way to interact with a computer (as an information processing device, rather than, for example, a game machine).
评论 #12107882 未加载
vasili111将近 9 年前
It should understand human language. Not commands, functions and etc, just plain human language.
评论 #12112114 未加载
joelthelion将近 9 年前
It should have a daemon to centralize things such as command history across multiple terminals.
joelthelion将近 9 年前
A modern protocol to communicate with the terminal would be nice.