Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script for extending bash-completion for certain commands. If I type command1 and do a tab, it should auto-complete with a file directory (and the files). It works fine expect for one inconvenient issue. It adds an extra white space every time it auto-complete. So if you are trying to reach sub-directories from root, for example, every sub-directory you get to an extra space gets added and it kinda defeats the purpose of extending bash-completion. I am new to bash. Is this a result of how I wrote the script or is this just how tab-completion behaves when you extend it?

local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="command1 command2"
serviceOpts="opt1 opt2"


case "${prev}" in
    command1)
        COMPREPLY=( $(compgen -f ${cur}) )
        return 0
        ;;
    command2)
        COMPREPLY=( $(compgen -W "${serviceOpts}" ${cur}) )
        return 0
        ;;
    *)
    ;;
esac
share|improve this question
1  
You may want to use shell check before posting. – Jedi yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.