blogarchivesoftwareunix-tips

By default bash completion doesn’t work for linux vserver in gentoo. On the linux vserver pages there’s a bash completion script available for download but it doesn’t compile. I’ve put together a very simple bash completion script here that does only what I need most – expand on available vservers and the safe options.

On gentoo you need to emerge bash-completion first – but you already knew that didn’t you?

Here’s the source for my script /etc/bash_completion.d/vserver

_vserver() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    opts="enter start stop restart chkconf status exec"
	vservers=$(for x in `ls /vservers -1`; do echo ${x} ; done )

	if [[ ${prev} == "vserver" ]] ; then
        COMPREPLY=( $(compgen -W "${vservers}" -- ${cur}) )
        return 0
	else
		COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
	fi
}

complete -F _vserver vserver

Generated with nanoc - a Ruby content management system for building static web sites.