http://www.linux-vserver.org/api.php?action=feedcontributions&user=82.225.0.224&feedformat=atom
Linux-VServer - User contributions [en]
2024-03-28T12:32:57Z
User contributions
MediaWiki 1.20.2
http://www.linux-vserver.org/util-vserver:Bash_Completion
util-vserver:Bash Completion
2006-11-30T21:36:13Z
<p>82.225.0.224: </p>
<hr />
<div>To test this, put the source in your .bashrc or put it in the file /etc/bash_completion.d/vserver (Debian).<br />
<br />
This release (0.4) supports the commands vserver vapt-get vrpm vyum vserver-copy.<br />
<br />
This script is included in the util-vserver Debian package, and is automatically installed into /etc/bash_completion.d/vserver when you install this package.<br />
<br />
For zsh completion, the Debian zsh package has the vserver completion included, see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=365238 for the source, or https://intrigeri.boum.org/svn/pub/home/modules/base/.zsh/functions/_vserver for the upstream SVN repository.<br />
<br />
<br />
# Completion for the vserver command. Source this file (or on some systems<br />
# add it to ~/.bash_completion and start a new shell) and bash's completion<br />
# mechanism will know all about vserver's options!<br />
#<br />
# Copyright (C) Thomas Champagne <lafeuil@gmail.com><br />
#<br />
# This program is free software; you can redistribute it and/or modify<br />
# it under the terms of the GNU General Public License as published by<br />
# the Free Software Foundation; either version 2, or (at your option)<br />
# any later version.<br />
#<br />
# This program is distributed in the hope that it will be useful,<br />
# but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />
# GNU General Public License for more details.<br />
#<br />
# You should have received a copy of the GNU General Public License<br />
# along with this program; if not, write to the Free Software Foundation,<br />
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br />
#<br />
# The latest version of this software can be obtained here:<br />
#<br />
# http://linux-vserver.org/Vserver_Completion<br />
#<br />
# version 0.4.1<br />
<br />
have vserver-info && {<br />
<br />
: ${UTIL_VSERVER_VARS:=$(vserver-info - SYSINFO |grep prefix: | awk '{ print $2}')/lib/util-vserver/util-vserver-vars}<br />
test -e "$UTIL_VSERVER_VARS" && {<br />
<br />
if [ -z "$_VS_NEWLINE" -o -z "$VS_ALLVSERVERS_ARGS" ]<br />
then<br />
. "$UTIL_VSERVER_VARS"<br />
. "$_LIB_FUNCTIONS"<br />
fi<br />
<br />
_vserver() {<br />
local cur cmds cmdOpts cmdMethodOpts helpCmds names names_pipe func i j method<br />
<br />
COMPREPLY=()<br />
cur=${COMP_WORDS[COMP_CWORD]}<br />
<br />
# find available v-servers: <br />
# call function getAllVservers in vserver library<br />
getAllVservers names<br />
names_pipe=`echo ${names[@]} | sed 's/ /|/g'`<br />
<br />
# available commands<br />
cmds='start stop restart condrestart suexec exec enter chkconfig \<br />
running status unify pkg apt-get apt-config apt-cache \<br />
rpm pkgmgmt delete'<br />
<br />
# options (long and short name)<br />
cmdOpts='--help --version --debug --defaulttty -s --sync -v \<br />
--verbose --silent --'<br />
<br />
cmdMethodOpts='-m -n --context --confdir --lockfile \<br />
--hostname --netdev --netbcast --netmask \<br />
--netprefix --interface --cpuset \<br />
--cpusetcpus --cpusetmems --cpusetvirt \<br />
--initstyle --flags --help --'<br />
<br />
# if the previous option is a single option <br />
helpCmds='--help|--version'<br />
if [[ ${COMP_WORDS[1]} == @($helpCmds) ]] <br />
then<br />
return 0<br />
fi<br />
<br />
# search a verser's name<br />
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ ))<br />
do<br />
if [[ ${COMP_WORDS[i]} == @($names_pipe) ]]<br />
then<br />
# it's found<br />
break<br />
fi<br />
done<br />
<br />
#a vserver has been found <br />
if (( $i < ${#COMP_WORDS[@]}-1 )) <br />
then <br />
#Show the vserver command without build<br />
case "${COMP_WORDS[i+1]}" in<br />
start)<br />
COMPREPLY=( $( compgen -W "--rescue --rescue-cmd" -- $cur ) )<br />
;;<br />
# No completion for apt-config<br />
stop|restart|condrestart|enter|running|status|apt-config|delete)<br />
;;<br />
suexec)<br />
# I don't know how to do<br />
COMPREPLY=( $( compgen -W -- $cur ) )<br />
;;<br />
exec)<br />
#I don't know how to do<br />
COMPREPLY=( $( compgen -W "" -- $cur ) )<br />
;;<br />
unify)<br />
COMPREPLY=( $( compgen -W "-R" -- $cur ) )<br />
;;<br />
apt-get|apt-cache)<br />
func=${COMP_WORDS[i+1]}<br />
COMP_WORDS=( ${COMP_WORDS[@]:$((i+1))} )<br />
COMP_CWORD=$((COMP_CWORD-i-1))<br />
declare -f _${func//-/_} > /dev/null && _${func//-/_}<br />
;;<br />
*)<br />
COMPREPLY=( $( compgen -W "$cmds" -- $cur ) ) <br />
;;<br />
esac<br />
return 0<br />
else<br />
#no vserver name found<br />
prev=${COMP_WORDS[COMP_CWORD-1]}<br />
<br />
#search the new name of vserver <br />
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do<br />
if [[ ${COMP_WORDS[i]} == !(vserver|-*) ]]; then<br />
# it's found<br />
break<br />
fi<br />
done<br />
<br />
if (( $i < ${#COMP_WORDS[@]}-1 )) ; then <br />
j=$i<br />
i=${#COMP_WORDS[@]}<br />
for (( ; j < ${#COMP_WORDS[@]}-1; j++ )); do<br />
if [[ ${COMP_WORDS[j]} == "--" ]]; then<br />
# method's parameter<br />
case "$method" in<br />
legacy|copy)<br />
;;<br />
apt-rpm)<br />
COMPREPLY=( $( compgen -W "-d" -- $cur ) )<br />
;;<br />
yum)<br />
COMPREPLY=( $( compgen -W "-d" -- $cur ) )<br />
;;<br />
rpm) <br />
COMPREPLY=( $( compgen -W "-d --empty --force --nodeps" -- $cur ) )<br />
;;<br />
skeleton)<br />
;;<br />
debootstrap)<br />
COMPREPLY=( $( compgen -W "-d -m -s --" -- $cur ) )<br />
;;<br />
*)<br />
#do nothing <br />
#the method is not defined<br />
;;<br />
esac<br />
return 0<br />
break<br />
fi<br />
if [[ ${COMP_WORDS[j]} == @(build|-m) ]]; then<br />
i=$j<br />
if (( $j+1 < ${#COMP_WORDS[@]}-1 )) ; then<br />
method=${COMP_WORDS[j+1]}<br />
fi<br />
fi<br />
done <br />
<br />
if (( $i < ${#COMP_WORDS[@]}-1 )) ; then<br />
case $prev in<br />
--help)<br />
#do nothing<br />
;;<br />
-n|--context|--confdir|--lockfile|--hostname|--netdev|--netbcast|--netmask|--netprefix|--interface|--cpuset|--cpusetcpus|--cpusetmems|--cpusetvirt|--initstyle|--flags)<br />
COMPREPLY=( $( compgen -W "" -- $cur ) )<br />
;;<br />
-m)<br />
COMPREPLY=( $( compgen -W "legacy copy apt-rpm yum rpm skeleton debootstrap" -- $cur ) )<br />
;;<br />
*)<br />
COMPREPLY=( $( compgen -W "$cmdMethodOpts" -- $cur ) )<br />
;;<br />
esac<br />
<br />
else<br />
COMPREPLY=( $( compgen -W "build" -- $cur ) )<br />
fi<br />
else<br />
COMPREPLY=( $( compgen -W "${names[@]} $cmdOpts" -- $cur ) )<br />
fi<br />
return 0<br />
fi<br />
<br />
return 0<br />
}<br />
complete -F _vserver vserver<br />
<br />
_vapt_rpm_yum()<br />
{<br />
local cur cmds cmdOpts helpCmds names func i<br />
<br />
COMPREPLY=()<br />
cur=${COMP_WORDS[COMP_CWORD]}<br />
<br />
# options (long and short name)<br />
cmdOpts='--help --version --quiet -q --all'<br />
<br />
# if the previous option is a single option <br />
helpCmds='--help|--version'<br />
if [[ "${COMP_WORDS[1]}" == "@($helpCmds)" ]] ; then<br />
return 0<br />
fi<br />
<br />
# search --<br />
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do<br />
if [[ ${COMP_WORDS[i]} = "--" ]]; then<br />
# it's found<br />
break<br />
fi<br />
done<br />
<br />
# find available v-servers: <br />
# call function getAllVservers in vserver library<br />
getAllVservers names<br />
names_pipe=`echo ${names[@]}" --all" | sed 's/ /|/g'`<br />
<br />
if (( $i < ${#COMP_WORDS[@]}-1 )) && (( $i < $COMP_CWORD )) ; then <br />
func=${COMP_WORDS[0]:1}<br />
COMP_WORDS=( $func ${COMP_WORDS[@]:$((i+1))} )<br />
COMP_CWORD=$((COMP_CWORD-i))<br />
declare -f _${func//-/_} > /dev/null && _${func//-/_}<br />
else <br />
# search a verser's name<br />
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do<br />
if [[ ${COMP_WORDS[i]} == @($names_pipe) ]]; then<br />
# it's found<br />
break<br />
fi<br />
done<br />
<br />
if (( $i < ${#COMP_WORDS[@]}-1 )) ; then <br />
if [[ "${COMP_WORDS[i]}" = "--all" ]]; then<br />
cmdOpts='--'<br />
COMPREPLY=( $( compgen -W "$cmdOpts" -- $cur ) )<br />
else<br />
cmdOpts='--'<br />
COMPREPLY=( $( compgen -W "${names[@]} $cmdOpts" -- $cur ) )<br />
fi<br />
else<br />
COMPREPLY=( $( compgen -W "${names[@]} $cmdOpts" -- $cur ) )<br />
fi<br />
fi<br />
return 0<br />
}<br />
complete -F _vapt_rpm_yum vapt-get<br />
complete -F _vapt_rpm_yum vrpm<br />
complete -F _vapt_rpm_yum vyum<br />
<br />
_vserver_copy()<br />
{<br />
local cur prev cmdOpts helpCmds confCmds names names_pipe i<br />
<br />
COMPREPLY=()<br />
cur=${COMP_WORDS[COMP_CWORD]}<br />
<br />
# find available v-servers: <br />
# call function getAllVservers in vserver library<br />
getAllVservers names<br />
names_pipe=`echo ${names[@]} | sed 's/ /|/g'`<br />
<br />
# options (long and short name)<br />
cmdOpts='--help -h --version -V --verbose -v --quiet -q \<br />
--vsroot -r --rsh -R --stopstart -s \<br />
--domain -d --ip -i'<br />
<br />
# if the previous option is a single option <br />
helpCmds='--help|-h|--version|-V'<br />
if [[ ${COMP_WORDS[1]} == @($helpCmds) ]] ; then<br />
return 0<br />
fi<br />
<br />
confCmds='--ip|-i|--domain|-d'<br />
prev=${COMP_WORDS[COMP_CWORD-1]}<br />
if [[ $prev == @($confCmds) ]]; then<br />
return 0<br />
fi<br />
<br />
# search a verser's name<br />
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do<br />
if [[ ${COMP_WORDS[i]} == @($names_pipe) ]]; then<br />
# it's found<br />
break<br />
fi<br />
done<br />
<br />
if (( $i < ${#COMP_WORDS[@]}-1 )) ; then <br />
return 0<br />
else<br />
COMPREPLY=( $( compgen -W "${names[@]} $cmdOpts" -- $cur ) )<br />
fi<br />
return 0<br />
}<br />
complete -F _vserver_copy vserver-copy<br />
<br />
}<br />
}<br />
<br />
<br />
;Changelog :<br />
:0.4.1 : handle multiple sourcing scenarios<br />
:0.4.0 : Update command vserver build<br />
:0.3.2 : Add Licence<br />
:0.3.1 : Add the command vapt-get vrpm vyum vserver-copy<br />
:0.2.0 : First release with just the command vserver</div>
82.225.0.224