Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

some completion functions :)



Hi,
I've written some completion function for :
rar, unrar (_rar)
oggenc, ogginfo, oggdec, ogg123 (_vorbis)
I've updated _links to work with links >= 2.X
I've improved _pkgtool 
Sory, no path because I've overwritten the different scripts :(

I've tested it under gentoo 1.4 with zsh 4.0.6 and slackware 9.1 with
zsh 4.0.7 and zsh 4.1.1

Normaly all works :)

-- 
baptiste daroussin <daroussi@xxxxxx>
#compdef links

local curcontext="$curcontext" state line
typeset -A opt_args

_arguments -C \
       '-async-dns[Asynchronous DNS resolver]:bool:(0 1)' \
       '-max-connections[Maximum number of concurrent connections.]:max:' \
       '-max-connections-to-host[Maximum number of concurrent connection to a given host.]:max:' \
       '-retries[Number of retries.]:retries:' \
       '-receive-timeout[Timeout on receive.]:secs:' \
       '-unrestartable-receive-timeout[Timeout on non restartable connections.]:secs:' \
       '-format-cache-size[Number of formatted document pages cached.]:pages:' \
       '-memory-cache-size[Cache memory in bytes.]:kilobytes:' \
       '-image-cache-size[Cache memory in bytes.]:kilobytes:'\
       '-http-proxy[Host and port number of the HTTP proxy, or blank.]:hostport:_hosts' \
       '-ftp-proxy[Host and port number of the FTP proxy, or blank.]:hostport:_hosts' \
       '-download-dir[Default download directory.]:_files -/' \
       '-assume-codepage[Use the given codepage when the webpage did not specify its codepage.]:codepage:' \
       '-anonymous[Restrict links so that it can run on an anonymous account.]' \
       '-no-connect[Runs links as a separate instance - instead of connecting to existing instance.]' \
       '-version[Prints the version number.]' \
       '-help[Display help]' \
       '-g[Run in graphics mode]'\
       '-driver[Graphics driver to use.]:drivers:(x svgalib fb pmshell atheos)'\
       '-mode[Graphics mode.]:mode:'\
       ':url:->html' && return 0

case "$state" in
html)
  _files -g '*.html' || _urls
  ;;
esac
#compdef installpkg upgradepkg removepkg pkgtool explodepkg makepkg 

