#compdef pkg ## vim:ft=zsh ## pkg completion ## Daniel Friesel ## https://derf.homelinux.org/~derf/dotfiles/zsh/completions/_pkg ## see also: https://derf.homelinux.org/~derf/code/lighty-stats typeset expl function _pkg_action () { _wanted action expl 'action' \ compadd add eval remove info list \ log pull push refresh status update } function _pkg_installed () { _wanted package expl 'local package' \ compadd $(pkg list local) } function _pkg_all () { _wanted package expl 'package' \ compadd $(pkg list all) } function _pkg_notinstalled () { _wanted package expl 'remote package' \ compadd $(pkg list not-installed) } function _pkg_args { if (( CURRENT == 2 )) { case ${words[1]} in log|pull|push|refresh|remove|status) _pkg_installed ;; info) _pkg_all ;; add) _pkg_notinstalled ;; eval) _message 'shell code for evaluation' _wanted function expl 'internal function' \ compadd $(grep -E '^\S*\s*\(\)\s*{' =pkg | cut -d ' ' -f 1) \ $(grep -E 'function \S* (\(\) )?{' =pkg | cut -d ' ' -f 2) ;; list) _wanted something expl 'list mode' \ compadd all local not-installed ;; update) _wanted mode expl 'update target' \ compadd local remote ;; *) _message 'no more arguments' ;; esac } elif [[ ${words[1]} = 'eval' ]] { _message 'shell code for evaluation' if (( CURRENT == 3 )) { case ${words[2]} in exec_hook|check_prereqs|*_collected|) _pkg_installed ;; esac } elif (( CURRENT == 4 )) { case ${words[2]} in exec_hook) _wanted hook expl 'package hook' \ compadd $(ls -1 ~/packages/${words[3]}/hooks 2> /dev/null) ;; esac } } } _arguments \ '--quiet[quiet mode]' \ '--debug[debugmode]' \ '--auto-update[automatically update package list]' \ '*--checklinks-options[options for checklinks]:option' \ '--packagedir[package directory]:directory:_files -/' \ '--packageroot[package root]:url' \ '--colours[use colours]' \ '--no-colours[No colours]' \ '--progress[show progress bar]' \ '--no-progress[No progress bar]' \ ':action:_pkg_action' \ '*::arguments:_pkg_args'