News for hackers. Stuff that matters.
Re:Renaming files with mv without typing the name two times by kazinator on Monday April 13, 2020 @09:03PM (#22861818)
> doesn't show you the new filename

  $ echo mv foo{x,y}bar
> the ability to edit a filename shown, in place

Easily done right in the command line. First, type this:

  $ mv oldname _ 
The _ denotes the cursor.

Now erase the last word using Ctrl-W:

  $ mv _
Now pastte it twie with Ctrl-Y Ctrl-Y:

  $ mv oldname oldname _
Edit in place, submit.
Re:Renaming files with mv without typing the name two times by matt-attack on Monday April 13, 2020 @09:24PM (#22861932)
Using echo is the wrong way. What you do is ‘CTRL-x *’. That will expand any glob right there on the command line.
Re:Renaming files with mv without typing the name two times by kazinator on Monday April 13, 2020 @09:31PM (#22861966)
Brace expansion isn't a glob, unfortunately. Did you try it?
Re:Renaming files with mv without typing the name two times by bruce_one on Tuesday April 14, 2020 @12:45AM (#22862830)
I didn't know the `CTRL-x * ` expansion; it appears to work in zsh for brace expansion:

  $ touch asdf-{gh,jk}-l
  # CTRL-x *
  $ touch asdf-gh-l asdf-jk-l
Re:Renaming files with mv without typing the name two times by tsbinz on Tuesday April 14, 2020 @04:39AM (#22863828)
In zsh you can use tab to expand globs/braces/variables as well.
Re:Renaming files with mv without typing the name two times by m463 on Tuesday April 14, 2020 @08:00AM (#22864838)
I didn't know about that.

I tried control-x escape, that only does variable expansion (and it appears to expand aliases too)

Re:Renaming files with mv without typing the name two times by Kiro on Tuesday April 14, 2020 @03:00AM (#22863378)
Or I just use this script which is much more intuitive and convenient.
Re:Renaming files with mv without typing the name two times by kazinator on Tuesday April 14, 2020 @03:59AM (#22863642)
In my other post, I got the readline method down to one control code. You type "mv name" and hit the assigned control character, which produces a second copy of the name that you can edit in place. It works with any command: mv, cp, ln, git mv ... The editing is in the same command line, resulting in a proper argument that is in the command line. It gets saved into your history, and can be pasted into a script.
Re:Renaming files with mv without typing the name two times by zeepzeep on Tuesday April 14, 2020 @03:31AM (#22863513)
But only solves one use case. Why not learn how to do it for every other unix tool?
Re:Renaming files with mv without typing the name two times by Kiro on Tuesday April 14, 2020 @05:17AM (#22864025)
I don't see how this script prevents me from learning it. With that said, we're obviously in different ballparks when it comes to the terminal. I don't need to do anything fancy. cd, ls, mv and git are pretty much the only commands I ever use. For me, this script fits nicely into my workflow.
Re:Renaming files with mv without typing the name two times by kelnos on Thursday April 16, 2020 @06:18AM (#22887894)
But it's... not? What if I want to use the same trick with 'cp'? Do I go and copy-paste my script, or maybe spend time to make it generic enough to handle both commands? That's not a good use of my time when the shell will do it for me, if only I'd spend a minute to learn.