7

More concise version

With "\t": menu-complete in ~/.inputrc create these two files,

$ touch one.two.txt
$ touch one.four.txt

start writing the following,

$ ls one

hit Tab and you'll get

$ ls one.four.txt

Now move the cursor to just before four, delete four, write only t, and then hit Tab again. You'll get

$ ls one.two.txt.txt

Is there a way to prevent the duplicated .txt in this workflow?

Original question

I use menu-complete bash function to cycle through completion when I press Tab, and I'm happy with it. But the following has too often happened to me.

Suppose I'm looking for the file longparthardtoremember.with.QQQQQQQ.extension in a directory which contains the files

longparthardtoremember.with.AAAAAAA.nice.long.extension
longparthardtoremember.with.BBBBBBB.very.nice.long.extension
...

If I Tab-complete $ long the first filename will be inserted. At that point, I'd like to move to the middle of the filename, delete the AAAAAAA part, type B, and then Tab-complete again. If I do so, all the part after BBBBBBB is inserted as well, thus leading to a duplication of it, which I obviously don't want.

With vi editing mode, I'm quite quick in dealing with this (I quickly move to the repeated part and delete it), but it is still annoying.

By pure chance I've find the skip-completed-text bash option in bash's man page. Isn't this what I need? I've set it on, but I can't see any difference in the behavior of in-middle-of-work Tab-completion. Have I misunderstood the man page?

2
  • It's a bit hard to follow what you want - maybe add a few steps and show the output on the command line?
    – laktak
    Commented Feb 6, 2021 at 22:00
  • @laktak, how's it now?
    – Enlico
    Commented Feb 6, 2021 at 22:28

2 Answers 2

3
+50

skip-completed-text works this way (with your example touch one.four.txt):

$ ls one.four
#        ^ cursor is on the f

If you press tab with skip-completed-text on it will complete to

$ ls one.four.txt

If you press tab with skip-completed-text off it will complete to

$ ls one.four.txtour

So this setting does not help you when you edit the middle of the completion.

0

Instead of

Now move the cursor to just before four, delete four, write only t, and then hit Tab again.

do

move the cursor to just before four, write only t, then hit Tab followed by Ctrlk (the default for delete from cursor until end)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .