how to add custom completion to ls command in bash_completion?

Viewed 213

i am trying for suggest custom options in bash completion in commands linux ( centos 7 )

i am know the this code add custom command to bash and suggest options
path : /etc/bash_completion.d/foo

_foo()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="-i(--incoming)  -o(-outgoing) -m(--missed) -a(-all) "

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _foo foo 

foo -[tab]
    -i(--incoming)  -o(-outgoing) -m(--missed) -a(-all)

goal me is extend this source code to built in commands in linux such as ls

trying me is :

path : /etc/bash_completion.d/ls

_ls() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="-a(--all)  -h(--human-readable)   -r(--reverse) "

    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _ls ls 

when this code used not suggest folders and files complete in ls command

ls -[tab]
  -a(--all)  -h(--human-readable)   -r(--reverse) 



ls[tab]
 not suggest files and directory

goal me is add custom option for suggest in bash and not behaviour command

0 Answers
Related