Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't think I've ever had to rename 20 files at once, so I wonder if the way people work is kind of shaped by their tools?


I've had to batch-rename files many times over the years. That means:

1. I do it manually over however many minutes. Works if there aren't too many (especially if the pattern is too complex to trivially automate).

2. I make a Python script for it. No way I'm renaming a thousand files by hand.

3. I don't do it. Too much work. The problem lingers forever.

Or these days,

4. I make an AI datacenter eat another town's water supply.

I've never used Emacs. I tried vi(m) nonconsensually and had to google how to exit. A while later, I tried it intentionally and hkjl navigation didn't work because I use a custom keyboard layout, so I never touched it again. Sublime Text and its many cursors for the win!

I'd love a way that isn't miserable to do such a common basic task.


Try vidir from moreutils (or its improved version, https://github.com/bulletmark/edir ).

It opens the list of filenames in a given directory (or set of files passed on cmdline) in an editor of your choice, and then you use your editor to rename them; the changes get applied when your editor is closed.


> I'd love a way that isn't miserable to do such a common basic task.

The problem is that you actually describe a family of tasks which is not basic. The "iterate over files, select the right ones and apply rules to rename them" part is common; the problem is that the rules vary broadly in kind and complexity, and you haven't figured out how you want to specify them (some ways will be limited in the complexity they can handle.

(Usually the selection of files is trivial; when not, we can fold that complexity into the change rules, and emit null changes in some cases.)

If your selection rule is simple enough for Bash globbing, and your per-file rename rule is simple enough for, say `tr` to handle, then that's trivial to wrap up as a Bash script (or function). In fact, you could write the Python script such that it just accepts a single input filename and outputs the changed version, and handle the rest externally.

> I've never used Emacs. I tried vi(m) nonconsensually and had to google how to exit. A while later, I tried it intentionally and hkjl navigation didn't work because I use a custom keyboard layout, so I never touched it again. Sublime Text and its many cursors for the win!

I'm not really clear on how text editors are supposed to be relevant to batch file renaming. If trying vi(m) the first time wasn't your idea, then there should have been someone else around responsible for guiding you through it. But the variations I've tried had arrow-key navigation configured by default (and `vimtutor` explicitly tells you that it should also work); you really don't have to learn hjkl, which exists largely for a combination of historical reasons with a lot of back-filled justifications. (I would have used ijkl, mimicking an arrow-key layout.) And everything can be remapped in the config files.


"I don't think I've ever had" stance, about any problem is not a good argument. At some point you'd face them and the mental models shaped by the tools you choose, often force you to deal with them in a way that often creates small, subtle micro-annoyances. You won't even consciously notice them, yet they add up. You get constantly distracted, every time by small bits, your focus budget gets eroded without you even noticing it. You feel inexplicably tired at 3PM without any meaningful work getting done for the day.

In psychology there's a term called "emotional bank account model" - small chronic negatives silently drain the account, so by the time something "big" happens there's no reserve left, even though the big thing isn't the actual cause. That is I think why our field has notorious "burned out programmer" problem. We can't even explain the reasons - because the accumulation is diffuse and undramatic, people lack a narrative-worthy explanation, and the real cause is chronic negative-affect accumulation.

That is why it is important to seek ways for the "gratified productivity" where no matter how small your problem seem to be, you can find ways to automate it nicely, ideally reaching for solutions quickly. Tools do shape your mindset. Expertise changes what affordances you perceive. Experienced Emacs user when stumbled on a problem looks at a workflow and literally sees the seams where it can be pried open, the way a climber sees holds on a blank wall. Novices often don't even recognize the wall. It's not that Emacs "has this capability, but other tools don't", it's not about specific features, it's about the mindset. Experience awk hacker for the same "rename 20 files problem" may combine a complex looking single-liner and say: "who needs Emacs schmimax? ble...", the difference in the approach, but the result is not just the output but also the mental gratification - small problem fixed quickly. While a newbie would be doing it manually, and maybe even solving it faster, but there's no gratification. We are species of "tool builders" - we get excited from using tools, sharpening them each time. Menial tasks don't leave that sharpened mental edge, they "blunt" your mindset and accumulate frustration.


The only case I can imagine is when I rename a Java interface and want all implementations to be also renamed accordingly. I can do that in 1 second in IntelliJ. With dired on emacs that would not be possible at all and I would need a tool that can find all implementations first: that requires a LSP on emacs, and then from a xref buffer, not sure how I could rename all classes and their files at once. Probably would need to be manually done? Anyone knows how to do it in emacs with one command?


It would be the same as in IntelliJ. As long as you have the Java LSP active, you issue the `lsp-rename` action: https://emacs-lsp.github.io/lsp-java/#lsp-mode-commands

This works exactly the same for all languages whose LSP support this action, which is most of them.


No! Rename in JSP is not intelligent enough to match an interface name with its implementation names and decide whether to also rename those!


What do you mean by "implementation names"? I assumed you meant changing the "implements X", which should be easy for an LSP.


Java implementations sometimes take part of the name from the interface they implement, for example, `FooRunner` probably implements `Runner`. My example was that I renamed `Runner` to whatever, `Executor`, and IntelliJ will ask me if I want to rename also implementations (in this case, it would show `FooRunner` -> `FooExecutor`).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: