[X-Unix] zsh / spotlight / application completion

Brian Medley bpm-list-osx-unix at 4321.tv
Wed Nov 16 08:46:35 PST 2005


I use zsh and want to have intelligent completion for open(1).  I
believe the command 

    $ compctl -f -x 'c[-1,-a]' -M 'b:=*' -k _apps -- open

provides this.  I believe what this does is:
    
    a) per default complete on filenames and directories
    b) iff the previous word is "-a" then perform completion
    using the _apps arrary.

This means that without "-a" filenames and directories are
completed and that _after_ the application has been completed
filenames and directories will be completed; therefore an
argument can supplied to the application.

To populate the _apps array I use:

    $ typeset -a _apps
    $ _apps=(${(f)"$(mdfind "kMDItemKind == 'Application'")"})

An example run is below.

[bpm at snafu] c:~>typeset -a _apps
[bpm at snafu] c:~>_apps=(${(f)"$(mdfind "kMDItemKind == 'Application'")"})
[bpm at snafu] c:~>echo ${#_apps}
398
[bpm at snafu] c:~>echo ${_apps[0]}
/Applications/iPhoto.app
[bpm at snafu] c:~>compctl -f -x 'c[-1,-a]' -M 'b:=*' -k _apps -- open
[bpm at snafu] c:~>open -a /Library/Application\ Support/Adobe/Workflow/Adobe\ Workgroup\ Helper
[bpm at snafu] c:~>open -a Photo
/Applications/Adobe\ Photoshop\ Elements\ 2/Photoshop\ Elements\ 2.0
/Applications/Hewlett-Packard/HP\ Photo\ and\ Imaging\ Software/HP\ E-mail\ Portal/HP\ E-mail\ Portal
...
/Applications/Hewlett-Packard/HP\ Photo\ and\ Imaging\ Software/HP\ Tools/HP\ Image\ Dropper.app
/Applications/iPhoto.app
/Library/Documentation/Applications/iPhoto/iPhoto\ Getting\ Started.app

-- 
~`^`'~=-._.-=~'`^`'~=-._.-=~'^'~=-., \|/  (___)  \|/ _,.-=~'`^`
                                      @~./'O o`\.~@
      "Knowledge is Power"           /__( \___/ )__\  *PPPFFBT!*
         -- Francis Bacon               `\__`U_/'
 _.-=~'``'~=-._.-=~'``'~=-._.-=~'`^`'~= <____|'  ^^`'~=-.,__,.-=
~'^`'~=-._.-=~'`^`'~=-._.-=~'^'~=-.,__,.-==--^'~=-.,__,.-=~'`^`


More information about the X-Unix mailing list