Sunday, 19 May 2013

bash_completion

bash_completion

I have a simple script, which creates a symlink IP_address -> config_file (used for pxe boot). My script is called like this:
lnpxe CONFIG HOSTNAME
where CONFIG is one of my config files stored in /home/tftp/config/ and HOSTNAME is any hostname. Now, I am trying to set up bash_completion for my script. When I type lnpxe and then press TAB, I would like to have my config files in /home/tftp/config/ "suggested" to me and autocompleted. Similarly, for the second argument, I would like to have suggestions of available hosts from my /etc/hosts file (similar as ping or ssh do)
Here is my /etc/bash_completion.d/lnpxe file which does NOT work as I would like to:
_lnpxe()
{
    local cur prev
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    _filedir

}
complete -F _lnpxe -o filenames lnpxe
Could somebody please help ?

No comments:

Post a Comment