zsh-workers
 help / color / mirror / code / Atom feed
* Fink completion
@ 2004-11-12 10:41 Motoi Washida
  2004-11-12 12:01 ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Motoi Washida @ 2004-11-12 10:41 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 387 bytes --]

Hi,

I wrote Fink completion. Fink is a package management system on Mac OS 
X. Could you add this completion to main zsh trunk if there is no 
problem?

William Scott and Wataru Kagawa gave me advices to complete correctly.

And could you add new completion I submitted before?

http://www.zsh.org/mla/workers/2004/msg00923.html

And I modified some files after that.
--
Motoi Washida


[-- Attachment #2: _fink --]
[-- Type: application/octet-stream, Size: 5350 bytes --]

#compdef fink

_fink_get_packages_with_cache(){
  local cache_policy
  zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
  if [[ -z "$cache_policy" ]]; then
    zstyle ":completion:${curcontext}:" cache-policy _finkpkgs_caching_policy
  fi

  typeset -g -a _fink_pkgs
  local expl

  if ( (( #_fink_pkgs == 0 )) || _cache_invalid finkpkgs) \
       && ! _retrieve_cache finkpkgs; then
    _fink_pkgs=(${(f)"$(
      command fink list --tab \
      | command grep -v '\[virtual package\]' \
      | command sed 's/^   / n /' \
      | command cut -f1,2
    )"})
    _store_cache finkpkgs _fink_pkgs
  fi

  if (( # > 0 )); then
    local i
    for i in "$@"; do
      case "$i" in
        -i) packages+=(${${(M)_fink_pkgs:#?i?*}#*	}) ;;
        -o) packages+=(${${(M)_fink_pkgs:#(i)*}#*	}) ;;
        -n) packages+=(${${(M)_fink_pkgs:# n *}#*	}) ;;
      esac
    done
  else
    packages=(${_fink_pkgs#*	})
  fi
}

_fink_get_packages_without_cache(){
  local expl

  packages=(${(f)"$(
    command fink list -t "$@" "$PREFIX" \
    | command grep -v '\[virtual package\]' \
    | command cut -f2
  )"})
}

_fink_get_packages(){
  # variable packages will be set
  if zstyle -t ":completion:${curcontext}:" use-cache; then
    _fink_get_packages_with_cache "$@"
  else
    _fink_get_packages_without_cache "$@"
  fi
}

_finkpkgs_caching_policy(){
  oldp=( "$1"(Nmw+1) )
  (( $#oldp )) ||
    [[ /sw/var/cache/apt/pkgcache.bin -nt "$1" ]] ||
    [[ /sw/var/lib/dpkg/available -nt "$1" ]]
}

_fink(){
  local -a _1st_arguments
  _1st_arguments=(
    'install:install or update packages'
    'remove:remove packages'
    'purge:remove packages and configuration files'
    'update-all:update all installed packages to the latest version'
    'list:search package name or conditions and list'
    'apropos:search package descriptions or conditions and list'
    'describe:display a description of the package'
    'fetch:download package source files'
    'fetch-all:downloads all package source files'
    'fetch-missing:download all missing package source files'
    'build:build .deb packages'
    'rebuild:rebuild .deb packages'
    'reinstall:reinstall packages'
    'configure:rerun the fink configuration process'
    'selfupdate:upgrade to a new fink release'
    'validate:validate files'
    'scanpackages:call dpkg-scanpackages'
    'checksums:validate the MD5 digest of all tarballs'
    'cleanup:removes obsolete package files'
  )

  local context state line expl
  local -A opt_args

  _arguments \
    '(-h --help)'{-h,--help}'[display help text]' \
    '(-q --quiet)'{-q,--quiet}'[causes fink to be less verbose]' \
    '(-V --version)'{-V,--version}'[display version information]' \
    '(-v --verbose)'{-v,--verbose}'[causes fink to be more verbose]' \
    '(-y --yes)'{-y,--yes}'[assume default answer for interactive questions]' \
    '*:: :->subcmds' && return 0

  if (( CURRENT == 1 )); then
    _describe -t commands "fink subcommand" _1st_arguments
    return
  fi

  local -a packages

  case "$words[1]" in
    install|update|enable|activate|use)
      _fink_get_packages -n -o
      _wanted packages expl 'not installed or outdated fink package' compadd -a packages ;;
    remove|disable|deactivate|unuse|delete|purge)
      _fink_get_packages -i
      _wanted packages expl 'installed package' compadd -a packages ;;
    #update-all)
    list)
      _arguments \
	'(-t --tab)'{-t,--tab}'[outputs list with tabs as field delimiter]' \
        '(-i --installed)'{-i,--installed}'[packages currently installed]' \
        '(-u --uptodate)'{-u,--uptodate}'[packages up to date]' \
        '(-o --outdate)'{-o,--outdated}'[packages newer version is available]' \
        '(-n --notinstalled)'{-n,--notinstalled}'[packages not installed]' \
	'(-b --buildonly)'{-b,--buildonly}'[packages Build Only Depends]' \
	'(-s --section)'{-s=,--section=}'[sections]:section name' \
	'(-m --maintainer)'{-m=,--maintainer=}'[maintainer]:maintainer name' \
	--tree='[tree]:tree name' \
	'(-w --width)'{-w=,--width=}'[width of display]:number or "auto"' \
	'(1 : -)'{-h,--help}'[display help text]' \
	'1: :->pkgs' && return 0

        if [[ "$state" == pkgs ]]; then
          _fink_get_packages
          _wanted packages expl 'package name hint' compadd -a packages
        fi ;;
    apropos)
      _arguments \
        '(-t --tab)'{-t,--tab}'[output the list with tabs as field delimiter]' \
        '(-w --width)'{-w=,--width=}'[width of display]:number or "auto"' \
        '(1 : -)'{-h,--help}'[display help text]' \
        '1: :->pkgs' && return 0
        
        if [[ "$state" == pkgs ]]; then
          _fink_get_packages
          _wanted packages expl 'package hint' compadd -a packages
        fi ;;
    describe|desc|description|info)
      _fink_get_packages
      _wanted packages expl 'package' compadd -a packages ;;
    #fetch)
    #fetch-all)
    fetch-missing)
      _arguments \
        '(-i --ignore-restrictive)'{-i,--ignore-restrictive}'[do not fetch packages that are "License: Restrictive"]' ;;
    #build)
    rebuild|reinstall)
      _fink_get_packages
      _wanted packages expl 'package' compadd -a packages ;;
    #configure)
    #selfupdate)
    validate|check)
      _wanted files expl 'finkinfo file' _files -g \*.info ;;
    #scanpackages)
    #checksums)
    #cleanup)
  esac
}

_fink "$@"

[-- Attachment #3: completion_for_mac_2004_11_12.patch --]
[-- Type: application/octet-stream, Size: 4065 bytes --]

diff -dur /Users/wm3/Desktop/hoge/_hdiutil Command/_hdiutil
--- /Users/wm3/Desktop/hoge/_hdiutil	Sat Oct 30 17:17:08 2004
+++ Command/_hdiutil	Sat Nov  6 14:25:59 2004
@@ -4,11 +4,10 @@
 #
 _hdiutil_disk() {
   local -a disk_desc
-  _call_program disks /bin/df | while read; do
+  _call_program devices hdiutil info | while read; do
     local disk_name="${${(M)REPLY[(w)1]%/dev/disk*}#/dev/}"
-    local mount_point="/${REPLY#*%*/}"
-    if [[ -n "$disk_name" && "$mount_point" != "/" ]]; then
-      disk_desc+=( $disk_name:$mount_point )
+    if (( #disk_name )); then
+      disk_desc+=( "$disk_name:${${(M)REPLY%	*}#?}" )
     fi
   done
   _describe -t devices disks disk_desc
diff -dur /Users/wm3/Desktop/hoge/_open Command/_open
--- /Users/wm3/Desktop/hoge/_open	Sat Oct 30 17:17:04 2004
+++ Command/_open	Fri Nov 12 19:21:02 2004
@@ -3,8 +3,8 @@
 _open_absolute_application_path() {
   local expl curcontext
   zstyle -T ":completion:${curcontext}:files" prefix-needed && \
-    [[ "$PREFIX" != /* && compstate[nmatches] -ne 0 ]] && return 1
-  _wanted files expl 'application file' _path_files -P / -W /
+    [[ "$PREFIX" != [/~]* && compstate[nmatches] -ne 0 ]] && return 1
+  _wanted files expl 'application file' _path_files -P "$PREFIX[1]" -W /
 }
 
 _open() {
@@ -13,6 +13,7 @@
   _arguments -C \
     '-a[specify application]: :->open_mac_applications' \
     '-e[open with TextEdit]' \
+    '-f[Reads input from standard input and opens with TextEdit]' \
     '*: :->open_files'
 
   case "$state" in
@@ -25,7 +26,7 @@
       local app
       if [[ -n "$words[(r)-a]" ]]; then
         app="${(Q)words[words[(i)-a] + 1]}"
-      elif [[ -n "$words[(r)-e]" ]]; then
+      elif [[ -n "$words[(r)-e]" || -n "$words[(r)-f]" ]]; then
         app="Text Edit"
       fi
       if [[ -n "$app" ]]; then
diff -dur /Users/wm3/Desktop/hoge/_mac_applications Type/_mac_applications
--- /Users/wm3/Desktop/hoge/_mac_applications	Sat Oct 30 17:17:14 2004
+++ Type/_mac_applications	Fri Nov 12 19:19:28 2004
@@ -1,15 +1,6 @@
 #autoload
 
-_mac_applications() {
-  [[ $PREFIX = */* ]] && return 1
-
-  _retrieve_mac_apps
-
-  local -a mac_apps
-  mac_apps=( ${_mac_apps[*]:t:r} )
-
-  local expl
-  _wanted commands expl 'Mac OS X application' compadd -a mac_apps
-}
+_retrieve_mac_apps
 
-_mac_applications "$@"
+local expl
+_wanted commands expl 'Mac OS X application' compadd -- "${(@)${_mac_apps[@]:t}%.app}"
diff -dur /Users/wm3/Desktop/hoge/_retrieve_mac_apps Type/_retrieve_mac_apps
--- /Users/wm3/Desktop/hoge/_retrieve_mac_apps	Sat Oct 30 21:49:30 2004
+++ Type/_retrieve_mac_apps	Sat Nov  6 18:42:54 2004
@@ -26,7 +26,7 @@
     then
       typeset -a app_dir_stop_pattern app_dir_root
       app_dir_stop_pattern=( "*.app" "contents#" "*data" "*plugins#" "*plug?ins#" "fonts#" "document[[:alpha:]]#" "*help" "resources#" "images#" "*configurations#" )
-      app_dir_root=( {,/Developer,/Network,"$HOME"}/{Applications*,Desktop} )
+      app_dir_root=( {,/Developer,/Network,"$HOME"}/{Applications*(N),Desktop} )
       typeset app_dir_pattern
       app_dir_pattern="(^(#i)(${(j/|/)app_dir_stop_pattern}))"
       app_dir=( ${^app_dir_root}/(${~app_dir_pattern}/)#(N) )
@@ -41,12 +41,14 @@
       _mac_apps+=( ${app_result[@]%/Contents/MacOS*} )
     fi
 
-    # Get classic application files
-    if ! zstyle -t ":completion:${curcontext}:commands" ignore-classic; then
+    # Get single file applications
+    if ! zstyle -t ":completion:${curcontext}:commands" ignore-single; then
       autoload -U zargs
-      local app_cand
-      app_cand=( ${^app_dir}^*.[a-z]#(.UrN,.RN^U) )
-      app_result="$(zargs --max-chars $((1024<<17)) ${^app_cand}/..namedfork/rsrc -- grep -l APPL)"
+      local app_cand nargs envvars
+      app_cand=( ${^app_dir}^*.[a-z]#/..namedfork/rsrc(.UrN,.RN^U) )
+      envvars="$(builtin typeset -x)"
+      nargs=$(( $(command sysctl -n kern.argmax) - $#envvars - 2048 ))
+      app_result="$(zargs --max-chars $nargs ${app_cand[@]} -- grep -l APPL)"
       _mac_apps+=( ${${(f)app_result}%/..namedfork/rsrc} )
     fi
 

[-- Attachment #4: Type: text/plain, Size: 1 bytes --]



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

* Re: Fink completion
  2004-11-12 10:41 Fink completion Motoi Washida
@ 2004-11-12 12:01 ` Peter Stephenson
  2004-11-13  9:34   ` Motoi Washida
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2004-11-12 12:01 UTC (permalink / raw)
  To: zsh-workers

Motoi Washida wrote:
> I wrote Fink completion. Fink is a package management system on Mac OS 
> X. Could you add this completion to main zsh trunk if there is no 
> problem?
> 
> William Scott and Wataru Kagawa gave me advices to complete correctly.
> 
> And could you add new completion I submitted before?
> 
> http://www.zsh.org/mla/workers/2004/msg00923.html
> 
> And I modified some files after that.

I've added all this.

I put it all under Darwin, since it modifies some files there, although
you definitely said Mac OS X specfically.  I doubt this is significant.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: Fink completion
  2004-11-12 12:01 ` Peter Stephenson
@ 2004-11-13  9:34   ` Motoi Washida
  0 siblings, 0 replies; 3+ messages in thread
From: Motoi Washida @ 2004-11-13  9:34 UTC (permalink / raw)
  To: zsh-workers

On 2004/11/12, at 21:01, Peter Stephenson wrote:

> Motoi Washida wrote:
>> I wrote Fink completion. Fink is a package management system on Mac OS
>> X. Could you add this completion to main zsh trunk if there is no
>> problem?
>>
>> William Scott and Wataru Kagawa gave me advices to complete correctly.
>>
>> And could you add new completion I submitted before?
>>
>> http://www.zsh.org/mla/workers/2004/msg00923.html
>>
>> And I modified some files after that.
>
> I've added all this.
Thanks!

> I put it all under Darwin, since it modifies some files there, although
> you definitely said Mac OS X specfically.  I doubt this is significant.
I did not think of that at all.

All completions under Completion/Darwin/Command except _fink seems to 
be Mac OS X specific. Those commands use Mac OS X specific libraries. I 
don't know whether Fink supports Darwin. It seems there are no reason 
Fink doesn't work on Darwin, although I don't know well about Fink.

Completions under Completion/Darwin/Type should work on Darwin, but I 
don't think they are useful without Mac OS X, since they complete 
applications for Mac OS X or files used by applications for Mac OS X.

--
Motoi Washida


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

end of thread, other threads:[~2004-11-13  9:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-12 10:41 Fink completion Motoi Washida
2004-11-12 12:01 ` Peter Stephenson
2004-11-13  9:34   ` Motoi Washida

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