Unwanted blank after command line <tab> expansion

Karl Auer kauer at biplane.com.au
Sun Sep 4 10:01:37 UTC 2022


On Sun, 2022-09-04 at 11:05 +0200, Ralf Mardorf via ubuntu-users wrote:
> I haven't tried this and the output is from the Arch Linux, not the
> Ubuntu manual page:

Why quote a manual page that may not even be relevant? It's way easier
for the OP to type "man bash", search for "nospace" and get exactly the
right information than to use an incomplete cut-and-paste version.
That's why I recommended doing that.

> I don't know how to use the "nospace" option.

Then what was the point of your message?!?

The "nospace" option is an option to the (bash-internal) "complete"
command, not to bash itself. I have now tried it out.

I have a completion script for one of my commands. The fundamental guts
of it (as with all completion scripts) is a call to the "complete"
command. As the man page says, the "-o" option is for options to the
"complete" command.

My completion script thus has this final line in it:

   complete -F _totp totp

- complete is the bash command
- _totp is a function I wrote that builds
  a completion list
- totp is the program that this completion
  script provides completions for

Altogether this says "when someone wants completions for the 'totp'
command, call the '_totp' function to get a complete list, then deliver
matching completions according to whatever they type".
 
If I use my completion script and there is NO match, it drops a list of
all possible matches and leaves the cursor where it is.

If I use my completion script and there are some matches, it drops a
list of them and leaves the cursor at the end of the longest matching
initial substring.

If I use my completion script and there is exactly ONE match, it adds
the remainder of the matching entry to what I have already typed, and
adds a space. This is what the OP did not want. I do not know if this
is new behaviour - as far as I recall it has always done that, but my
memory is notoriously unreliable :-)

So I modified my completion script to add "-o nospace" before first
existing option to the "complete" command. The command now looks like
this:

   complete -o nospace -F _totp totp

The behaviour is exactly the same except that when there is exactly ONE
match, it adds the remainder of the matching entry to what I have
already typed, and DOES NOT add a space.

Which I am pretty sure is exactly what the OP wanted to know.

Regards, K.

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Karl Auer (kauer at biplane.com.au)
http://www.biplane.com.au/kauer








More information about the ubuntu-users mailing list