Ask HN: How should the CLI be designed today?
I've long thought that the command line is just a bit rubbish, even if it is powerful.
If you were redesigning it today (2016), how would you lay it out and what it do?
E.g. collapse output. Keep more metadata on history. Built in error hints (e.g. google the error, harvest possibilities).
How should the CLI work across microservices and cloud services?
What should the graphical design be?
This is deliberately open. Looking for pet hates and ideas.
90 comments
[ 6.0 ms ] story [ 158 ms ] threadHow is rc better than bash or zsh? I've read the bash man pages and I couldn't figure out exactly how bash expands commands before executing them. Every time the shell see's an unquoted variable name (e.g. $foo) it will do word splitting, which is why you have to write "$foo" instead, or "${foo}bar" to distinguish "$foo" from "$foobar", etc. Add history and filename expansion and command substitution, weird syntax for control statements...
The best feature of rc is that word splitting and globbing happens once, and it results in a list of strings. There is no longer a need to quote variables all the time. No need to use filenames without spaces.
Here's what bash does:
Here's what rc does: It's similar to the situation for dynamic vs lexical scope.http://plan9.bell-labs.com/sys/doc/rc.html
https://github.com/rakitzis/rc
Idea: proper graphics for data/image/video display.
I think it'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).
Too late. xterm already has it for a long time (I remember seeing it working as long ago as in 2003 in rxvt, and it was nowhere new thing then). See the screenshot of w3m, a lynx-like web browser: https://en.wikipedia.org/wiki/W3m
My today's rxvt-unicode also supports this mode.
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'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.
I'd like lines to be rewrapped if I change terminal dimensions. I'd like more automatic pagination (rather than forgetting to use less and nuking your scrollback). I think is an issue with mintty/putty but I'd like its command history to be printed correctly after changing the terminal width.
Pet hates: terminal bells that I didn't explicitly ask for; middle click paste; the obscure terminfo file that sometimes controls the features a program uses.
In reality, no one is using `get-childitem` instead of `ls` or `dir` (both of which are simply aliases for `get-childitem`).
For existing commands that don't get updated, one could just supply the list from a central repo, not unlike Homebrew Cask.
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/$VISUAL (or perhaps via special file-type handlers) would be a nice.
Overall, I'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.
Other than that I wouldn't mind some graphical features, such as being able to display thumbnails of images for example.
(I have done this in KDE's Konsole, so I can paste from a web form I must often use, which somehow blocks the standard Unix/Linux selecting-to-copy, middle-click-to-paste method.)
As many keyboards and computer terminals once directly generated ASCII code, the choice of control-C overlapped with the ASCII end-of-text character. This character has a numerical value of three, as "C" is the third letter of the alphabet. It was chosen to cause an interrupt as it is otherwise unlikely to be part of a program's interactive interface. Many other control codes, such as control-D for the end-of-transmission character, do not generate signals and are occasionally used to control a program.
Also see https://en.wikipedia.org/wiki/C0_and_C1_control_codes#STX
H is 0x48, backspace is 0x08. ^H is the same as backspace.
I is 0x49, tab is 0x09, ^I is the tab sequence.
Now you know why Windows \r in text file show up as ^M in vi and Emacs.
^D is ASCII 0x04, "EOT (end of transmission)". That's why you use that to end input.
^C is ASCII 0x03, whose name is "ETX (end of text)". That seems a reasonable choice.
(…well that, and being able to use your thumb for performing the keyboard shortcut instead of having to use your pinky finger).
Linux isn't lacking it. It just has already decided on a specific shortcut. Do you also consider the absence of Ctrl-C to paste in Safari (in favour of Cmd-C) a lack?
At least on Linux terminal emulators you could always remap it (at your own peril, be careful about setting up another shortcut for the actual interrupt). Pre-Windows 10, OTOH...
And this: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_...
In Powershell you just get an error that this thing is not executable. A waste of semantic space, IMO.
Consider for example executing a compression command on all jpg files in a folder and below. Currently, the syntax goes something like this:
Naive Unix users would have expected this to be achievable by piping, but no! In reality there is a special syntax of the find command that does this, and it'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't just plug in another data source and perform the same operation. In a CLI where tools are designed to be chained, it would look something like this: In this example I used an imaginary |> operator to indicate I want something performed on every item, and I can refer to the "name" 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.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.
SOAP, WSDL have taught us already that more "structure" does not mean better. Binary interfaces such as provided by systemd or http/2 may teach us again the importance of simplicity, human-readability and avoiding too frigid constraints failing in the face of natural evolution between different software versions.
[0] http://www.dwheeler.com/essays/filenames-in-shell.html
Or, if gfxcompress supports multiple arguments, just
Treating the output as objects would be an improvement. I write things like or the more traditional columnar output and awk, but it would be nice if the shell knew about this, enabling tab completion and avoiding a lot of boilerplate.The issue here is not really finding a "better" way to implement this exact example, it's finding a better mechanism for what the example represents.
Can you make everything work with today's tools? Absolutely. Can you do it without arcane switches and weird corner cases? Mostly not. The question I'm raising is more whether this pain is inevitable or not.
But anyway, I think you missed where I wrote, "treating the output as objects would be an improvement", and presented a better example in support of your suggestion.
We already agree about that part (at least sort of). Instead I wanted to address the part where you declared my example invalid and where we're talking about nothing else but the details of this one example. Did I choose it poorly? Was it too simplistic? Maybe, it really depends on your tastes. I content that arguing about whether or not the find command is usefully implemented is besides the point. The problem lies deeper and is more systemic than that.
I'm not arguing that a loop construct is arcane, I'm arguing that in practice such scripts turn arcane really quickly, and that there is something substantial to be gained from having tools exchange information in a structured, machine-centric format - and also from switching to a human-centric control format.
Obviously, for a great many tools that wouldn't be an option because it would break compatibility for scripts that have been running for decades.
And \0 isn't necessarily a safe delimiter for all types of lists.
But, for lists of file names (and other strings that cannot contain \0), yes, I believe that automatically using it when stdout is not connected to a terminal would be a reasonably good idea.
https://www.destroyallsoftware.com/talks/a-whole-new-world
I'd love if the bash shell language was less clunky.
My pet hate is that commands themselves cannot tell you things about them in a structured way. There's no reason why completion and --help are somehow separate from the execution itself.
Love: context aware shell like zsh/oh-my-zsh provide. If I'm in a git project, show me a good git summary for example. If I'm in python venv, tell me about it. If I'm in some python project, extract its name from setup.py.
A modern shell would:
- 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/IPC.
- Know about the structure of valid invocations of commands (essentially, their type signature and the algebraic type structure of their parameters), preventing any "invalid invocation" 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.
- 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.
- Support unicode as the only character set for text.
- 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 "I use a shitty 1980's-era UI because that's the only thing I can export across the network consistently".
- Allow addressing both local and remote system resources (RAM, CPUs, I/O devices) via a uniform interface, and allow dynamically attaching and detaching these from running processes, both local and remote.
- From a more traditional shell perspective, it seems important to support "by" operations with good ergonomics. This is stuff like "sort all these files based on the output of applying this other file-accepting command to each" or "filter out all paragraphs in a text file containing the string 'foo', but only print the last seven characters of each one.".
These would be a start.
Next on the spectrum would be the QT version of ipython. And then of course ipython notebook/jupyter.
What really looks promising is the Jupyter Lab, currently in alpha.
http://blog.jupyter.org/2016/07/14/jupyter-lab-alpha/
https://pypi.python.org/pypi/jupyterlab
Being able to grab some filenames/contents with
is super handy. And the real shell is always just C-z away, if I need it.Right now, "convert a.jpg b.png" passes the strings "a.jpg" and "b.png" to ImageMagick's convert command, but that command is free to open whatever files it wants, since there's no distinction between strings vs resources such as filenames, network sockets, etc.
You can do this with pipes in simple cases, and bash has some support for this, but it's very primitive and the syntax is cumbersome.
https://github.com/shockone/black-screen
- contextual help. if i write a command incorrect, it should suggest correction and link to more help.
- cloud storage of all my command history
- be more understanding. talk a bit in natural language. Eg. show my ip address -> translated to the right shell command.
- learn and grow automatically as the community builds more tools. Like, hey used this command but check this one out!
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.
http://elixir-lang.org/docs/stable/iex/IEx.html#module-remot...
First off, as much as possible, I'd eliminate non-words. I tutor a lot and people think perhaps I have a speech impediment the first time I say "grep". (Yes, I know, it's not technically part of the shell. But okay how about "fi" and "esac"? Really? Why not "enod" then?)
I'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's be a lot of room for those types of ideas.
I do think the philosophy of "do one thing and one thing only, but do it well" 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 "water flowed the other way" instead. For example:
"sort the output of the find result" = sort | find
as opposed to:
"take the output of find and sort it" = find | sort
(That last bit was just a random thought of the moment, just trying to think a wee bit outside of the box.)