by imiric · 1y ago · 0 comments
Huh? All your examples are easily done in a shell. GNU find and fd support regex, xargs can be used for bulk operations, etc. This is more flexible and scriptable than anything dired allows you to do. It might not be immediately easier, but once you grasp how a few basic shell utilities work and how to combine them, using shell history, functions, aliases, and key bindings becomes part of your muscle memory. This workflow is even more transferable across systems and environments.
I think dired is convenient if you're already using Emacs and want to do a quick operation, but the shell is far more generally useful in the long run.
I don't see how this is comparable to arbitrarily browsing through a directory, inspecting files, and manually marking the ones you want to act on. The feature I was describing is more akin to how we browse directories in a graphical desktop environment.
I use find, xargs, and similar tools as well, but they don't allow you to casually mark or unmark files and run operations on them later. With these tools, you need a fairly precise idea of what you're targeting. Then you have to write a glob or regex pattern up front, and then execute the command. That's a very different workflow from interactively exploring a directory, making ad-hoc decisions, and selectively marking files as you go.
You might be missing fzf from your toolbelt. Running `fzf --multi` does just that, and allows you to pipe the selection further to anything else you want to do.
This is why the shell is a more flexible environment. You don't need to adopt a large monolithic tool or drastically change your workflow to do something which you previously couldn't. You just need to insert another tool that does a single thing well into your existing pipelines, and your workflow can be improved with much less effort.
Shell tools, Unix utilities, and 'fzf --multi' are definitely very powerful. But at least to me, they don't seem to offer the same kind of spontaneous browsing and editing experience, I'm referring to.
To be clear, this isn't some sort of competition! I'm not claiming one approach is superior to the other. Every tool has its strengths. My comments highlighting the features of Emacs do not imply that other tools are inferior. Quite the contrary!
I'm very fond of computing and I enjoy having a broad set of excellent tools at my disposal. The only point I disagree with is the claim that "all your examples are easily done in a shell". In my experience, the kind of random, ad hoc browsing, previewing, editing, marking and unmarking files, I'm talking about isn't quite as straightforward in the shell. It's certainly possible, but it doesn't feel as seamless or fluid as it does in Emacs. But again, this is not a competition. This is just an acknowledgement that different tools do different things!
I regularly rely on commands like 'find ... -exec', 'xargs', 'fzf', etc. But I also use Dired (and Emacs, in general) extensively. I find familiarity with both styles of tools very useful and the knowledge of both types of tools are transferable across a wide range of systems and environments.
> In my experience, the kind of random, ad hoc browsing, previewing, editing, marking and unmarking files, I'm talking about isn't quite as straightforward in the shell. It's certainly possible, but it doesn't feel as seamless or fluid as it does in Emacs. But again, this is not a competition.
Certainly. We should all use the tools we feel most comfortable with. And, frankly, the kind of visual selection you mentioned is not something I frequently do myself. In the rare cases I've had to, I was fine with a more rudimentary approach of previewing the files in whatever program can read them and mapping them to filenames manually. Doing this with dired, fzf with preview mode, or in a proper file manager, whether that's in a terminal with something like lf or in a more featureful GUI one, would've probably been faster.
That said, I was also objecting to your original claim that this cannot be easily done with standard Unix tools. At the end of the day, the choice of tools and what is easier to accomplish is subjective. I personally don't like relying on a single tool for my workflows, so I use Emacs strictly for editing text files. I even prefer the Git CLI over Magit, which is pretty blasphemous in the Emacs world. :) And I really like composing small purpose-built tools in the shell, especially if I can repurpose them in some way I hadn't done before, so using the shell instead of a file manager feels more natural to me. But they're all preferences, and it would be silly to claim that one is objectively inferior or superior to another.
Cheers!
[1]: https://github.com/junegunn/fzf?tab=readme-ov-file#previewin...
Instead of typing up an entire command pipeline all at once, or running sections of the pipeline into temporary files that you examine/edit with a text editor, Emacs lets you run that same pipeline interactively in a text buffer (basically a temporary file). Being able to see the results as you work on it interactively is a huge advantage (compare ed vs vi).
As you say, none of them do anything that can't be done with find and xargs (and perhaps a little awk and sed), but they're occasionally handy for one-off operations.
Dired can filter files with regexp; you can even fall back on GNU ‘find’ (‘find-dired’). And you can execute shell commands on filtered files in Dired (‘&’), it’s like xargs without the confusing syntax—but, of course, you can just run ‘xargs’ from it, if that’s what you prefer.
A graphical file-manager is, I find, a much nicer interface for file-management than the command-line. I see all filtered files, and I can view and edit them anytime, as I please. With the command-line, it’s like I’m working with blindfolds on.
Dired can be a nice refuge even if you’re a command-line junkie, because in-spite of its own commands (abstracting the shell), you can always drop back to the shell, as you please. Funnily enough, my usage of Dired vis-à-vis the shell is kind of the inverse of what you described, I use the shell for either quick or really complicated operations and Dired for everything else—which ends up being over 95% of my use.
Preference is definitely a factor, I agree with you there. But while a programming language is obviously more flexible technically, most people don't want to write a program to perform a task on their computer.
My point is that the shell is easier to script than writing Lisp (for most people; I'm sure Lisp nerds would disagree), and is more flexible than whatever facilities dired provides out of the box. To be fair, I haven't used dired more than a few times even though Emacs is my primary editor, but even if it emulates xargs or allows you to drop down to shell commands directly, it will never be as flexible for file operations as just using the shell.
The shell is not just a file manager. That's one of its primary features, sure, but it allows you to operate on files in an infinite number of ways. This is because it exposes fairly simple primitives that allow you to combine programs in ways that even their authors hadn't anticipated. This is why the do-one-thing-well philosophy is so powerful.
The famous Knuth-McIlroy story illustrates this well. Knuth created a sophisticated program to count words, which McIlroy replicated in a one-line shell script using a few UNIX tools. Knuth's was probably more correct, better documented, and handled edge cases better, but McIlroy's obviously required far less effort and would be easier to understand and expand. I don't think any tech geek or programmer would prefer writing a program for such relatively simple tasks.
My points were, first, Dired is easier than the shell for 99% of file management, as it’s a graphical file manager with many advanced functions. It’s literally a graphical ‘ls -l’ that that you can freely move around, browse and act on; the same way vi was a graphical ed. And, second,
> it will never be as flexible for file operations as just using the shell
for the remaining 1% where the shell would be easier than a Dired built-in, I’d rather do them from Dired, because, being a graphical program, I have a dynamic directory listing that I can peruse as I please. And the shell is the shell, whether you open a command-line in your terminal emulator or run shell commands from Dired.
Maybe the shell’s primitives are too abstract and I prefer them abstracted behind Dired. Emacs Lisp has primitive functions, too, it’s just the higher-level functions are useful most of the time.
> Knuth created a sophisticated program to count words, which McIlroy replicated in a one-line shell script using a few UNIX tools.
Yes, now let’s see McIlroy publish the C source of the Unix built-ins he used to be fair to Knuth in that comparison, who provided the whole source of his implementation.
Composibility was an afterthought when making C, and that’s what Unix inherits; redirecting text with pipes between different programs will never be as simple and elegant as an interface that was made for composibility and extension, from the programming language up—Lisp Machines. I have scarcely found shell one-liners to be elegant in the sense they make sense at first glance—granted I’m a user, not a programmer. Lisp functions—functional programming—on the other hand, when used together, have an intuitive flow, especially in how they modify input, that’s easy to wrap my head around.
But the word runs on Unix shell, much, much more so than a functional-programming-language REPLs—“worse is better” like you said earlier.
> I don't think any tech geek or programmer would prefer writing a program for such relatively simple tasks.
Writing little Emacs Lisp functions—combining more abstract built-in Emacs Lisp functions—feels a lot like chaining shell command together, but better.