LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash autocomplete space after match (https://www.linuxquestions.org/questions/linux-newbie-8/bash-autocomplete-space-after-match-4175420709/)

suicidaleggroll 08-06-2012 05:19 PM

bash autocomplete space after match
 
Is there a way to prevent the autocomplete feature in the bash shell from appending a space to the match for certain commands?

My problem is this: I create a temporary file or two, call them file1 and file2, then want to remove them. Usually I'll do "rm fi<tab>*". This completes to "rm file*", which matches all of the file1, file2, etc that I want to remove.

The issue is that sometimes I'm in a rush, and I forget and do this when there's just one file to remove. The result is that "rm fi<tab>*" completes to "rm file *", which removes not only "file", but everything else in my CWD.

All I want is a programmable completion so that for "rm", autocomplete works like normal except that it does NOT append a space to the match. I can add the space myself if I want to specify more than one file.

I simply cannot find a way to do this...I thought nospace would work, but when I run "complete -o nospace rm", autocomplete seems to be completely disabled for rm, which obviously is not what I want. What am I missing here?

grail 08-06-2012 11:18 PM

Well some searching I found the following page:

http://www.gnu.org/software/bash/man...etion-Builtins

And as a basic test I did the following:
Code:

$ compopt rm
compopt +o bashdefault +o default +o dirnames +o filenames +o nospace +o plusdirs rm
$ compopt -o nospace rm
$ compopt rm
compopt +o bashdefault +o default +o dirnames +o filenames -o nospace +o plusdirs rm

Now when I use rm I get no space after the completion. Didn't read far enough to make it permanent but sure it is in there somewhere :)

suicidaleggroll 08-07-2012 04:59 PM

Thanks, I was trying to use complete to set the nospace, and it was killing autocomplete entirely.

complete -o default rm
followed by
compopt -o nospace rm

has fixed the issue


All times are GMT -5. The time now is 02:20 AM.