[Help-bash] autocompletion - adding a space after a hint
From:
Quaquaraqua
Subject:
[Help-bash] autocompletion - adding a space after a hint
Date:
Fri, 28 Aug 2015 15:40:31 +0100
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0
Hi,
I've already tried to ask about this issue on bashscripts.org, but
didn't receive a satisfactory answer so far. My question is there a way
to have the autocompletion functionality adding a space after a
suggestion in certain cases, and not in others?
For instance, consider a function that can have arguments such as -c
<key> <path>. I'd like that when a user is looking for <key>, he or she
presses <TAB> and selects the suggestion, then the caret should move to
the next argument adding a space after the suggestion. And indeed this
is the default. However when the argument refers to a <path>, after a
suggestion the caret shouldn't be moved further, because the user may
want to continue traversing the path looking for the folders/files
inside the current path.
Currently I have disabled the feature of adding a space setting `-o
nospace', but this disables it all together for both keys and paths.
This is my code so far:
# Autocompletion
function _go_autocomplete() {
COMPREPLY=( ); # restore to empty
local cur=${COMP_WORDS[COMP_CWORD]}
# command
if [ "$COMP_CWORD" == "1" ]; then
if [ ${cur:0:1} == "-" ]; then
# all the commands