I was recently inspired to realize my goal of intelligent completion of the open(1) command using the built-in zsh facilities (man zshcompctl) and Spotlight. It is believed that the command...
To populate the _apps array, I use these commands:
compctl -f -x 'c[-1,-a]' -M 'b:=*' -k _apps -- open
...provides this. I believe what it does is:
- Per default completion on filenames and directories
- If the previous word is -a, then perform completion using the _apps arrary.
To populate the _apps array, I use these commands:
$ typeset -a _apps
$ _apps=(${(f)"$(mdfind "kMDItemKind == 'Application'")"})
An example run is below.
[bpm@snafu] c:~>typeset -a _apps
[bpm@snafu] c:~>_apps=(${(f)"$(mdfind "kMDItemKind == 'Application'")"})
[bpm@snafu] c:~>echo ${#_apps}
398
[bpm@snafu] c:~>echo ${_apps[0]}
/Applications/iPhoto.app
[bpm@snafu] c:~>compctl -f -x 'c[-1,-a]' -M 'b:=*' -k _apps -- open
[bpm@snafu] c:~>open -a /Library/Application Support/Adobe/Workflow/Adobe Workgroup Helper
[bpm@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
[robg adds: This worked as described when I tested it using the zsh shell...]
•
[8,669 views]

