News for hackers. Stuff that matters.
Re:New(ish) command line tools by dystroy on Wednesday April 13, 2022 @02:50AM (#31011877)
I really like the approach of pipe-rename (https://github.com/marcusbuffett/pipe-rename) for renaming many files. It's especially convenient for people who can efficiently edit many lines in their favorite text editor (so everybody here, I guess).

Main problem: you maybe don't do this kind of operation frequently enough to remember how it's called or how you aliased it.

Re:New(ish) command line tools by tomsmeding on Wednesday April 13, 2022 @03:45AM (#31012132)
Given that I'm guaranteed to forget that I have this thing installed if I would install it, I'm just going to steal the idea and try to remember to use my editor instead of an ugly shell loop next time I want to rename many files. There's only a small difference, really, between transforming `1.txt 2.txt 3.txt` to `file1.md file2.md file3.md` and transforming to `mv 1.txt file1.md; mv 2.txt file2.md; mv 3.txt file3.md`.
Re:New(ish) command line tools by chrisshroba on Thursday April 14, 2022 @08:29AM (#31025986)
You likely already know this, but just a reminder/tip that bash and zsh will let you edit the current command you’re entering in your editor of choice if you press ctrl+x ctrl+e (without releasing ctrl between). (Note if you’re using zsh without ohmyzsh, you’ll have to enable this manually [1])

[1]: https://nuclearsquid.com/writings/edit-long-commands/

Re:New(ish) command line tools by remram on Saturday April 16, 2022 @12:23PM (#31053607)
I don't see how the shell could know whether you released the Ctrl key?
Re:New(ish) command line tools by chrisshroba on Monday April 18, 2022 @03:11PM (#31075100)
Whoops, you're right, I assumed my muscle memory was the source of truth heh.
Re:New(ish) command line tools by nmaggioni on Wednesday April 13, 2022 @06:30AM (#31013027)
Some time ago I have in fact written a small utility based on fzf that solves this problem by letting you comment aliases in your shell config file and fuzzy-search through them:

https://github.com/nmaggioni/wat

The tag system is especially useful to me when I know the general concept I'm after but don't remember the exact wording of the command.

Re:New(ish) command line tools by southerntofu on Wednesday April 13, 2022 @08:56AM (#31014060)
From a quick look I love it! I just wish something like that was part of my shell and it not only applied to aliases... :)
Re:New(ish) command line tools by jwilk on Wednesday April 13, 2022 @04:35AM (#31012393)
Sounds a bit like vidir from moreutils.
Re:New(ish) command line tools by Erwin on Wednesday April 13, 2022 @05:01AM (#31012519)
I like that idea of converting metadata to text, so you can do text operations on it that you are already familiar with, and then apply the changes back.

If your problem can be solved by just regexps, there's a "rename" tool installed by Perl I've used for decades. E.g.

    rename -n 's/JPEG$/jpg/' *JPEG
Will apply the substitution for JPEG at end of the filename to just jpg. The -n will run without renaming so you can see what it intends to do.
Re:New(ish) command line tools by jwilk on Wednesday April 13, 2022 @10:19AM (#31014951)
Beware there are two incompatible rename programs in the wild. :(

What you have installed, and what Debian and its derivates ship is this: https://metacpan.org/pod/distribution/File-Rename/rename.PL

Most(?) other distros ship the one from util-linux: http://man7.org/linux/man-pages/man1/rename.1.html

Re:New(ish) command line tools by ChrisGranger on Wednesday April 13, 2022 @10:22AM (#31014980)
We had the same idea at the same time. For a command line newbie trying to follow a tutorial, it can certainly be confusing.
Re:New(ish) command line tools by greazy on Wednesday April 13, 2022 @05:04AM (#31012534)
A newer tool 'brename' is similar but uses standard inputs and allows for full regex. Like rename it has dry mode for safe renaming.
Re:New(ish) command line tools by ChrisGranger on Wednesday April 13, 2022 @10:20AM (#31014957)
Note that the rename tool bundled with some distributions is not the Perl version. If someone is looking to install it, it may also be called perl-rename.
Re:New(ish) command line tools by anthk on Wednesday April 13, 2022 @06:41AM (#31013089)
Just use vidir from moreutils.
Re:New(ish) command line tools by yboris on Wednesday April 13, 2022 @10:33AM (#31015111)
OMG! I created a GUI tool for this: Simplest File Renamer (Win, Mac, Linux).

In my app, you can rename using your favorite code editor, so you have access to all your keyboard shortcuts.

https://github.com/whyboris/Simplest-File-Renamer - MIT open source

Re:New(ish) command line tools by encryptluks2 on Wednesday April 13, 2022 @10:45AM (#31015265)
Except the previous example relies on Rust and the shell, while yours relies on Angular/Electron.
Re:New(ish) command line tools by yboris on Wednesday April 13, 2022 @11:29AM (#31015833)
Sorry, by "this" I meant "the same functionality - rename files via text file" :)
Re:New(ish) command line tools by rsync on Wednesday April 13, 2022 @03:27PM (#31019106)
" ... renaming many files ..."

I think folks should be aware of 'vimv' which opens your pwd in an editor and you just edit your filenames in 'vi' ... and all of the renaming happens upon saving and quitting.

Not sure if this is the official/canonical distribution, but for what it's worth:

https://github.com/thameera/vimv

Re:New(ish) command line tools by Existenceblinks on Thursday April 14, 2022 @12:07AM (#31023305)
Everything that needs manual entry can utilize text editor features greatly! Search and replace, multiple cursors, duplication, formatting etc. However, there will require some fancy ways to put result back in input sources.
Re:New(ish) command line tools by nxbp on Wednesday April 13, 2022 @05:32AM (#31012684)
Looks like a glorified version of qmv from renameutils? (https://www.nongnu.org/renameutils/)
Re:New(ish) command line tools by globular-toast on Wednesday April 13, 2022 @04:39AM (#31012412)
It is a good approach. Emacs has dired and other modes for doing this.
Re:New(ish) command line tools by dan-robertson on Wednesday April 13, 2022 @04:50AM (#31012475)
To expand on this: if you look at a dir in Emacs then change the buffer to be writable, you can change file names and saving the buffer renames files. You can also edit the permissions columns in a similar way. And there is vc integration so eg eMacs will hg mv files in a mercurial repo.
Re:New(ish) command line tools by globular-toast on Wednesday April 13, 2022 @05:12AM (#31012584)
I didn't know about the VC integration. After 15 years emacs can still surprise me!
Re:New(ish) command line tools by rich_sasha on Wednesday April 13, 2022 @04:47AM (#31012458)
My approach is something like

  $ ls / find # tweak until I have a list of things to rename
  $ for file in $(ls / find...); do echo "mv $file $(echo $file | sed ... )"; done # this prints mv commands for renaming, I can inspect them as needed
  $ for file in $(); do...; done | sh # execute the renaming
It is inspectable, easy to cancel (just don't pipe to shell), incremental... just needs wrangling with bash etc. which is a bit of a pain.

It works for a bunch of other all-or-nothing commands, which are potentially quite destructive; use a for-loop to generate the commands, tweak until you're happy with it, then pipe to shell.

Re:New(ish) command line tools by da39a3ee on Wednesday April 13, 2022 @07:41AM (#31013497)
Thanks! I do this but go in and remove the echo. For some reason I hadn’t thought to pipe to a shell interpreter.
Re:New(ish) command line tools by justsomehnguy on Wednesday April 13, 2022 @05:54AM (#31012817)

    ls | % {rename-item $_ -newname $('myfile_' + ($_.BaseName -replace '\D') + '.md' )}
No need to remember anything.
Re:New(ish) command line tools by michaelmior on Wednesday April 13, 2022 @06:49AM (#31013135)
</sarcasm>? I would be much more likely to remeber ls | renamer than figure out how to write such a command.
Re:New(ish) command line tools by justsomehnguy on Wednesday April 13, 2022 @12:52PM (#31017016)
> </sarcasm>?

Nope.

> to remeber

That's the point, you don't need to remember anything, it would come naturally after a day of tinkering with PS/pwsh.

You just write it for your current needs.

This example was just a quick one-liner, it's very simple:

    ls | % {            # get the file list, cycle for each item
    
    rename-item         # obvious usage: rename-item oldname newname
    
        $_              # pretty obvious, the source - place the loop variable here ie file name
      
        -newname        # explicit calling for a parameter name, isn't really needed 
        
          $(            # subroutine start or eval if you prefer, to construct the new file name:
                        # 'text' + (take property basename from the file and regex it) + 'text'
                        
            'myfile_' + ($_.BaseName -replace '\D') + '.md'
            
          )             # subroutine end
          
      }                 # cycle end.
It could be simplified (in this example) to this:

    ls | % {
        $a = 'myfile_' + ($_ -replace '\D') + '.md'
        rename-item $_ $a
        }
which could be even written as a one-liner if you prefer it right now, just add a semicolon after `$a = ...`

    ls | % {$a = 'myfile_' + ($_ -replace '\D') + '.md'; rename-item $_ $a }
Re:New(ish) command line tools by l2dy on Sunday April 17, 2022 @09:55AM (#31060833)
This is a lot to remember, and a typo could mess things up badly.
Re:New(ish) command line tools by GoblinSlayer on Wednesday April 13, 2022 @04:54AM (#31012491)
The demo requires a sufficiently smart editor. But with a sufficiently smart editor you can prepare a script and pipe it into an interpreter.
Re:New(ish) command line tools by gorgoiler on Wednesday April 13, 2022 @05:00AM (#31012512)
Pipe rename automates the following common script in a much nicer way:

  !ls
  qaVypImv “escapeA” escapeJi”escapeA”escapejq99@a
Re:New(ish) command line tools by lenkite on Thursday April 14, 2022 @03:38AM (#31024309)
ZSH has mmv for this.