Revision: 19103
          http://gar.svn.sourceforge.net/gar/?rev=19103&view=rev
Author:   chninkel
Date:     2012-08-26 19:01:44 +0000 (Sun, 26 Aug 2012)
Log Message:
-----------
improved or fixed pkgadd, pkgrm, pkgutil and svcadm completion

Modified Paths:
--------------
    csw/mgar/pkg/bash_completion/trunk/files/changelog.CSW
    csw/mgar/pkg/bash_completion/trunk/files/pkgadd.completion
    csw/mgar/pkg/bash_completion/trunk/files/pkgrm.completion
    csw/mgar/pkg/bash_completion/trunk/files/pkgutil.completion

Added Paths:
-----------
    csw/mgar/pkg/bash_completion/trunk/files/pkg-get.completion
    csw/mgar/pkg/bash_completion/trunk/files/svcadm.completion

Removed Paths:
-------------
    csw/mgar/pkg/bash_completion/trunk/files/pkg-get.completion
    csw/mgar/pkg/bash_completion/trunk/files/smf.completion

Modified: csw/mgar/pkg/bash_completion/trunk/files/changelog.CSW
===================================================================
--- csw/mgar/pkg/bash_completion/trunk/files/changelog.CSW      2012-08-26 
14:50:13 UTC (rev 19102)
+++ csw/mgar/pkg/bash_completion/trunk/files/changelog.CSW      2012-08-26 
19:01:44 UTC (rev 19103)
@@ -1,3 +1,10 @@
+bash_completion (2.0,REV=2012.08.26)
+
+  * Improved pkgadd, pkgrm and svcadm completion.
+  * Fixed pkgutil completion.
+
+   -- Yann Rouillard <[email protected]>  Sun, 26 Aug 2012 20:59:36 +0200
+
 bash_completion (2.0,REV=2012.08.23)
 
   * New upstream version.

