Stupid tricks to quickly learn Eshell and Dired

Eshell, Dired, Never learn Bash

Maybe no one told you, but Dired and Eshell go together. Try to learn just one without the other, and enlightenment will be tardy.

For faster enlightenment:

  • Realize that there's effectively no prompt as far as the shell is concerned, they're just bookmarks for prompt nav commands. Try having a blank prompt for a while (prompt nav commands won't work) until it feels normal.
  • Forbid cd. It's not sufficient to "try to use it less"; either run something like alias cd=echo in .bashrc, or have cd open a Dired buffer for the target.
  • Forbid ls, or have ls just switch to the Dired buffer for that directory.
  • Have a good hotkey in Dired to open the Shell buffer for the present directory, creating the buffer anew if necessary.
  • Have a good hotkey in Shell to open the Dired buffer for the present directory—or you could content yourself with the ls command doing that.
  • Previous Dired and Shell buffers should always bury themselves at the bottom of the buffer list! They would flood it otherwise.
  • You'll notice that your shell buffers will be cleaner, with no trail of cd or ls output, and this may have made the scrollback more interesting. That ties into the next point: when using the shell, aim to never repeat a command. Decline to engage in the ancient workflow of iterating on shell commands, trying different switches and building pipes incrementally. In fact, you could set a counter for eshell-send-input (RET) such that you can only send 20 commands per day, and display this counter in the modeline or prompt.
    • Learn emacs-piper – it won't be needed as often as you think, but it's great as your last weapon.
    • Learn the hotkeys for navigating and manipulating the output. In particular:
      • C-c C-p – jump to previous prompt
      • C-M-l – similar, but jump to top of last output (better)
      • C-M-j – my-ins-oth-buf-fil-nam
      • C-c RET – more on this later
    • Instead of building pipes like ls -l | grep .jpg | cut -f1, use C-c M-o (eshell-mark-output), narrow-to-region and carry out the appropriate buffer-editing commands to get the same result that the shell command sequence would have. This is the hardest part by far, but the skills you gain in text transformation are general and carry over everywhere.
    • Learn to operate on the custom output you've munged – or even on any text, for example an Occur or EWW buffer – save it into a Lisp variable 'var, and access it as $var in eshell. Write custom functions to instantly pipe selected region to xargs. That sort of thing.

More, if you like going off the beaten path:

  • Save the shell scrollback per directory
  • Save the shell command history per directory
    • A side detail: keep track of the commands you've used the current session. They should be appended to the open directories' histories, regardless which directory they were used in.

if you follow the earlier advice, every directory already gets its own shell (remember that you disabled cd). With this last advice, when you enter a new directory's shell, you may be shown scrollback from weeks ago! Relevant or not, it can be fun to see, and anchors you in the passage of time. If you realize you wanted to use the output from earlier commands, from before you changed directory… simply go back to the previous directory's shell and grab it (hopping between shells should be a hotkey, that's faster than cd .. and cd -). Of course you'll still want the recent command history, things you used just minutes ago in another directory, which is why they should be brought along on the ride. The difference from usual history-tracking is that only the commands this session get saved to only those directories in which you have opened a shell, which is going to be a minority of all the directories you've visited with Dired.

I could ban the pipe (|) operator as part of a learning process for text munging.

What links here

Created (4 years ago)