On Not Using Terminals
The typical hierarchy of computer users involves two levels: those who use UNIX terminals a lot, and... everyone else, who should but doesn't.
Said hierarchy is present in many minds of users of UNIX / Linux machines; actually, with PowerShell, even Windows users are slowly getting convinced that the True Way of using a computer involves opening one (or many) terminal windows, typing long commands (extra points for pipelines), and staring at the results as they scroll forth. This, due to its simplicity, is clearly superior to any other way in which one could use a computer... and this especially includes clicking on things.
With this, I present today's Mostly Weird Fact:
I don't actually use terminals that much. (Despite working a whole lot with Linux computers.)
In this post (and some of the followups?), I'll show how this might actually be nice, even.
Is this yet another weird Emacs post?
This statement is technically true. For the record, if you do want terminals, Emacs is a mostly excellent replacement for
screen; you can start an instance on your server & use
emacsclient to reconnect to your set of terminal buffers.
This is, however, not what I mean. Terminals within Emacs are still terminals, with a prompt, and an infinitely long piece of printer paper above, with all the things your previous commands printed.
There are other ways though.
Just not running commands
I'm wondering how much of UNIX terminal usage is a combination of
ls. They are excellent tools; I'm pretty sure there are also neat enhanced versions (e.g. a
cd with a stack of past directories).
As it happens, Emacs has a mode for "editing" directories; it's called
dired. If you open a directory instead of a file, you get something like this:
It's just like the output of
ls. But then it's much better! It's just like another Emacs buffer with an open file; you can do whatever you can in those: search for text, move around, copy parts, etc. It's also much faster than exploring directories with plain
- Up a directory: just hit "^"
- Open a subdir: hit "Enter" on it
- "w" copies the name of the file, even without having to select it (... I'm literally using this right now to copy the image file name into the HTML file)
- "C-u 0 w" copies the full path of a file
- You can also just edit (as in "type into the middle of") file names (and do search-replace on them) if you hit "C-x C-q" (commit with "C-c C-c")
If you just want to peek into a subdir, you can have it dump the contents into the same buffer:
But... most importantly, for our Quest of Avoiding Terminals: you can run commands on them!
But actually still running commands
You might have thought that we'll go all the way & will avoid running UNIX commands altogether. Well... we're definitely not going that far. Being able to run commands is actually nice; it's just we don't have to do it in a terminal (a.k.a. infinite piece of printer paper) all the time.
As it happens, it's super easy to run commands in Emacs: "M-!" ("M" is Alt, basically) gets you a prompt:
... hit Enter & you get the results:
... also showcasing the fact that it's non-interactive: it was probably trying to ask for a new one, but we closed its input on it.
This is nice if you just want to run something quick, maybe look at the results, and have them disappear once you do anything else. (If you really want to, you can still dig them up from the "*Messages*" buffer.)
You can also run these commands async, either by lauching them as such by "M-&" or just by putting an & at the end of the command. Here is an example, with preparing a new command while a previous round of it is still running:
The difference is that the synchronous ones will block everything & just display their results ephemerally; for the async ones, the output gets written into a buffer, in which you can search, copy, etc, since they are just like any other buffer / open file in Emacs. (... there might be a recurring theme here.)
Finally, you can use
dired (the directory editor) to pick files & run commands on them. You can just go to a file and hit "!"... or you can select (mark) multiple (press "m") and hit "!" after, to get an entire list of files:
After typing a command, results are shown just like in the above case.
OK so we can... navigate around & kinda run commands? In a weird way? Without a terminal? And sometimes it's quicker?
Which is nice for some things. Quick & simple commands, like checking the date? Sure. Converting some random images to jpegs while looking at a directory listing? Possibly. But then we have our ssh sessions and long-running compilations and countless other cases, when one-offs are just inconvenient.
So... coming up in the followup post: compilation mode, some things about ssh and some other things about shell scripts!