Deleted: csw/mgar/pkg/bash_completion/trunk/files/pkg-get.completion
===================================================================
--- csw/mgar/pkg/bash_completion/trunk/files/pkg-get.completion 2012-08-26 
14:50:13 UTC (rev 19102)
+++ csw/mgar/pkg/bash_completion/trunk/files/pkg-get.completion 2012-08-26 
19:01:44 UTC (rev 19103)
@@ -1,80 +0,0 @@
-#
-# Copyright 2006 Yann Rouillard <[email protected]>
-# All rights reserved.  Use is subject to license terms.
-#
-# Redistribution and/or use, with or without modification, is
-# permitted.  This code is without warranty of any kind.  The
-# author(s) shall not be liable in the event that use of the
-# software causes damage.
-#
-# pkg-get.completion - bash completion for opencsw pkg-get
-#
-
-_have pkg-get && 
-_pkg-get_get_catalog_file()
-{
-       local url="$1"
-       local catalog_file i conffile
-
-       for file in /etc/opt/csw/pkg-get.conf /opt/csw/etc/pkg-get.conf 
/etc/pkg-get.conf; do
-               if [[ -f $file ]]; then
-                       conffile="$file"
-                       break
-               fi
-       done
-       conffile="${conffile:-/opt/csw/etc/pkg-get.conf}"
-
-       if [[ -z "$url" ]]; then
-               url=$(awk -F= ' $1=="url" { print $2 }' $conffile)
-       fi
-
-       catalog_file="${url##*//}"
-       catalog_file="${catalog_file%%/*}"
-       catalog_file="/var/pkg-get/catalog-$catalog_file"
-
-       echo "$catalog_file"
-} &&
-_pkg-get()
-{
-       local cur prev file catalog_file url command
-       COMPREPLY=()
-       cur="${COMP_WORDS[COMP_CWORD]}"
-       prev="${COMP_WORDS[COMP_CWORD-1]}"
-
-       if [[ "${prev}" = "-s" ]]; then
-               return 1
-       fi
-
-       i=${#COMP_WORDS[*]} 
-       while [[ $i -gt 0 ]]; do
-               i=$((i-1))
-               if [[ "${COMP_WORDS[$i]}" = "-s" ]]; then
-                       url="${COMP_WORDS[$((i+1))]}"
-               fi
-               if [[ "${COMP_WORDS[$i]}" == 
@(available|-a|describe|-D|download|-d|install|-i|list|updatecatalog|-U|upgrade|-u)
 ]]; then
-                       command="${COMP_WORDS[$i]}"     
-               fi
-       done
-       
-       if [[ -n "$command" ]]; then
-               if [[ "$command" == @(describe|-D|download|-d|install|-i) ]]; 
then
-                       catalog_file=$(_pkg-get_get_catalog_file "$url")
-                       if [[ -f $catalog_file ]]; then
-                               local packages_list=$(awk ' $0 ~ /BEGIN PGP 
SIGNATURE/ { exit } $1 ~ /^Hash:/ || $1 ~ /^ *(-|#|$)/ { next } { print $1 }' 
$catalog_file)
-                               COMPREPLY=( $(compgen -W "${packages_list}" -- 
${cur}) )
-                       fi
-               fi
-               return 0
-       fi
-
-       if [[ ${cur} == -* ]] ; then
-               local opts="-c -d -D -f -i -l -s -S -u -U -v"
-               COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
-               return 0
-       else
-               local commands="available describe download install list 
updatecatalog upgrade" 
-               COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
-               return 0
-       fi
-} &&
-complete -F _pkg-get pkg-get

Added: csw/mgar/pkg/bash_completion/trunk/files/pkg-get.completion
===================================================================
--- csw/mgar/pkg/bash_completion/trunk/files/pkg-get.completion                 
        (rev 0)
+++ csw/mgar/pkg/bash_completion/trunk/files/pkg-get.completion 2012-08-26 
19:01:44 UTC (rev 19103)
@@ -0,0 +1,80 @@
+#
+# Copyright 2006 Yann Rouillard <[email protected]>
+# All rights reserved.  Use is subject to license terms.
+#
+# Redistribution and/or use, with or without modification, is
+# permitted.  This code is without warranty of any kind.  The
+# author(s) shall not be liable in the event that use of the
+# software causes damage.
+#
+# pkg-get.completion - bash completion for opencsw pkg-get
+#
+
+_have pkg-get && 
+_pkg-get_get_catalog_file()
+{
+       local url="$1"
+       local catalog_file i conffile
+
+       for file in /etc/opt/csw/pkg-get.conf /opt/csw/etc/pkg-get.conf 
/etc/pkg-get.conf; do
+               if [[ -f $file ]]; then
+                       conffile="$file"
+                       break
+               fi
+       done
+       conffile="${conffile:-/opt/csw/etc/pkg-get.conf}"
+
+       if [[ -z "$url" ]]; then
+               url=$(awk -F= ' $1=="url" { print $2 }' $conffile)
+       fi
+
+       catalog_file="${url##*//}"
+       catalog_file="${catalog_file%%/*}"
+       catalog_file="/var/pkg-get/catalog-$catalog_file"
+
+       echo "$catalog_file"
+} &&
+_pkg-get()
+{
+       local cur prev file catalog_file url command
+       COMPREPLY=()
+       cur="${COMP_WORDS[COMP_CWORD]}"
+       prev="${COMP_WORDS[COMP_CWORD-1]}"
+
+       if [[ "${prev}" = "-s" ]]; then
+               return 1
+       fi
+
+       i=${#COMP_WORDS[*]} 
+       while [[ $i -gt 0 ]]; do
+               i=$((i-1))
+               if [[ "${COMP_WORDS[$i]}" = "-s" ]]; then
+                       url="${COMP_WORDS[$((i+1))]}"
+               fi
+               if [[ "${COMP_WORDS[$i]}" == 
@(available|-a|describe|-D|download|-d|install|-i|list|updatecatalog|-U|upgrade|-u)
 ]]; then
+                       command="${COMP_WORDS[$i]}"     
+               fi
+       done
+       
+       if [[ -n "$command" ]]; then
+               if [[ "$command" == @(describe|-D|download|-d|install|-i) ]]; 
then
+                       catalog_file=$(_pkg-get_get_catalog_file "$url")
+                       if [[ -f $catalog_file ]]; then
+                               local packages_list=$(awk ' $0 ~ /BEGIN PGP 
SIGNATURE/ { exit } $1 ~ /^Hash:/ || $1 ~ /^ *(-|#|$)/ { next } { print $1 }' 
$catalog_file)
+                               COMPREPLY=( $(compgen -W "${packages_list}" -- 
${cur}) )
+                       fi
+               fi
+               return 0
+       fi
+
+       if [[ ${cur} == -* ]] ; then
+               local opts="-c -d -D -f -i -l -s -S -u -U -v"
+               COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+               return 0
+       else
+               local commands="available describe download install list 
updatecatalog upgrade" 
+               COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
+               return 0
+       fi
+} &&
+complete -F _pkg-get pkg-get


Property changes on: csw/mgar/pkg/bash_completion/trunk/files/pkg-get.completion
___________________________________________________________________
Added: svn:executable
   + *

Modified: csw/mgar/pkg/bash_completion/trunk/files/pkgadd.completion
===================================================================
--- csw/mgar/pkg/bash_completion/trunk/files/pkgadd.completion  2012-08-26 
14:50:13 UTC (rev 19102)
+++ csw/mgar/pkg/bash_completion/trunk/files/pkgadd.completion  2012-08-26 
19:01:44 UTC (rev 19103)
@@ -8,37 +8,20 @@
 # software causes damage.
 #
 
-_pkgadd_complete_pkginst ()
-{
-       local device filedir
-       device=$1
-
-       for filedir in $(/bin/ls -1 $device); do
-               if [[ -d "$device/$filedir" ]] && [[ -f 
"$device/$filedir/pkginfo" ]]; then 
-                       pkginst_list=( ${pkginst_list[@]:-} "$filedir" )
-               fi
-       done
-}
-
-have pkgadd &&
 _pkgadd ()
 {
-        local cur prev i device pkginst_list
-        COMPREPLY=()
-       pkginst_list=()
-        cur="${COMP_WORDS[COMP_CWORD]}"
-        prev="${COMP_WORDS[COMP_CWORD-1]}"
+       local cur prev words cword 
+       _init_completion -n : || return
 
        # if a device directory was given
        # we must complete with the package
        # available in this directory
-       device=/var/spool/pkg;
-       i=${#COMP_WORDS[*]};
-       while [[ $i -gt 0 ]]; do
-               i=$((i-1));
-               case "${COMP_WORDS[$i]}" in
-                       -d)
-                       device="${COMP_WORDS[$((i+1))]}";
+       local device=/var/spool/pkg;
+       local i=$cword
+       while [[ $((i--)) -gt 0 ]]; do
+               case "${words[$i]}" in
+               -d)
+                       device="${words[$((i+1))]}";
                        break
                        ;;
                esac;
@@ -62,11 +45,16 @@
                        local opts="-a -A -d -k -n -M -P -r -R -s -v -V -x"
                        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
                else    
+                       local pkginst_list
                        if [[ -d $device ]]; then       
-                               _pkgadd_complete_pkginst $device
+                               for filedir in $(/bin/ls -1 $device); do
+                                       if [[ -d "$device/$filedir" ]] && [[ -f 
"$device/$filedir/pkginfo" ]]; then 
+                                               pkginst_list+=( 
${pkginst_list[@]:-} "$filedir" )
+                                       fi
+                               done
                                pkginst_list="${pkginst_list[@]}"
                        else
-                               pkginst_list=$(strings $device | grep "^PKG=" | 
sort -u | cut -d= -f2)
+                               pkginst_list=$(strings $(dequote $device) | 
grep "^PKG=" | sort -u | cut -d= -f2)
                        fi
                        COMPREPLY=( $(compgen -W "$pkginst_list" -- ${cur}) )
                fi

Modified: csw/mgar/pkg/bash_completion/trunk/files/pkgrm.completion
===================================================================
--- csw/mgar/pkg/bash_completion/trunk/files/pkgrm.completion   2012-08-26 
14:50:13 UTC (rev 19102)
+++ csw/mgar/pkg/bash_completion/trunk/files/pkgrm.completion   2012-08-26 
19:01:44 UTC (rev 19103)
@@ -11,21 +11,19 @@
 _have pkgrm &&
 _pkgrm ()
 {
-    local cur prev i spool;
-    COMPREPLY=();
-    cur="${COMP_WORDS[COMP_CWORD]}";
-    prev="${COMP_WORDS[COMP_CWORD-1]}";
+    local cur prev words cword 
+    _init_completion || return
 
     # if a spool directory was given
     # we must complete with the package
     # available in this directory
-    spool=/var/sadm/pkg;
-    i=${#COMP_WORDS[*]};
-    while [[ $i -gt 0 ]]; do
+    local spool=/var/sadm/pkg;
+    local i=$cword
+    while [[ $((i--)) -gt 0 ]]; do
         i=$((i-1));
-        case "${COMP_WORDS[$i]}" in
+        case "${words[$i]}" in
             -s)
-                spool="${COMP_WORDS[$((i+1))]}";
+                spool="${words[$((i+1))]}";
                 break
             ;;
         esac;

Modified: csw/mgar/pkg/bash_completion/trunk/files/pkgutil.completion
===================================================================
--- csw/mgar/pkg/bash_completion/trunk/files/pkgutil.completion 2012-08-26 
14:50:13 UTC (rev 19102)
+++ csw/mgar/pkg/bash_completion/trunk/files/pkgutil.completion 2012-08-26 
19:01:44 UTC (rev 19103)
@@ -10,53 +10,95 @@
 # pkgutil.completion - bash completion for pkgutil
 #
 
-_have pkgutil && 
+
+_pkgutil_url2catalog()
+{
+       local filename="$1"
+
+       filename="${filename##*://}"
+       filename="${filename//\//_}"
+       filename="/var/opt/csw/pkgutil/catalog.${filename}_$(uname -p)_$(uname 
-r)"
+
+       echo "$filename"
+}
+
 _pkgutil()
 {
-       local cur prev file catalog_file url command
-       local catalog_file="/var/opt/csw/pkgutil/catalog.`uname -p`.`uname -r`"
-       COMPREPLY=()
-       cur="${COMP_WORDS[COMP_CWORD]}"
-       prev="${COMP_WORDS[COMP_CWORD-1]}"
+       local cur prev words cword 
+       _init_completion -n : || return
 
-       i=${#COMP_WORDS[*]} 
-       while [[ $i -gt 1 ]]; do
-               i=$((i-1))
-               if [[ "${COMP_WORDS[$i]}" = @(-t|--temp) ]]; then
-                       url="${COMP_WORDS[$((i+1))]}"
+       local command catalog_files configuration_files
+       declare -a configuration_files=("/opt/csw/etc/pkgutil.conf" 
"/etc/opt/csw/pkgutil.conf")
+       declare -a catalog_files=()
+
+       i=$cword
+       while [[ $((i--)) -gt 1 ]]; do
+               if [[ "${words[$i]}" = @(-t|--temp) ]]; then
+                       local url="${words[$((i+1))]}"
+                       local catalog=$(_pkgutil_url2catalog "$url")
+                       catalog_files=("$catalog")
+               elif [[ "${words[$i]}" = @(--config) ]]; then
+                       configuration_files=( "$(dequote ${words[$((i+1))]})" )
+               elif [[ "${words[$i]}" == 
@(-i|--install|-u|--upgrade|-r|--remove|-d|--download|-a|--available|-c|--compare|-U|--catalog|-S|--stream)
 ]]; then
+                       command="${words[$i]}"  
                fi
-               if [[ "${COMP_WORDS[$i]}" == 
@(-i|--install|-u|--upgrade|-r|--remove|-d|--download|-a|--available|-c|--compare|-U|--catalog|-S|--stream)
 ]]; then
-                       command="${COMP_WORDS[$i]}"     
-               fi
        done
-       
-       if [[ -n "$command" ]]; then
-               if [[ -f $catalog_file ]]; then
-                       if [[ "$command" == 
@(--download|-d|--install|-i|--upgrade|-u|s|--stream) ]]; then
-                               local packages_list=$(awk ' $0 ~ /BEGIN PGP 
SIGNATURE/ { exit } $1 ~ /^Hash:/ || $1 ~ /^ *(-|#|$)/ { next } { print $1 }' 
$catalog_file)
-                               COMPREPLY=( $(compgen -W "${packages_list}" -- 
${cur}) )
-                       elif [[ "$command" == @(-r|--remove) ]]; then
-                               local packages_list=$(pkginfo | awk ' $2 ~ 
/^CSW/ { printf ("%s|",$2) }')
-                               packages_list=${packages_list%|}
-                               packages_list=$(nawk " \$3 ~ 
/^$packages_list\$/ { print \$1 }" $catalog_file)
-                               COMPREPLY=( $(compgen -W "${packages_list}" -- 
${cur}) )
-                       fi
-               fi
+
+       if [[ "$prev" = @(-W|--workdir|-P|--pkgdir|-R|--rootpath) ]]; then
+               _filedir -d
                return 0
        fi
 
-       if [[ "$prev" = @(-W|--workdir) ]]; then
-               COMPREPLY=( $(compgen -d -- ${cur}) )
+       if [[ "$prev" = @(-o|--output|--config) ]]; then
+               _filedir
                return 0
        fi
 
-       if [[ "$prev" = @(-o|--output) ]]; then
-               COMPREPLY=( $(compgen -f -- ${cur}) )
+       if [[ "$prev" = @(-p|--param) ]]; then
+               compopt -o nospace
+               COMPREPLY=( $(compgen -W "mirror: pkgaddopts: pkgrmopts: 
wgetopts: use_gpg: use_md5: pkgliststyle: maxpkglist: noncsw: 
stop_on_hook_soft_error: exclude_pattern: gpg_homedir: root_path: 
deptree_filter_common: show_current: catalog_not_cached: catalog_update:" -- 
$cur) )
                return 0
        fi
 
-       local commands="-i --install -u --upgrade -r --remove -d --download -a 
--available -c --compare -U --catalog -e --email -t --temp=site -s --stream -T 
--target -o --output -x --exclude -W --workdir -y --yes -n --nomod -D --debug 
-h --help -v --version -V --syscheck"
-       COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
+       if [[ "$prev" = @(-T|--target) ]]; then
+               # Work-around bash_completion issue where bash interprets a 
colon
+               # as a separator, borrowed from maven completion code which 
borrowed
+               # it from darcs completion code :)
+               local colonprefixes=${cur%"${cur##*:}"}
+               COMPREPLY=( $(compgen -W "sparc:5.9 sparc:5.10 sparc:5.11 
i386:5.9 i386:5.10 i386:5.11" -- $cur) )
+               local i=${#COMPREPLY[*]}
+               while [ $((--i)) -ge 0 ]; do
+                       COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"}
+               done
+               return 0
+       fi
+
+       if [[ -n "$command" ]] && [[ ! "$cur" == -* ]]; then
+
+               local mirrors mirror_url
+               mirrors=$(awk -F= ' $1 ~ /^ *mirror *$/ { print $2 }' 
${configuration_files[@]})
+               mirrors=${mirrors:-http://mirror.opencsw.org/opencsw/testing}
+               for mirror_url in $mirrors; do
+                       local catalog=$(_pkgutil_url2catalog "$mirror_url")
+                       catalog_files=( "${catalog_files[@]}" "$catalog" )
+               done
+
+               if [[ "$command" == 
@(--download|-d|--install|-i|--upgrade|-u|s|--stream) ]]; then
+                       local packages_list=$(awk ' $0 ~ /BEGIN PGP SIGNATURE/ 
{ exit } $1 ~ /^Hash:/ || $1 ~ /^ *(-|#|$)/ { next } { print $1 }' 
"${catalog_files[@]}")
+                       COMPREPLY=( $(compgen -W "${packages_list}" -- $cur) )
+
+               elif [[ "$command" == @(-r|--remove) ]]; then
+                       local packages_list=$(pkginfo | awk ' $2 ~ /^CSW/ { 
printf ("%s|",$2) }')
+                       packages_list=${packages_list%|}
+                       packages_list=$(nawk " \$3 ~ /^$packages_list\$/ { 
print \$1 }" "${catalog_files[@]}")
+                       COMPREPLY=( $(compgen -W "${packages_list}" -- $cur) )
+               fi
+               return 0
+       fi
+
+       local commands="-i --install -u --upgrade -r --remove -d --download -U 
--catalog -a --available --describe -c --compare -C --compare-diff -A 
--compare-avail -e --email -t --temp -x --exclude -W --workdir -P --pkgdir -R 
--rootpath --config -y --yes -f --force -n --nomod -N --nodeps -D --debug 
--trace -h --help -v --version -V --syscheck -l --list -L --listfile -F 
--findfile --deptree --extract -s --stream -o --output -T --target --single -p 
--param --parse --cleanup --catinfo"
+       COMPREPLY=( $(compgen -W "${commands}" -- $cur) )
        return 0
-} &&
+} 
+
 complete -F _pkgutil pkgutil

Deleted: csw/mgar/pkg/bash_completion/trunk/files/smf.completion
===================================================================
--- csw/mgar/pkg/bash_completion/trunk/files/smf.completion     2012-08-26 
14:50:13 UTC (rev 19102)
+++ csw/mgar/pkg/bash_completion/trunk/files/smf.completion     2012-08-26 
19:01:44 UTC (rev 19103)
@@ -1,104 +0,0 @@
-#
-# Copyright 2006 Yann Rouillard <[email protected]>
-# All rights reserved.  Use is subject to license terms.
-#
-# Redistribution and/or use, with or without modification, is
-# permitted.  This code is without warranty of any kind.  The
-# author(s) shall not be liable in the event that use of the
-# software causes damage.
-#
-
-_smf_complete_frmi ()
-{
-       local cur="$1" prefix="$2"
-       local IFS=$'\t\n' 
-       local colons nb_colons frmi pattern=""
-
-       if [[ "$cur" == "$prefix"* ]]; then
-               prefix="$cur"
-       fi
-
-       colons=${cur//[^:]/}
-       nb_colons=${#colons}
-
-       # solaris sed doesn't seem to support \(pattern\)\{number\} regex
-       while [[ "$nb_colons" -ne 0 ]]; do
-               pattern="$pattern[^:]*:"
-               nb_colons=$(( nb_colons - 1 ))
-       done
-               
-       if [[ -n "$pattern" ]]; then
-               frmi="$(svcs -H -o FMRI "$prefix*" 2>/dev/null | sed -n -e 
"s/$pattern//p")"
-       else
-               frmi="$(svcs -H -o FMRI "$prefix*" 2>/dev/null)"
-       fi
-       
-       cur="${cur##*:}"
-       COMPREPLY=( $(compgen -W "$frmi" -- ${cur}) )
-}
-
-_have svcadm &&
-_svcadm ()
-{
-        local cur prev command command_list command_option i
-        COMPREPLY=()
-        command_list="enable disable restart refresh clear mark milestone"
-        cur="${COMP_WORDS[COMP_CWORD]}"
-        prev="${COMP_WORDS[COMP_CWORD-1]}"
-
-       for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
-                if [[ ${COMP_WORDS[i]} == 
@(enable|disable|restart|refresh|clear|mark|milestone) ]]; then
-                        command=${COMP_WORDS[i]}
-                fi
-        done
-
-        if [[ -z "$command" ]]; then
-                if [[ ${cur} == -* ]] ; then
-                        COMPREPLY=( $(compgen -W "-v" -- ${cur}) )
-                else
-                        COMPREPLY=( $(compgen -W "$command_list" -- ${cur}) )
-                fi
-        else
-                case "$command" in
-                        enable)
-                       if [[ ${cur} == -* ]]; then
-                               COMPREPLY=( $(compgen -W "-r -s -t" -- ${cur}) )
-                        else
-                                _smf_complete_frmi "${cur}" "svc:"
-                        fi;;
-
-                        disable)
-                       if [[ ${cur} == -* ]]; then
-                               COMPREPLY=( $(compgen -W "-s -t" -- ${cur}) )
-                        else
-                                _smf_complete_frmi "${cur}" "svc:"
-                        fi;;
-
-                       restart)
-                                _smf_complete_frmi "${cur}" "svc:";;
-                       refresh)        
-                                _smf_complete_frmi "${cur}" "svc:";;
-                       clear)
-                                _smf_complete_frmi "${cur}" "svc:";;
-                       mark)
-                       if [[ ${cur} == -* ]]; then
-                               COMPREPLY=( $(compgen -W "-I -t" -- ${cur}) )
-                       else
-                               if [[ "$prev" == @(degraded|maintenance) ]]; 
then
-                                       _smf_complete_frmi "${cur}" "svc:"
-                               else
-                                       COMPREPLY=( $(compgen -W "degraded 
maintenance" -- ${cur}) )
-                               fi
-                        fi;;
-
-                       milestone)
-                       if [[ ${cur} == -* ]]; then
-                               COMPREPLY=( $(compgen -W "-d" -- ${cur}) )
-                       else
-                               _smf_complete_frmi "${cur}" "svc:/milestone/"
-                       fi;;
-                esac
-        fi
-} &&
-complete -F _svcadm svcadm
-

Copied: csw/mgar/pkg/bash_completion/trunk/files/svcadm.completion (from rev 
19076, csw/mgar/pkg/bash_completion/trunk/files/smf.completion)
===================================================================
--- csw/mgar/pkg/bash_completion/trunk/files/svcadm.completion                  
        (rev 0)
+++ csw/mgar/pkg/bash_completion/trunk/files/svcadm.completion  2012-08-26 
19:01:44 UTC (rev 19103)
@@ -0,0 +1,152 @@
+#
+# Copyright 2006 Yann Rouillard <[email protected]>
+# All rights reserved.  Use is subject to license terms.
+#
+# Redistribution and/or use, with or without modification, is
+# permitted.  This code is without warranty of any kind.  The
+# author(s) shall not be liable in the event that use of the
+# software causes damage.
+#
+
+
+# 
+# svcadm accept any complete FMRI or abreviated FMRI
+#  - a complete FMRI is svc:/foo/bar/bar/baz
+#  - abbreviated FMRI are foo/bar/bar/baz, bar/bar/baz, bar/baz or baz
+#
+# The goal of this function is to be able to propose all alternatives,
+# but to not clutter the interface with all completions, we will only
+# cut every completion alternative at the next slash.
+#
+# For exemple, if the user types <nothing><tab>, we will propose for 
svc://foo/bar/bar/baz
+# the following completion: foo/, bar/ and baz
+# If the user types <b><tab>, we will propose: bar/ and baz
+# If the user types <bar/><tab>, we will propose: bar/bar/ and bar/baz
+#
+# By default, the function proproses only abbreviated completions except if 
the user already
+# began to type svc:. In that case we will propose only the complete FMRI 
beginning with the
+# pattern
+#
+_smf_complete_fmri ()
+{
+       local cur="$1" prefix="$2"
+       local cur_prefix fmri fmri_list=""
+       local exact_mode pattern
+
+       if [[ "$cur" == $prefix* ]]; then
+               [[ "$cur" == $prefix ]] && cur+="/"
+               pattern="$cur*"
+               exact_mode=1
+       else
+               pattern="$prefix*/$cur*"
+       fi
+               
+       cur_prefix="${cur%"${cur##*/}"}"
+
+       for fmri in $(svcs -H -o FMRI "$pattern" 2>/dev/null); do
+
+               local fmri_part_list fmri_part
+
+               if [[ -z "$exact_mode" ]]; then
+
+                       fmri=${fmri#$prefix/}
+
+                       # we generate all possibles abbrevations for the FMRI
+                       # no need to have a generic loop as we will have a 
finite
+                       # number of components
+                       local OIFS="$IFS"; IFS="/"; set -- $fmri; IFS="$OIFS"
+                       case $# in
+                               1) fmri_part_list=" $1";;
+                               2) fmri_part_list=" $2 $1/$2";;
+                               3) fmri_part_list=" $3 $2/$3 $1/$2/$3";;
+                               4) fmri_part_list=" $4 $3/$4 $2/$3/$4 
$1/$2/$3/$4";;
+                       esac
+               else
+                       fmri_part_list="$fmri"
+               fi
+
+               # Here we make sure the completions begins with the pattern and 
+               # we cut them at the first slash
+               for fmri_part in $fmri_part_list; do
+                       [[ "$fmri_part" == $cur* ]] || continue
+                       local first_part=${fmri_part#$cur_prefix}
+                       first_part=$cur_prefix${first_part%%/*}
+                       [[ "$first_part" != "$fmri_part" ]] && first_part+="/"
+                       fmri_list+=" $first_part"
+               done
+       done
+
+       COMPREPLY=( $fmri_list )
+
+       # here we want to detect if there only one completion proposed and that
+       # it ends with a slash. That means the users will still have to complete
+       # after, so we gain him one tab keystroke by immediately proposing the
+       # next completion alternatives
+       local i=${#COMPREPLY[*]}
+       if [[ $i -gt 0 ]] && [[ "${COMPREPLY[$((--i))]}" == */ ]]; then
+               # we have to iterate throught the list as we may have duplicate
+               while [[ $i -ne 0 ]]; do
+                       [[ "${COMPREPLY[$i]}" != "${COMPREPLY[$((i - 1))]}" ]] 
&& break
+                       ((i--))
+               done
+               if [[ $i -eq 0 ]]; then
+                       _smf_complete_fmri "${COMPREPLY[0]}" "$prefix"
+                       return 0
+               fi
+       fi
+
+       # Work-around bash_completion issue where bash interprets a colon
+       # as a separator, borrowed from maven completion code which borrowed
+       # it from darcs completion code :)
+       local colonprefixes=${cur%"${cur##*:}"}
+       local i=${#COMPREPLY[*]}
+       while [ $((--i)) -ge 0 ]; do
+               COMPREPLY[$i]=${COMPREPLY[$i]#"$colonprefixes"}
+       done
+}
+
+_svcadm ()
+{
+       local cur prev words cword 
+       _init_completion -n : || return
+
+        local command_list="enable disable restart refresh clear mark 
milestone"
+        local command i
+
+       for (( i=1; i < $cword; i++ )); do
+                if [[ ${words[i]} == 
@(enable|disable|restart|refresh|clear|mark|milestone) ]]; then
+                        command=${words[i]}
+                fi
+        done
+
+        if [[ -z "$command" ]]; then
+                if [[ ${cur} == -* ]] ; then
+                        COMPREPLY=( $(compgen -W "-v" -- ${cur}) )
+                else
+                        COMPREPLY=( $(compgen -W "$command_list" -- ${cur}) )
+                fi
+        else
+               if [[ ${cur} == -* ]]; then
+                       case "$command" in
+                        enable)
+                               COMPREPLY=( $(compgen -W "-r -s -t" -- ${cur}) 
);;
+                        disable)
+                               COMPREPLY=( $(compgen -W "-s -t" -- ${cur}) );;
+                       mark)
+                               COMPREPLY=( $(compgen -W "-I -t" -- ${cur}) );;
+                       milestone)
+                               COMPREPLY=( $(compgen -W "-d" -- ${cur}) );;
+                       esac
+               else
+                       if [[ "$command" == "mark" ]] && [[ "$prev" != 
@(degraded|maintenance) ]]; then
+                               COMPREPLY=( $(compgen -W "degraded maintenance" 
-- ${cur}) )
+                       elif [[ "$command" == "milestone" ]]; then
+                               _smf_complete_fmri "${cur}" "svc:/milestone"
+                       else
+                               _smf_complete_fmri "${cur}" "svc:"
+                        fi
+                fi
+        fi
+} &&
+complete -F _svcadm svcadm
+

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

_______________________________________________
devel mailing list
[email protected]
https://lists.opencsw.org/mailman/listinfo/devel

Reply via email to