zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] completion for opensolaris IPS package manager
@ 2008-09-13 15:21 "xRaich[o]²x"
  2008-09-13 15:58 ` Danek Duvall
  0 siblings, 1 reply; 4+ messages in thread
From: "xRaich[o]²x" @ 2008-09-13 15:21 UTC (permalink / raw)
  To: zsh-workers

I started working on some scripts for opensolaris commands (zpool, zfs, 
beadm and more are in the works). Here is the first for package 
management. It's still pretty basic but supports the features that are 
used the most (or at least i use the most ^^)

#compdef pkg

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'
)

_pkg () {
    ret=1
    SHIFTER=0
    if [[ $words[2] == "-R" ]]; then
        if (( CURRENT == 3 )); then
            _directories && ret=0
            return ret
        elif (( CURRENT >= 4 )); then
            SHIFTER=2
        fi
    fi

    if (( CURRENT-SHIFTER == 2 )); then
        _describe 'pkg command' cmds && ret=0
    else
        case ${words[$(( 2 + SHIFTER ))]} in
            install)
                compadd $(awk $'{print $3}' $(find /var/pkg/catalog 
-name catalog -type f) | sort -u) && ret=0
                ;;
            uninstall|verify)
                compadd $(/usr/bin/ls /var/pkg/state/installed | cut -d@ 
-f1) && ret=0
                ;;
            search|info|contents)
                if [[ $words[$(( 3 + SHIFTER ))] == "-r" ]]; then
                    compadd  $(awk $'{print $3}' $(find /var/pkg/catalog 
-name catalog -type f) | sort -u) && ret=0
                else
                    compadd  $(/usr/bin/ls /var/pkg/state/installed | 
cut -d@ -f1) && ret=0
                fi
                ;;
            refresh|unset-authority)
                compadd $(find /var/pkg/catalog/ -type d | sed 1d | cut 
-d/ -f5) && ret=0
        esac
    fi
    return ret
}

Regards,
Björn


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] completion for opensolaris IPS package manager
  2008-09-13 15:21 [PATCH] completion for opensolaris IPS package manager "xRaich[o]²x"
@ 2008-09-13 15:58 ` Danek Duvall
  2008-09-13 16:27   ` "xRaich[o]²x"
  0 siblings, 1 reply; 4+ messages in thread
From: Danek Duvall @ 2008-09-13 15:58 UTC (permalink / raw)
  To: xRaich[o]²x; +Cc: zsh-workers

On Sat, Sep 13, 2008 at 05:21:22PM +0200, "xRaich[o]²x" wrote:

> I started working on some scripts for opensolaris commands (zpool, zfs, beadm 
> and more are in the works).

Completion functions for zpool and zfs are already in the zsh distribution,
and part of opensolaris (as of build 96), so there's no need to rewrite
those (though perhaps they need enhancement).

> #compdef pkg

You keep looking at files under /var/pkg.  These are private interfaces
which could change at any time.  You'd be better off using "pkg list" to
get this information, though you'll probably need to stick the information
in a cache.

Also, "search" doesn't take package names, so it doesn't belong in the same
clause as info and contents.

Thanks!

Danek


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] completion for opensolaris IPS package manager
  2008-09-13 15:58 ` Danek Duvall
@ 2008-09-13 16:27   ` "xRaich[o]²x"
  2008-09-13 16:49     ` Danek Duvall
  0 siblings, 1 reply; 4+ messages in thread
From: "xRaich[o]²x" @ 2008-09-13 16:27 UTC (permalink / raw)
  To: zsh-workers

Danek Duvall wrote:
> On Sat, Sep 13, 2008 at 05:21:22PM +0200, "xRaich[o]²x" wrote:
>
>   
>> I started working on some scripts for opensolaris commands (zpool, zfs, beadm 
>> and more are in the works).
>>     
>
> Completion functions for zpool and zfs are already in the zsh distribution,
> and part of opensolaris (as of build 96), so there's no need to rewrite
> those (though perhaps they need enhancement).
>
>   
>> #compdef pkg
>>     
>
> You keep looking at files under /var/pkg.  These are private interfaces
> which could change at any time.  You'd be better off using "pkg list" to
> get this information, though you'll probably need to stick the information
> in a cache.
>
> Also, "search" doesn't take package names, so it doesn't belong in the same
> clause as info and contents.
>
> Thanks!
>
> Danek
>
>   

I didn't use pkg info because its very slow. i know there is a cache 
function in zsh completion somewhere but this is actually the first 
shellscript i ever really wrote ^^.

Thanks for the pointer with zfs und zpool, didn't know that.

Regards,
Björn


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] completion for opensolaris IPS package manager
  2008-09-13 16:27   ` "xRaich[o]²x"
@ 2008-09-13 16:49     ` Danek Duvall
  0 siblings, 0 replies; 4+ messages in thread
From: Danek Duvall @ 2008-09-13 16:49 UTC (permalink / raw)
  To: xRaich[o]²x; +Cc: zsh-workers

On Sat, Sep 13, 2008 at 06:27:48PM +0200, "xRaich[o]²x" wrote:

> I didn't use pkg info because its very slow.

list, not info.  We made some performance improvements as of build 94.
"pkg list" now takes about two seconds on my machine, and "pkg list -a"
takes about three.  It could be faster, certainly, but for a first-time
startup cost, it's not bad at all, though certainly running it every time
would be pretty painful.  And in the next build or two, there'll be a
history command that will let you safely determine whether the cache is
invalid.

> i know there is a cache function in zsh completion somewhere but this is
> actually the first shellscript i ever really wrote ^^.

Hey, it's a good start!

Thanks,
Danek


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-09-13 16:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-13 15:21 [PATCH] completion for opensolaris IPS package manager "xRaich[o]²x"
2008-09-13 15:58 ` Danek Duvall
2008-09-13 16:27   ` "xRaich[o]²x"
2008-09-13 16:49     ` Danek Duvall

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).