@tucamon Vuestra web ha caido, vais a subir el video a algĂșn sitio?
To have a bash script with auto-completion capabilities is easy. Imagine a script called startp2p.sh, this scripts takes as parameter the name of the program to start, for example amule or bt. Since many times I don't remember the names, I just want to type the following command:
$ startp2p.sh [TAB-key]
and the shell should return the options:
amule bt

Achieve that is very easy, just create as root the following file:
/etc/bash_completion.d/startp2p.sh
with this content:
_startp2p()
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="amule bt"

    if [[ ${cur} == * && ${COMP_CWORD} -eq 1 ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi
}
complete -F _startp2p -o filenames startp2p.sh
/etc/bash_completion.d/startp2p.sh

To test it, reboot the computer or run
. /etc/bash_completion.d/startp2p.sh

For more information about bash completion visit this links:
An introduction to bash completion: part 1
An introduction to bash completion: part 2
Gentoo guide for shell completion


Comments (0)







Allowed tags: <b><i><br>Add a new comment: