zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] OpenSolaris IPS completion 2.0 (complete rewrite/almost complete)
@ 2008-09-14  1:32 "xRaich[o]²x"
  0 siblings, 0 replies; only message in thread
From: "xRaich[o]²x" @ 2008-09-14  1:32 UTC (permalink / raw)
  To: zsh-workers

Hi,

I rewrote the script i sent yesterday. This one is almost complete and 
uses more of the compsys abilities. Would be cool if someone could help 
me on the other options.

Regards,
Björn

#compdef pkg

local state
ret=1

_arguments -s '-R[image]:image:_directories' '*::command:->command' && ret=0

#TODO use pkg interface
function all_packages
{
    compadd $(awk '{print $3}' $(find /var/pkg/catalog -name catalog 
-type f) | sort -u)
}

function installed_packages
{
    compadd $(/usr/bin/ls /var/pkg/state/installed | cut -d@ -f1)
}

function get_auth
{
    compadd $(find /var/pkg/catalog/ -type d | sed 1d | cut -d/ -f5) && 
ret=0
}

while [[ -n "$state" ]]; do
    tmp=$state
    state=
    case $tmp in
    command)
        if (( CURRENT == 1 )); then
            state=subcommands
        else
            echo ${words[1]} ${tmp} > /dev/pts/6
            cmd="$words[1]"
            curcontext="${curcontext%:*:*}:pkg-${cmd}:"
            case $cmd in
                install)
                    _arguments -s \
                        '-n[no changes]::all_packages' \
                        '-v[verbose]::all_packages' \
                        '-q[quiet]::all_packages' \
                        '*::command:all_packages' && ret=0
                    ;;
                uninstall)
                    _arguments -s \
                        '-n[no changes]::installed_packages' \
                        '-v[verbose]::installed_packages' \
                        '-q[quiet]::installed_packages' \
                        '-r[recursive]::installed_packages' \
                        '*::command:installed_packages' && ret=0
                    ;;
                search)
                    _arguments -s \
                        '-l[local search]' \
                        '-r[remote search]' \
                        '-I[case sensitive]'  && ret=0
                    ;;
                info)
                    _arguments  \
                        '-l[local package]::installed_packages' \
                        '-r[remote package]::all_packages' \
                        '*::command:installed_packages' && ret=0
                    #TODO --license
                    ;;
                verify)
                    _arguments \
                        '-v[verbose]::installed_packages' \
                        '-H[omit headers]::installed_packages' \
                        '-q[quiet]::installed_packages' \
                        '*::command:installed_packages' && ret=0
                    ;;
                contents)
                    _arguments -s \
                        '-r[remote package]::all_packages' \
                        '-H[omit headers]::installed_packages' \
                        '-m[bla]::installed_packages' \
                        '*::command:installed_packages' && ret=0
                    #TODO rest of options
                    ;;
                list)
                    _arguments -s \
                        '-a[all]::all_packages' \
                        '-H[omit header]::all_packages' \
                        '-s[display short-form]::all_packages' \
                        '-u[display only newer packages]::all_packages' \
                        '-v[display full FMRI]::all_packages' \
                        '*::command:all_packages' && ret=0
                    ;;
                image-update)
                    _arguments -s \
                        '-n[no changes]' \
                        '-v[verbose]' \
                        '-q[quite]' && ret=0
                    ;;
                authority)
                    _arguments -s \
                        '-H[omit header]::get_auth' \
                        '-P[]::get_auth' \
                        '*::command:get_auth' && ret=0
                    ;;
                unset-authority)
                    get_auth && ret=0
                    ;;
                refresh)
                    _arguments -s \
                        '--full[full refresh]::get_auth' \
                        '*::command:get_auth' && ret=0
                    ;;
                image-create)
                    #TODO options
                    ;;
                set-authority)
                    _arguments '-O[origin URL]'
                    #TODO rest of options
                    ;;
                rebuild-index|version|help)
                    ;;
            esac
        fi
        ;;
    subcommands)
        cmds=(
         'install:install a package'
         'uninstall:uninstall a package'
         'verify:verify a package'
         'info:fetch package info'
         'contents:show package contents'
         'list:list installed packages'
         'search:search for a package'
         'refresh:refresh catalogues'
         'image-create:create new image'
         'image-update:update an image'
         'set-authority:set an authority'
         'unset-authority:unset an authority'
         'authority:list authorities'
         'rebuild-index:rebuild index'
        )
        _describe 'pkg command' cmds -- && ret=0    
        ;;
    esac
done

#clean up
unfunction installed_packages
unfunction all_packages
unfunction get_auth

return ret


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-09-14  1:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-14  1:32 [PATCH] OpenSolaris IPS completion 2.0 (complete rewrite/almost complete) "xRaich[o]²x"

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).