_slackware_pkg() {
  local flags

  case "$service" in
  installpkg)
    flags=(
      '-warn[warn if files will be overwritten, but do not install]'
      '-root=[install someplace else, like /mnt]:Root directory:_path_files -/'
      '-infobox[use dialog to draw an info box]'
      '-menu[confirm package installation with a menu]'
      '-ask[used with menu mode: always ask if a package should be installed regardless of what the package'\''s priority is]'
      '-priority[provide a priority for the entire package list to use instead of the priority in the tagfile]:Priority list:(ADD REC OPT SKP)'
      '-tagfile[specify a different file to use for package priorities.  The default is "tagfile" in the package'\''s directory]:Tagfile:_files -/'
    )

    _arguments -s \
      $flags[@] \
      '*:Slackware packages:_files -g \*.tgz'
    ;;

  removepkg)
    flags=(
      '-warn[Generate  a  report  to  the  standard output about which files and directories would be removed, but does not actually remove the package.]'
      '-preserve[If specified, the complete package subtree is reconstructed in /tmp/preserved_packages/packagename.]'
      '-copy[Construct a copy of the package under /tmp/preserved_packages/packagename, but don'\''t remove it.  (same effect as -warn -preserve)]'
      '-keep[Save the  intermediate  files  created  by  removepkg  (delete_list,  required_files,  uniq_list,  del_link_list,  required_links, required_list).  Mostly useful for debugging purposes.]'
    )

    _arguments -s \
      $flags[@] \
      '*:Package name:_files -W /var/log/packages/ -/'
    ;;

  upgradepkg)
    flags=(
      '--install-new[the behavior is modified to install new packages in addition to upgrading existing ones.]'
      '--reinstall[upgrade all packages even if the same version is already installed.]'
      '--verbose[Show all the gory details of the upgrade.]'
    )


    _arguments -s \
      $flags[@] \
      '*:Slackware packages:_files -g \*.tgz'
    ;;

    
  explodepkg)
    _arguments -s \
    '*:Slackware packages:_files -g \*.tgz'
    ;;

  makepkg)
    flags=(
      '(--linkadd -l)'{--linkadd,-l}'[moves symlinks into doinst.sh: recommended]:Answer:(y n)'
      '(--chown -c)'{--chown,-c}'[resets all permissions to root:root 755 - not generally recommended]:Answer:(y n)'
    )


    _arguments -s \
      $flags[@] 
    ;;



  pkgtool)
    flags=(
    '-sets[Install the disk sets A, B, C. Seperate the disk set names by '\''#'\'' symbols.]'
    '-source_mounted[When this flag is present, pkgtool will not attempt to unmount and remount the source device with each disk.]'
    '-ignore_tagfile[When this flag is present, pkgtool will install every *.tgz package encountered no matter what the tagfiles say.]'
    '-tagfile[This flag is used to specify from the command line which tagfile should be used for the installation.]:Tagfile:_files -/'
    '-source_dir[Used  when installing multiple packages from disk sets. This is the directory in which the subdirectories for each disk are found.]:Source directory:_path_files -/'
    '-target_dir[The directory where the target root directory is located. This is '/' when installing on the hard drive, or typically '\''/mnt'\''  when installing from an install disk.]:Target directory:_path_files -W -/'
    '-source_device[The source device to install from. This is not used if you'\''ve provided the -source_mounted flag. It'\''s usually used when installing from floppy.]:Source device:{compadd "$expl[@]" /dev/*}'
    )
    _arguments -s \
      $flags[@] 
      ;;
  esac
}

_slackware_pkg "$@"
#compdef rar unrar


_rar(){
    case $service in
        rar)
        _arguments -s \
        '*::rar command:_rar_command' 
        ;;
    unrar)
        _arguments -s \
        '*::unrar command:_unrar_command'
        ;;
    esac
}

_compression_level() {
    compression_level=
    _tags compression_level && { compadd "$@" -k compression_level || compadd "$@" ${(kv)=compression_level} }
}

_dico_size() {
    dico_size=(64 128 256 512 1024 2048 4096 a b c d e f g)
    _tags dico_size && { compadd "$@" -k dico_size || compadd "$@" ${(kv)=dico_size} }
}

_unrar_command () {
    cmd=(e l lt p t v vt x)
    if (( CURRENT == 1 ));then
        _tags cmd && { compadd "$@" -k cmd || compadd "$@" ${(kv)=cmd} }
    else
        _arguments -C  \
            '-ad[Append archive name to destination path]'\
            '-ap[Set path inside archive]'\
            '-av\-[Disable authenticity verification check]'\
            '-c\-[Disable comments show]'\
            '-cfg\-[Disable read configuration]'\
            '-cl\-[Convert names to lower case]'\
            '-cu[Convert names to upper case]'\
            '-dh[Open shared files]'\
            '-ep[Exclude paths from name]'\
            '-f[Freshen files]'\
            '-idp[Disable percentage display]'\
            '-ierr[Send all messages to stderr]'\
            '-inul[Disable all messages]'\
            '-kb[Keep broken extracted files]'\
            '-o\+[Overwrite existing files]'\
            '-o\-[Do not overwrite existing files]'\
            '-ow[Save or restore file owner and group]'\
            '-p\-[Do not query password]'\
            '-r[Recurse subdirectorie]'\
            '-ta[Process files modified after <date> in YYYYMMDDHHMMSS format]'\
            '-tb[Process files modified before <date> in YYYYMMDDHHMMSS format]'\
            '-tn[Process files newer than <time>]'\
            '-to[Process files older than <time>]'\
            '-u[Update files]'\
            '-v[Create volumes with size autodetection or list all volumes]'\
            '-ver[File version control]'\
            '-vp[Pause before each volume]'\
            '-x[Exclude specified file]'\
            '-y[Assume Yes on all queries]'\
            '*:RAR files:_files -g \*.rar' && return 0
    fi
}

_rar_command () {
    cmd=(a c cf cw d e f i k l lt m mf p r rc rr rv s t u v vt x)
    if (( CURRENT == 1 ));then
        _tags cmd && { compadd "$@" -k cmd || compadd "$@" ${(kv)=cmd} }
    else
        _arguments -s \
            '-ad[Append archive name to destination path]'\
            '-ag[Generate archive name using the current date]'\
            '-ap[Set path inside archive]'\
            '-as[Synchronize archive contents]'\
            '-av[Put authenticity verification (registered versions only)]'\
            '-av\-[Disable authenticity verification check]'\
            '-c\-[Disable comments show]'\
            '-cfg\-[Disable read configuration]'\
            '-cl\-[Convert names to lower case]'\
            '-cu[Convert names to upper case]'\
            '-df[Delete files after archiving]'\
            '-dh[Open shared files]'\
            '-ds[Disable name sort for solid archive]'\
            '-e[Set file exclude attributes]'\
            '-ed[Do not add empty directories]'\
            '-en[Do not put end of archive block]'\
            '-ep[Exclude paths from name]'\
            '-ep1[Exclude base directory from names]'\
            '-ep2[Expand paths to full]'\
            '-f[Freshen files]'\
            '-hp[Encrypt both file data and headers]'\
            '-idp[Disable percentage display]'\
            '-ierr[Send all messages to stderr]'\
            '-ilog[Log errors to file (registered versions only)]'\
            '-inul[Disable all messages]'\
            '-isnd[Enable sound]'\
            '-k[Lock archive]'\
            '-kb[Keep broken extracted files]'\
            '-m+[Set compression level (0-store...3-default...5-maximal)]:compression level:(( 0\:store 1\:fastest 2\:fast 3\:normal 4\:good 5\:maximal ))'\
            '-md+[Dictionary size in KB]:dictionaty size in KB:_dico_size' \
            '-ms[Specify file types to store]'\
            '-o\+[Overwrite existing files]'\
            '-o\-[Do not overwrite existing files]'\
            '-ol[Save symbolic links as the link instead of the file]'\
            '-ow[Save or restore file owner and group]'\
            '-p[Set password]'\
            '-p\-[Do not query password]'\
            '-r[Recurse subdirectorie]'\
            '-r0[Recurse subdirectories for wildcard names only]'\
            '-rr[Add data recovery record]'\
            '-rv[Create recovery volumes]'\
            '-s[Create solid archive]'\
            '-se[Create solid archive using extension]'\
            '-sv[Create solid archive using volumes]'\
            '-s\-[Disable solid archiving]'\
            '-sfx[Create SFX archive]'\
            '-t[Test files after archiving]'\
            '-ta[Process files modified after <date> in YYYYMMDDHHMMSS format]'\
            '-tb[Process files modified before <date> in YYYYMMDDHHMMSS format]'\
            '-tk[Keep original archive time]'\
            '-tl[Set archive time to latest file]'\
            '-tn[Process files newer than <time>]'\
            '-to[Process files older than <time>]'\
            '-u[Update files]'\
            '-v[Create volumes with size autodetection or list all volumes]'\
            '-ver[File version control]'\
            '-vn[Use the old style volume naming scheme]'\
            '-vp[Pause before each volume]'\
            '-w+[Assign work directory]:work directory:_files -/'\
            '-x[Exclude specified file]'\
            '-y[Assume Yes on all queries]'\
            '-z+[Read archive comment from file]:comment file:_files' \
            '*:files:_files'
    fi
}
_rar "$@"
#compdef oggenc ogg123 ogginfo oggdec 

_vorbis (){
    case $service in
    oggenc)
        _arguments -C -s \
        '(--help)-h[Display help]'\
        '(-h)--help[Display help]'\
        '(--raw)-r[Assume input data is raw little-endian audio data with no header information.]'\
        '(-r)--raw[Assume input data is raw little-endian audio data with no header information.]'\
        '(--raw-bits=)-B[Sets raw mode input sample size in bits.]:sample size:(8 16)'\
        '(-B)--raw-bits=[Sets raw mode input sample size in bits.]:sample size:(8 16)'\
        '(--raw-chan=)-C[Sets raw mode input number of channels.]:number of channels:'\
        '(-C)--raw-chan=[Sets raw mode input number of channels.]:number of channels:'\
        '(--raw-rate=)-R[Sets raw mode input samplerate.]:samplerate:(44100 48000)'\
        '(-R)--raw-rate=[Sets raw mode input samplerate.]:samplerate:(44100 48000)'\
        '--raw-endianness[Sets raw mode endianness]:endianness:(0 1)'\
        '(--quiet)-Q[Quiet mode.  No messages are displayed.]'\
        '(-Q)--quiet[Quiet mode.  No messages are displayed.]'\
        '(--bitrate=)-b[Sets encoding to the bitrate closest to n (in kb/s).]'\
        '(-b)--bitrate=[Sets encoding to the bitrate closest to n (in kb/s).]'\
        '(--min-bitrate=)-m[Sets minimum bitrate to n (in kb/s).]'\
        '(-m)--min-bitrate=[Sets minimum bitrate to n (in kb/s).]'\
        '(--max-bitrate=)-M[Sets maximum bitrate to n (in kb/s).]'\
        '(-M)--max-bitrate=[Sets maximum bitrate to n (in kb/s).]'\
        '--managed[ Set bitrate management mode.  This  turns  off  the  normal  VBR encoding]'\
        '(--quality=)-q[Sets encoding quality to n, between -1 (low) and 10 (high).]:quality:(0 1 2 3 4 5 6 7 8 9 10)'\
        '(-q)--quality=[Sets encoding quality to n, between -1 (low) and 10 (high).]:quality:(0 1 2 3 4 5 6 7 8 9 10)'\
        '--resample[Resample input to the given sample rate (in Hz) before encoding.]'\
        '--downmix[ Downmix input from stereo to mono (has no effect  on  non-stereo streams).]'\
        '--advanced-encode-option[Sets  an  advanced  option.]:optionname:(bitrate_average_window lowpass_frequency)'\
        '(--serial)-s[Forces a specific serial number in the output  stream.]'\
        '(--output-file=)-o[Write the Ogg Vorbis stream to output_file]:output file:_files -g \*.ogg'\
        '(-o)-output-file=[Write the Ogg Vorbis stream to output_file]:output file:_files -g \*.ogg'\
        '(--pattern=)-n[Produce filenames as this string]'\
        '(-n)--pattern=[Produce filenames as this string]'\
        '*-c[Add the string comment as an extra comment.]'\
        '*--comment[Add the string comment as an extra comment.]'\
        '*-a[Set the artist comment field in the comments to artist.]'\
        '*--artist[Set the artist comment field in the comments to artist.]'\
        '*-G[Set the genre comment field in the comments to genre.]'\
        '*--genre[Set the genre comment field in the comments to genre.]'\
        '*-d[Sets the date comment field to the given value.]'\
        '*--date[Sets the date comment field to the given value.]'\
        '*-N[Sets the track number comment field to the given value.]'\
        '*--tracknum[Sets the track number comment field to the given value.]'\
        '*-t[Set the track title comment field to title.]'\
        '*--title[Set the track title comment field to title.]'\
        '*-l[Set the album comment field to album.]'\
        '*--album[Set the album comment field to album.]'\
        '*:wav file:_files -g \*.wav'
        ;;
    ogg123)
        _arguments -C -s \
        '(-h)--help[Dispaly help]'\
        '(--help)-h[Dispaly help]'\
        '(--version)-V[Display ogg123 version]'\
        '(-V)--version[Display ogg123 version]'\
        '(--device=)-d[Uses an output device]:device:{compadd "$expl[@]" /dev/*}'\
        '(-d)--device=[Uses an output device]:device:{compadd "$expl[@]" /dev/*}'\
        '(--files=)-f[Set the output filename for a previously specified file device \(with -d\)]:output filename:_files'\
        '(--files=)-f[Set the output filename for a previously specified file device \(with -d\)]:output filename:_files'\
        '(--skip)-k[Skip the first '\''n'\'' seconds]:seconds to skip:'\
        '(-k)--skip[Skip the first '\''n'\'' seconds]:seconds to skip:'\
        '(-o)--device-option=[Passes special option k with value v to previously specified device (with -d). See man page for more info.]'\
        '(--device-option=)-o[Passes special option k with value v to previously specified device (with -d). See man page for more info.]'\
        '(--buffer)-b[Use an input buffer of '\''n'\'' kilobytes]:kilobytes:'\
        '(-b)--buffer[Use an input buffer of '\''n'\'' kilobytes]:kilobytes:'\
        '(--prebuffer)-p[Load n% of the input buffer before playing]:percentage:'\
        '(-p)--prebuffer[Load n% of the input buffer before playing]:percentage:'\
        '(--verbose)-v[Display progress and other status information]'\
        '(-v)--verbose[Display progress and other status information]'\
        '(--quiet)-q[Don'\''t display anything (no title)]'\
        '(-q)--quiet[Don'\''t display anything (no title)]'\
        '(--nth)-x[Play every '\''n'\''th block]:'\''n'\''th block:'\
        '(-x)--nth[Play every '\''n'\''th block]:'\''n'\''th block:'\
        '(--ntimes)-y[Repeat every played block '\''n'\'' times]:times:'\
        '(-y)--ntimes[Repeat every played block '\''n'\'' times]:times:'\
        '(--shuffle)-z[Shuffle play]'\
        '(-z)--shuffle[Shuffle play]'\
        '(--delay=)-l[set s \[milliseconds\] (default 500).]:milliseconds:'\
        '(-l)--delay=[set s \[milliseconds\] (default 500).]:milliseconds:'\
        '(--playlist)-@[Play all of  the  files  named  in  the  file  '\''playlist'\''.]:Playlist:_files'\
        '(-@)--playlist[Play all of  the  files  named  in  the  file  '\''playlist'\''.]:Playlist:_files'\
        '--audio-buffer[Use an output audio buffer of approximately '\''n'\'' kilobytes.]:kilobytes:'\
        '*:ogg files:_files -g \*.ogg'
        ;;
    ogginfo)
        _arguments -C -s \
        '-h[Show a help and usage message]'\
        '-q[Quiet  mode. This may be specified multiple times.]'\
        '-v[Verbose mode.]'\
        '*:ogg files:_files -g \*.ogg'
        ;;
    oggdec)
        _arguments -C -s \
        '(--quiet)-q[Suppresses program output.]'\
        '(--quiet)-q[Suppresses program output.]'\
        '(--help)-h[Print help message.]'\
        '(--help)-h[Print help message.]'\
        '(--version)-v[Display version information.]'\
        '(-v)--version[Display version information.]'\
        '(--bits=)-b[Bits per sample.]:Bits per sample:(8 16)'\
        '(-b)--bits=[Bits per sample.]:Bits per sample:(8 16)'\
        '(--endian=)-e[Set endianness for 16-bit output.]:endianness:(( 0\:\(default\)\ is\ little-endian\ \(Intel\ byte\ order\). 1\:is\ big-endian\ \(sane\ byte\ order\). ))'\
        '(-e)--endian=[Set endianness for 16-bit output.]:endianness:(( 0\:\(default\)\ is\ little-endian\ \(Intel\ byte\ order\). 1\:is\ big-endian\ \(sane\ byte\ order\). ))'\
        '(--raw=)-R[Output  in  raw format.]'\
        '(-R)--raw=[Output in raw format.]'\
        '(--output=)-o[Write output to specified filename.]:output filename:_files'\
        '(-o)--output=[Write output to specified filename.]:output filename:_files'\
	'(--sign=)-s[Set signedness for output.]:signedness:(( 0\:unsigned 1\:signed\ \(default\) ))'\
	'(-s)--sign=[Set signedness for output.]:signedness:(( 0\:unsigned 1\:signed\ \(default\) ))'\
        '*:ogg files:_files -g \*.ogg'
        ;;
    esac
}

_vorbis "$@"


Messages sorted by: Reverse Date, Date, Thread, Author