Hacker News new | past | comments | ask | show | jobs | submit login

> 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.



Using echo is the wrong way. What you do is ‘CTRL-x *’. That will expand any glob right there on the command line.


Brace expansion isn't a glob, unfortunately. Did you try it?


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


In zsh you can use tab to expand globs/braces/variables as well.


I didn't know about that.

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


Or I just use this script which is much more intuitive and convenient.


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.


But only solves one use case. Why not learn how to do it for every other unix tool?


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.


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.




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

Search: