From 88421034784eab155217d429a05a429f72fc2675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Wed, 19 Feb 2014 08:52:04 +0100 Subject: [PATCH 01/11] Use capitalized names in option description --- src/_port | 130 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 103 insertions(+), 27 deletions(-) diff --git a/src/_port b/src/_port index 173eb4f..8b6e3fc 100644 --- a/src/_port +++ b/src/_port @@ -20,19 +20,84 @@ _port() { typeset -A opt_args local context state state_descr line - local actions pseudo_common pseudo_advanced select_options port_prefix + typeset -a upgrade_options revupgrade_options select_options \ + actions pseudo_common pseudo_advanced port_prefix port_prefix=$(which port | sed 's|/bin/port||') - actions=( activate archive archivefetch build cat cd - checksum clean configure contents deactivate dependents deps - destroot dir distcheck distfiles dmg dpkg echo edit exit - extract fetch file gohome help info install installed lint list - livecheck load location log logfile mdmg mirror mpkg notes - outdated patch pkg platform portpkg provides quit rdependents - rdeps rev-upgrade rpm search select selfupdate setrequested space - srpm submit sync test unarchive uninstall unload unsetrequested - upgrade url usage variants version work ) + actions=( + 'activate\:Activate\ the\ given\ ports' + 'archive\:Archive\ the\ given\ ports,\ i.e.\ install\ the\ port\ image\ but\ do\ not\ activate' + 'archivefetch\:Fetch\ archive\ for\ the\ given\ ports' + 'build\:Build\ the\ given\ ports' + 'cat\:Writes\ the\ Portfiles\ of\ the\ given\ ports\ to\ stdout' + 'cd\:Changes\ to\ the\ directory\ of\ the\ given\ port' + 'checksum\:Compares\ the\ checksums\ for\ the\ downloaded\ files\ of\ the\ given\ ports' + 'clean\:Removes\ files\ associated\ with\ the\ given\ ports' + 'configure\:Removes\ files\ associated\ with\ the\ given\ ports' + 'contents\Returns\ a\ list\ of\ files\ installed\ by\ given\ ports' + 'deactivate\:Deactivates\ the\ given\ ports' + 'dependents\:Returns\ a\ list\ of\ installed\ dependents\ for\ each\ of\ the\ given\ ports' + 'deps\:Display\ a\ dependency\ listing\ for\ the\ given\ ports' + 'destroot\:Destroot\ the\ given\ ports' + 'dir\:Returns\ the\ directories\ of\ the\ given\ ports' + 'distcheck\:Checks\ if\ the\ given\ ports\ can\ be\ fetched\ from\ all\ of\ its\ master_sites' + 'distfiles\:Returns\ a\ list\ of\ distfiles\ for\ the\ given\ port' + 'dmg\:Creates\ a\ dmg\ for\ each\ of\ the\ given\ ports' + 'dpkg\:Creates\ a\ dpkg\ for\ each\ of\ the\ given\ ports' + 'echo\:Returns\ the\ list\ of\ ports\ the\ argument\ expands\ to' + 'edit' + 'exit' + 'extract\:Extract\ the\ downloaded\ files\ of\ the\ given\ ports' + 'fetch' + 'file' + 'gohome' + 'help' + 'info' + 'install' + 'installed' + 'lint' + 'list' + 'livecheck' + 'load' + 'location' + 'log' + 'logfile' + 'mdmg' + 'mirror' + 'mpkg' + 'notes' + 'outdated' + 'patch' + 'pkg' + 'platform' + 'portpkg' + 'provides' + 'quit' + 'rdependents' + 'rdeps' + 'rev-upgrade' + 'rpm' + 'search' + 'select' + 'selfupdate' + 'setrequested' + 'space' + 'srpm' + 'submit' + 'sync' + 'test' + 'unarchive' + 'uninstall' + 'unload' + 'unsetrequested' + 'upgrade' + 'url' + 'usage' + 'variants' + 'version' + 'work' + ) pseudo_common=(all current active inactive actinact installed uninstalled outdated obsolete requested unrequested leaves) @@ -50,6 +115,12 @@ _port() { revupgrade_options=('--id-loadcmd-check:Run more checks against a special loadcommand in Mach-O binaries') + upgrade_options=( + '--force\:Ignore\ circumstances\ that\ would\ normally\ cause\ ports\ to\ be\ skipped\ \(e.g.\ not\ outdated\).' \ + '--enforce-variants\:If\ the\ installed\ variants\ do\ not\ match\ those\ requested,\ upgrade\ even\ if\ the\ port\ is\ not\ outdated.' \ + '--no-replace\:Do\ not\ replace\ one\ port\ with\ another\ according\ to\ the\ replaced_by\ field.' \ + ) + local cache_policy zstyle -s ":completion:${curcontext}:" cache-policy cache_policy if [[ -z "$cache_policy" ]]; then @@ -57,23 +128,23 @@ _port() { fi _arguments -s -C \ - '-v[verbose mode (generate verbose messages)]' \ - '-d[debug mode (generate debugging messages, implies -v)]' \ - '-q[quiet mode (suppress messages)]' \ - "-n[don't upgrade dependencies (affects upgrade and install)]" \ - "-R[also upgrade dependents (only affects upgrade) - note that this does not upgrade dependents' dependencies]" \ - '-u[uninstall non-active ports when upgrading and uninstalling]' \ - '-f[force mode (ignore state file)]' \ - '-o[honor state files even if the Portfile has been modified since (called -o because it used to mean "older")]' \ - '-s[source-only mode (build and install from source, do not attempt to fetch binary archives)]' \ - '-b[binary-only mode (build and install from binary archives, ignore source, abort if no archive available)]' \ - '-c[autoclean mode (execute clean after install)]' \ - "-k[keep mode (don't autoclean after install)]" \ - '-D[specify portdir]' \ + '-v[Verbose mode (generate verbose messages)]' \ + '-d[Debug mode (generate debugging messages, implies -v)]' \ + '-q[Quiet mode (suppress messages)]' \ + "-n[Don't upgrade dependencies (affects upgrade and install)]" \ + "-R[Also upgrade dependents (only affects upgrade) - note that this does not upgrade dependents' dependencies]" \ + '-u[Uninstall non-active ports when upgrading and uninstalling]' \ + '-f[Force mode (ignore state file)]' \ + '-o[Honor state files even if the Portfile has been modified since (called -o because it used to mean "older")]' \ + '-s[Source-only mode (build and install from source, do not attempt to fetch binary archives)]' \ + '-b[Binary-only mode (build and install from binary archives, ignore source, abort if no archive available)]' \ + '-c[Autoclean mode (execute clean after install)]' \ + "-k[Keep mode (don't autoclean after install)]" \ + '-D[Specify portdir]' \ '-F[Read and process the file of commands specified by the argument.]' \ '-p[Despite any errors encountered, proceed to process multiple ports and commands.]' \ '-y[Perform a dry run.]' \ - '-t[enable trace mode debug facilities on platforms that support it (Mac OS X).]' \ + '-t[Enable trace mode debug facilities on platforms that support it (Mac OS X).]' \ "1:Port actions:($actions)" \ '*:extra:->extra' \ && return 0 @@ -104,7 +175,7 @@ _port_dispatch() { if ( [[ ${+_port_installed_packages} -eq 0 ]] || _cache_invalid PORT_INSTALLED_PACKAGES ) && ! _retrieve_cache PORT_INSTALLED_PACKAGES; then - _port_installed_packages=( $(_call_program path-all "port echo all") ) + _port_installed_packages=( $(_call_program path-all "port echo installed | cut -d ' ' -f 1") ) _store_cache PORT_INSTALLED_PACKAGES _port_installed_packages fi _alternative \ @@ -113,9 +184,14 @@ _port_dispatch() { "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" ;; upgrade) + # No good reason to actually cache outdated ports list local outdated_packages - outdated_packages=("${(f)$(port outdated | sed -e '1 d' -e 's/^\([[:graph:]]*\).*/\1/')}") - _describe "Outdated ports" outdated_packages + outdated_packages=( $(_call_program path-outdated "port echo outdated | cut -d ' ' -f 1") ) + _alternative -- \ + "upgrade-options:Upgrade options:(($upgrade_options))" \ + "ports:Outdated ports:($outdated_packages)" \ + "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \ + "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" ;; rev-upgrade) if (( CURRENT == 3 )); then From 42aace253f9c9e28b1bfb795b79a0dbc9d409282 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Wed, 19 Feb 2014 08:55:29 +0100 Subject: [PATCH 02/11] Use correct command to get installed ports This fixes a copy-paste error when we completed any port name instead of installed ones --- src/_port | 100 +++++++----------------------------------------------- 1 file changed, 12 insertions(+), 88 deletions(-) diff --git a/src/_port b/src/_port index 8b6e3fc..c2a7a73 100644 --- a/src/_port +++ b/src/_port @@ -20,84 +20,19 @@ _port() { typeset -A opt_args local context state state_descr line - typeset -a upgrade_options revupgrade_options select_options \ - actions pseudo_common pseudo_advanced port_prefix + local actions pseudo_common pseudo_advanced select_options port_prefix port_prefix=$(which port | sed 's|/bin/port||') - actions=( - 'activate\:Activate\ the\ given\ ports' - 'archive\:Archive\ the\ given\ ports,\ i.e.\ install\ the\ port\ image\ but\ do\ not\ activate' - 'archivefetch\:Fetch\ archive\ for\ the\ given\ ports' - 'build\:Build\ the\ given\ ports' - 'cat\:Writes\ the\ Portfiles\ of\ the\ given\ ports\ to\ stdout' - 'cd\:Changes\ to\ the\ directory\ of\ the\ given\ port' - 'checksum\:Compares\ the\ checksums\ for\ the\ downloaded\ files\ of\ the\ given\ ports' - 'clean\:Removes\ files\ associated\ with\ the\ given\ ports' - 'configure\:Removes\ files\ associated\ with\ the\ given\ ports' - 'contents\Returns\ a\ list\ of\ files\ installed\ by\ given\ ports' - 'deactivate\:Deactivates\ the\ given\ ports' - 'dependents\:Returns\ a\ list\ of\ installed\ dependents\ for\ each\ of\ the\ given\ ports' - 'deps\:Display\ a\ dependency\ listing\ for\ the\ given\ ports' - 'destroot\:Destroot\ the\ given\ ports' - 'dir\:Returns\ the\ directories\ of\ the\ given\ ports' - 'distcheck\:Checks\ if\ the\ given\ ports\ can\ be\ fetched\ from\ all\ of\ its\ master_sites' - 'distfiles\:Returns\ a\ list\ of\ distfiles\ for\ the\ given\ port' - 'dmg\:Creates\ a\ dmg\ for\ each\ of\ the\ given\ ports' - 'dpkg\:Creates\ a\ dpkg\ for\ each\ of\ the\ given\ ports' - 'echo\:Returns\ the\ list\ of\ ports\ the\ argument\ expands\ to' - 'edit' - 'exit' - 'extract\:Extract\ the\ downloaded\ files\ of\ the\ given\ ports' - 'fetch' - 'file' - 'gohome' - 'help' - 'info' - 'install' - 'installed' - 'lint' - 'list' - 'livecheck' - 'load' - 'location' - 'log' - 'logfile' - 'mdmg' - 'mirror' - 'mpkg' - 'notes' - 'outdated' - 'patch' - 'pkg' - 'platform' - 'portpkg' - 'provides' - 'quit' - 'rdependents' - 'rdeps' - 'rev-upgrade' - 'rpm' - 'search' - 'select' - 'selfupdate' - 'setrequested' - 'space' - 'srpm' - 'submit' - 'sync' - 'test' - 'unarchive' - 'uninstall' - 'unload' - 'unsetrequested' - 'upgrade' - 'url' - 'usage' - 'variants' - 'version' - 'work' - ) + actions=( activate archive archivefetch build cat cd + checksum clean configure contents deactivate dependents deps + destroot dir distcheck distfiles dmg dpkg echo edit exit + extract fetch file gohome help info install installed lint list + livecheck load location log logfile mdmg mirror mpkg notes + outdated patch pkg platform portpkg provides quit rdependents + rdeps rev-upgrade rpm search select selfupdate setrequested space + srpm submit sync test unarchive uninstall unload unsetrequested + upgrade url usage variants version work ) pseudo_common=(all current active inactive actinact installed uninstalled outdated obsolete requested unrequested leaves) @@ -115,12 +50,6 @@ _port() { revupgrade_options=('--id-loadcmd-check:Run more checks against a special loadcommand in Mach-O binaries') - upgrade_options=( - '--force\:Ignore\ circumstances\ that\ would\ normally\ cause\ ports\ to\ be\ skipped\ \(e.g.\ not\ outdated\).' \ - '--enforce-variants\:If\ the\ installed\ variants\ do\ not\ match\ those\ requested,\ upgrade\ even\ if\ the\ port\ is\ not\ outdated.' \ - '--no-replace\:Do\ not\ replace\ one\ port\ with\ another\ according\ to\ the\ replaced_by\ field.' \ - ) - local cache_policy zstyle -s ":completion:${curcontext}:" cache-policy cache_policy if [[ -z "$cache_policy" ]]; then @@ -184,14 +113,9 @@ _port_dispatch() { "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" ;; upgrade) - # No good reason to actually cache outdated ports list local outdated_packages - outdated_packages=( $(_call_program path-outdated "port echo outdated | cut -d ' ' -f 1") ) - _alternative -- \ - "upgrade-options:Upgrade options:(($upgrade_options))" \ - "ports:Outdated ports:($outdated_packages)" \ - "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \ - "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" + outdated_packages=("${(f)$(port outdated | sed -e '1 d' -e 's/^\([[:graph:]]*\).*/\1/')}") + _describe "Outdated ports" outdated_packages ;; rev-upgrade) if (( CURRENT == 3 )); then From a2765bc27c73519acb98bcca05fa03c27eb3afe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Wed, 19 Feb 2014 10:46:10 +0100 Subject: [PATCH 03/11] Explicitly typeset arrays --- src/_port | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/_port b/src/_port index c2a7a73..25e0077 100644 --- a/src/_port +++ b/src/_port @@ -20,7 +20,8 @@ _port() { typeset -A opt_args local context state state_descr line - local actions pseudo_common pseudo_advanced select_options port_prefix + local -a revupgrade_options select_options \ + actions pseudo_common pseudo_advanced port_prefix port_prefix=$(which port | sed 's|/bin/port||') From 8dc4b8a490a31f580fd2cfce1b7d99b5bc0c9a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Wed, 19 Feb 2014 10:46:53 +0100 Subject: [PATCH 04/11] Better port upgrade completion When upgrading, pseudo-portnames can be used. Also, add upgrade options to completion choices. --- src/_port | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/_port b/src/_port index 25e0077..e986b60 100644 --- a/src/_port +++ b/src/_port @@ -20,7 +20,7 @@ _port() { typeset -A opt_args local context state state_descr line - local -a revupgrade_options select_options \ + local -a upgrade_options revupgrade_options select_options \ actions pseudo_common pseudo_advanced port_prefix port_prefix=$(which port | sed 's|/bin/port||') @@ -51,6 +51,12 @@ _port() { revupgrade_options=('--id-loadcmd-check:Run more checks against a special loadcommand in Mach-O binaries') + upgrade_options=( + '--force\:Ignore\ circumstances\ that\ would\ normally\ cause\ ports\ to\ be\ skipped\ \(e.g.\ not\ outdated\).' \ + '--enforce-variants\:If\ the\ installed\ variants\ do\ not\ match\ those\ requested,\ upgrade\ even\ if\ the\ port\ is\ not\ outdated.' \ + '--no-replace\:Do\ not\ replace\ one\ port\ with\ another\ according\ to\ the\ replaced_by\ field.' \ + ) + local cache_policy zstyle -s ":completion:${curcontext}:" cache-policy cache_policy if [[ -z "$cache_policy" ]]; then @@ -114,9 +120,14 @@ _port_dispatch() { "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" ;; upgrade) + # No good reason to actually cache outdated ports list local outdated_packages - outdated_packages=("${(f)$(port outdated | sed -e '1 d' -e 's/^\([[:graph:]]*\).*/\1/')}") - _describe "Outdated ports" outdated_packages + outdated_packages=( $(_call_program path-outdated "port echo outdated | cut -d ' ' -f 1") ) + _alternative -- \ + "upgrade-options:Upgrade options:(($upgrade_options))" \ + "ports:Outdated ports:($outdated_packages)" \ + "pseudo-common:Common Pseudo-portnames:($pseudo_common)" \ + "pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)" ;; rev-upgrade) if (( CURRENT == 3 )); then From 0b791a2f50da09c4d5f634bd48c41a9cc90755fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Wed, 19 Feb 2014 11:23:35 +0100 Subject: [PATCH 05/11] Add description to each port target Also, remove targets used only in interactive mode, like 'exit' or 'cd' --- src/_port | 79 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 10 deletions(-) diff --git a/src/_port b/src/_port index e986b60..03a4895 100644 --- a/src/_port +++ b/src/_port @@ -25,15 +25,74 @@ _port() { port_prefix=$(which port | sed 's|/bin/port||') - actions=( activate archive archivefetch build cat cd - checksum clean configure contents deactivate dependents deps - destroot dir distcheck distfiles dmg dpkg echo edit exit - extract fetch file gohome help info install installed lint list - livecheck load location log logfile mdmg mirror mpkg notes - outdated patch pkg platform portpkg provides quit rdependents - rdeps rev-upgrade rpm search select selfupdate setrequested space - srpm submit sync test unarchive uninstall unload unsetrequested - upgrade url usage variants version work ) + actions=( + 'activate\:Activate\ the\ given\ ports' + 'archive\:Archive\ the\ given\ ports,\ i.e.\ install\ the\ port\ image\ but\ do\ not\ activate' + 'archivefetch\:Fetch\ archive\ for\ the\ given\ ports' + 'build\:Build\ the\ given\ ports' + 'cat\:Writes\ the\ Portfiles\ of\ the\ given\ ports\ to\ stdout' + 'checksum\:Compares\ the\ checksums\ for\ the\ downloaded\ files\ of\ the\ given\ ports' + 'clean\:Removes\ files\ associated\ with\ the\ given\ ports' + 'configure\:Configure\ the\ given\ ports' + 'contents\:\Returns\ a\ list\ of\ files\ installed\ by\ given\ ports' + 'deactivate\:Deactivates\ the\ given\ ports' + 'dependents\:Returns\ a\ list\ of\ installed\ dependents\ for\ each\ of\ the\ given\ ports' + 'deps\:Display\ a\ dependency\ listing\ for\ the\ given\ ports' + 'destroot\:Destroot\ the\ given\ ports' + 'dir\:Returns\ the\ directories\ of\ the\ given\ ports' + 'distcheck\:Checks\ if\ the\ given\ ports\ can\ be\ fetched\ from\ all\ of\ its\ master_sites' + 'distfiles\:Returns\ a\ list\ of\ distfiles\ for\ the\ given\ port' + 'dmg\:Creates\ a\ dmg\ for\ each\ of\ the\ given\ ports' + 'dpkg\:Creates\ a\ dpkg\ for\ each\ of\ the\ given\ ports' + 'echo\:Returns\ the\ list\ of\ ports\ the\ argument\ expands\ to' + 'edit\:Edit\ given\ ports' + 'extract\:Extract\ the\ downloaded\ files\ of\ the\ given\ ports' + 'fetch\:Downloaded\ distfiles\ for\ the\ given\ ports' + 'file\:Returns\ the\ path\ to\ the\ Portfile\ for\ each\ of\ the\ given\ ports' + 'gohome\:Opens\ the\ homepages\ of\ the\ given\ ports\ in\ your\ browser' + 'help\:Displays\ short\ help\ texts\ for\ the\ given\ actions' + 'info\:Returns\ information\ about\ the\ given\ ports ' + 'install\:Installs\ the\ given\ ports' + 'installed\:List\ installed\ versions\ of\ the\ given\ port,\ or\ all\ installed\ ports\ if\ no\ port\ is\ given' + 'lint\:Checks\ if\ the\ Portfile\ is\ lint-free\ for\ each\ of\ the\ given\ ports' + 'list\:List\ the\ available\ version\ for\ each\ of\ the\ given\ ports' + 'livecheck\:Checks\ if\ a\ new\ version\ of\ the\ software\ is\ available' + 'load\:Interface\ to\ launchctl(1)\ for\ ports\ providing\ startup\ items' + 'location\:Returns\ the\ install\ location\ for\ each\ of\ the\ given\ ports' + 'log\:Shows\ main\ log\ for\ given\ ports' + 'logfile\:Returns\ the\ log\ file\ path\ for\ each\ of\ the\ given\ ports' + 'mdmg\:Creates\ a\ dmg\ containing\ an\ mpkg\ for\ each\ of\ the\ given\ ports\ and\ their\ dependencies' + 'mirror\:Fetches\ distfiles\ for\ the\ given\ ports' + 'mpkg\:Creates\ an\ mpkg\ for\ each\ of\ the\ given\ ports\ and\ their\ dependencies' + 'notes\:Displays\ informational\ notes\ for\ each\ of\ the\ given\ ports' + 'outdated\:Returns\ a\ list\ of\ outdated\ ports' + 'patch\:Applies\ patches\ to\ each\ of\ the\ given\ ports' + 'pkg\:Creates\ a\ pkg\ for\ each\ of\ the\ given\ ports' + 'platform\:Returns\ the\ current\ platform\ that\ port\ is\ running\ on' + 'provides\:Return\ which\ port\ provides\ each\ of\ the\ files\ given' + 'rdependents\:Recursive\ version\ of\ dependents' + 'rdeps\:Display\ a\ recursive\ dependency\ listing\ for\ the\ given\ ports' + 'rev-upgrade\:Scan\ for\ broken\ binaries\ in\ the\ installed\ ports\ and\ rebuild\ them\ as\ needed' + 'rpm\:Creates\ a\ rpm\ for\ each\ of\ the\ given\ ports' + 'search\:Search\ for\ a\ port' + 'select\:Select\ between\ multiple\ versions\ of\ a\ versioned\ port' + 'selfupdate\:Upgrade\ MacPorts\ itself\ and\ run\ the\ sync\ target' + 'setrequested\:Marks\ each\ of\ the\ given\ ports\ as\ requested' + 'space\:Show\ the\ disk\ space\ used\ by\ the\ given\ ports' + 'srpm\:Creates\ a\ srpm\ for\ each\ of\ the\ given\ ports' + 'sync\:Synchronize\ the\ set\ of\ Portfiles' + 'test\:Run\ tests\ on\ each\ of\ the\ given\ ports' + 'unarchive\:Unarchive\ the\ destroot\ of\ the\ given\ ports\ from\ installed\ images' + 'uninstall\:Uninstall\ the\ given\ ports' + 'unload\:Interface\ to\ launchctl(1)\ for\ ports\ providing\ startup\ items' + 'unsetrequested\:Marks\ each\ of\ the\ given\ ports\ as\ unrequested' + 'upgrade\:Upgrades\ the\ given\ ports\ to\ the\ latest\ version' + 'url\:Returns\ the\ URL\ for\ each\ of\ the\ given\ ports' + 'usage\:Returns\ basic\ usage\ of\ the\ port\ command' + 'variants\:Returns\ a\ list\ of\ variants\ provided\ by\ the\ given\ ports,\ with\ descriptions\ if\ present' + 'version\:Returns\ the\ version\ of\ MacPorts' + 'work\:Returns\ the\ path\ to\ the\ work\ directory\ for\ each\ of\ the\ given\ ports' + ) pseudo_common=(all current active inactive actinact installed uninstalled outdated obsolete requested unrequested leaves) @@ -81,7 +140,7 @@ _port() { '-p[Despite any errors encountered, proceed to process multiple ports and commands.]' \ '-y[Perform a dry run.]' \ '-t[Enable trace mode debug facilities on platforms that support it (Mac OS X).]' \ - "1:Port actions:($actions)" \ + "1:Port actions:(($actions))" \ '*:extra:->extra' \ && return 0 From 77df22a969577c908e40bed70906b57ae79a3a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Wed, 19 Feb 2014 15:24:33 +0100 Subject: [PATCH 06/11] No need to set cache policy in the main function The caching policy style for _port can be set in _port_dispatch, as it is the one that uses caching. --- src/_port | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/_port b/src/_port index 03a4895..7ac5a6e 100644 --- a/src/_port +++ b/src/_port @@ -116,12 +116,6 @@ _port() { '--no-replace\:Do\ not\ replace\ one\ port\ with\ another\ according\ to\ the\ replaced_by\ field.' \ ) - local cache_policy - zstyle -s ":completion:${curcontext}:" cache-policy cache_policy - if [[ -z "$cache_policy" ]]; then - zstyle ":completion:${curcontext}:" cache-policy _port_caching_policy - fi - _arguments -s -C \ '-v[Verbose mode (generate verbose messages)]' \ '-d[Debug mode (generate debugging messages, implies -v)]' \ @@ -141,17 +135,15 @@ _port() { '-y[Perform a dry run.]' \ '-t[Enable trace mode debug facilities on platforms that support it (Mac OS X).]' \ "1:Port actions:(($actions))" \ - '*:extra:->extra' \ + '*:extra:_port_dispatch' \ && return 0 - - case "$state" in - extra) - _port_dispatch - ;; - esac } _port_dispatch() { + local cache_policy + zstyle -s ":completion:${curcontext}:" cache-policy cache_policy + zstyle ":completion:${curcontext}:" cache-policy ${cache_policy:-_port_caching_policy} + case "$words[2]" in provides) _files @@ -170,7 +162,7 @@ _port_dispatch() { if ( [[ ${+_port_installed_packages} -eq 0 ]] || _cache_invalid PORT_INSTALLED_PACKAGES ) && ! _retrieve_cache PORT_INSTALLED_PACKAGES; then - _port_installed_packages=( $(_call_program path-all "port echo installed | cut -d ' ' -f 1") ) + _port_installed_packages=( $(_call_program path-all "port -q echo installed") ) _store_cache PORT_INSTALLED_PACKAGES _port_installed_packages fi _alternative \ @@ -181,7 +173,7 @@ _port_dispatch() { upgrade) # No good reason to actually cache outdated ports list local outdated_packages - outdated_packages=( $(_call_program path-outdated "port echo outdated | cut -d ' ' -f 1") ) + outdated_packages=( $(_call_program path-outdated "port -q echo outdated") ) _alternative -- \ "upgrade-options:Upgrade options:(($upgrade_options))" \ "ports:Outdated ports:($outdated_packages)" \ @@ -198,7 +190,7 @@ _port_dispatch() { if ( [[ ${+_port_available_packages} -eq 0 ]] || _cache_invalid PORT_AVAILABLE_PACKAGES ) && ! _retrieve_cache PORT_AVAILABLE_PACKAGES; then - _port_available_packages=( $(_call_program path-all "port echo all") ) + _port_available_packages=( $(_call_program path-all "port -q echo all") ) _store_cache PORT_AVAILABLE_PACKAGES _port_available_packages fi _alternative \ @@ -227,8 +219,16 @@ _port_select() { } _port_caching_policy() { - local reg_time comp_time - reg_time=$(stat -c '%Z' $port_prefix/var/macports/registry/registry.db) + local reg_time comp_time check_file + case "${1##*/}" in + PORT_INSTALLED_PACKAGES) + check_file=$port_prefix/var/macports/registry/registry.db + ;; + PORT_AVAILABLE_PACKAGES) + check_file=${$(port dir MacPorts)%/*/*}/PortIndex + ;; + esac + reg_time=$(stat -c '%Z' $check_file) comp_time=$(stat -c '%Z' $1) return $(( reg_time < comp_time )) } From 04e2e85de859b37c6c81db6b9515518c860457b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Wed, 19 Feb 2014 15:26:52 +0100 Subject: [PATCH 07/11] Use the -q flag when calling port The -q flag suppresses any output other than port names, eliminating the need to further modify output. --- src/_port | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/_port b/src/_port index 7ac5a6e..3a6eaf2 100644 --- a/src/_port +++ b/src/_port @@ -135,8 +135,14 @@ _port() { '-y[Perform a dry run.]' \ '-t[Enable trace mode debug facilities on platforms that support it (Mac OS X).]' \ "1:Port actions:(($actions))" \ - '*:extra:_port_dispatch' \ + '*:extra:->extra' \ && return 0 + + case "$state" in + extra) + _port_dispatch + ;; + esac } _port_dispatch() { @@ -219,16 +225,8 @@ _port_select() { } _port_caching_policy() { - local reg_time comp_time check_file - case "${1##*/}" in - PORT_INSTALLED_PACKAGES) - check_file=$port_prefix/var/macports/registry/registry.db - ;; - PORT_AVAILABLE_PACKAGES) - check_file=${$(port dir MacPorts)%/*/*}/PortIndex - ;; - esac - reg_time=$(stat -c '%Z' $check_file) + local reg_time comp_time + reg_time=$(stat -c '%Z' $port_prefix/var/macports/registry/registry.db) comp_time=$(stat -c '%Z' $1) return $(( reg_time < comp_time )) } From 8daa84f28ffc8b1f955a1a5e83b8cb55f47111e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Wed, 19 Feb 2014 15:28:30 +0100 Subject: [PATCH 08/11] A better cache policy for _port This compares modification times of the main PortIndex for all ports and registry.db for installed ports. --- src/_port | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/_port b/src/_port index 3a6eaf2..405872f 100644 --- a/src/_port +++ b/src/_port @@ -225,8 +225,16 @@ _port_select() { } _port_caching_policy() { - local reg_time comp_time - reg_time=$(stat -c '%Z' $port_prefix/var/macports/registry/registry.db) + local reg_time comp_time check_file + case "${1##*/}" in + PORT_INSTALLED_PACKAGES) + check_file=$port_prefix/var/macports/registry/registry.db + ;; + PORT_AVAILABLE_PACKAGES) + check_file=${$(port dir MacPorts)%/*/*}/PortIndex + ;; + esac + reg_time=$(stat -c '%Z' $check_file) comp_time=$(stat -c '%Z' $1) return $(( reg_time < comp_time )) } From 062e23c1bfe0fddf2a0e1576a745a04d77541eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Wed, 19 Feb 2014 15:35:09 +0100 Subject: [PATCH 09/11] No need to use the ->string format If we have only one function to call fro completion, just call it. Also, remove local declaration, since we don't use the ->string form. --- src/_port | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/_port b/src/_port index 405872f..dc93a5d 100644 --- a/src/_port +++ b/src/_port @@ -16,10 +16,6 @@ # ------------------------------------------------------------------------------ _port() { - # Variables for _argument - typeset -A opt_args - local context state state_descr line - local -a upgrade_options revupgrade_options select_options \ actions pseudo_common pseudo_advanced port_prefix @@ -135,14 +131,8 @@ _port() { '-y[Perform a dry run.]' \ '-t[Enable trace mode debug facilities on platforms that support it (Mac OS X).]' \ "1:Port actions:(($actions))" \ - '*:extra:->extra' \ + '*:Per-action arguments:_port_dispatch' \ && return 0 - - case "$state" in - extra) - _port_dispatch - ;; - esac } _port_dispatch() { From e580a15f99541aa5fdb879d7707cd34e083acc9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Thu, 26 Jun 2014 17:50:10 +0200 Subject: [PATCH 10/11] _port: complete more subcommands Add completions for outdated, sync and selfupdate subcommands. --- src/_port | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/_port b/src/_port index dc93a5d..d7aa322 100644 --- a/src/_port +++ b/src/_port @@ -181,6 +181,13 @@ _port_dispatch() { _describe 'Rev-upgrade options' revupgrade_options fi ;; + outdated|sync) + # No need to complete anything more here. + return 0; + ;; + selfupdate) + _all_labels 'Selfupdate options' '--nosync' + ;; *) # Cache the list of all ports. if ( [[ ${+_port_available_packages} -eq 0 ]] || _cache_invalid PORT_AVAILABLE_PACKAGES ) && From de9abc631e9c350cd574636e57fb94c17d9a2c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aljaz=CC=8C=20=22g5pw=22=20Srebrnic=CC=8C?= Date: Thu, 26 Jun 2014 17:58:36 +0200 Subject: [PATCH 11/11] _port: Fix completion of next arguments --- src/_port | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_port b/src/_port index d7aa322..8e3fc5b 100644 --- a/src/_port +++ b/src/_port @@ -131,7 +131,7 @@ _port() { '-y[Perform a dry run.]' \ '-t[Enable trace mode debug facilities on platforms that support it (Mac OS X).]' \ "1:Port actions:(($actions))" \ - '*:Per-action arguments:_port_dispatch' \ + '::Per-action arguments:_port_dispatch' \ && return 0 }