scop / bash-completion

Programmable completion functions for bash
GNU General Public License v2.0
2.91k stars 380 forks source link

Problems when the cursor is in the middle of words #489

Open jidanni opened 3 years ago

jidanni commented 3 years ago

Today let's explore some cases of when the cursor is within a word, and we hit TAB. We will use [ ] to indicated what character the cursor is on. We will randomly choose some commands here, (sys..., find), to test. But this bug report applies much wider. (Actually the sys... example isn't too good, as it highly depends on the state of your system.)

Example 1:

# systemctl st[s]ystemd-resolved
BEEPS

(Hitting TAB flashes the screen / beeps.) (Bad.)

Example 2:

# systemctl st[ ]systemd-resolved
start   status  stop

Excellent. However in Example 1, couldn't the space been added for us?

Example 3:

# systemctl st systemd-reso[ ]
BEEPS

Hmmmm.

Example 4:

# systemctl stop systemd-res[o]lved.ser
# systemctl stop systemd-resolved.service[o]lved.ser

That's right. We are now looking at

# systemctl stop systemd-resolved.serviceolved.ser

(with the cursor still sitting on the final "o".) (Hitting RET no will of course send the trailing junk to the program.)

Anyway, I hope through these examples I have illustrated that although bash-completions works great when the cursor is at the end of the (last) word, they don't work so great when the cursor is in the middle of words.

Wait, here's one more. Example 5:

# find x -e[m]p
-empty       -exec        -execdir     -executable

(Hey, didn't you see the 'p' at the end?!)

jidanni commented 3 years ago

OK,

bind 'set skip-completed-text on'

fixes example 4 and 5, and at least doesn't seem to make anything else worse.

   skip-completed-text (Off)
          If set to On, this alters the default completion  behavior  when
          inserting  a  single match into the line.  It's only active when
          performing completion in the middle  of  a  word.   If  enabled,
          readline  does  not  insert  characters from the completion that
          match characters after point in the  word  being  completed,  so
          portions of the word following the cursor are not duplicated.

Then why isn't "on" the default? (OK, I will ask bug-bash.)