Compare commits

...

9 Commits

Author SHA1 Message Date
Shohei YOSHIDA f4b7099c10
Merge 0b3d20b74b into 684021f2a1 2026-03-03 13:39:36 +09:00
Shohei YOSHIDA 684021f2a1
Merge pull request #1227 from zsh-users/update_port
Update MacPorts completion
2026-02-22 11:20:04 +09:00
Shohei YOSHIDA 8d5f60cf38 add missing colon 2026-02-21 20:15:01 +09:00
Shohei YOSHIDA 80613d862a Add relationship selectors 2026-02-20 14:54:06 +09:00
Shohei YOSHIDA b5a9ce4b37 Update global option descriptions according to latest manpage 2026-02-20 14:39:59 +09:00
Shohei YOSHIDA 79da59126e fix typo 2026-02-20 14:36:14 +09:00
Shohei YOSHIDA b302f21ed9 Fix cache handling, it must work as the original implementation 2026-02-19 15:03:57 +09:00
Shohei YOSHIDA f344c2ca77 Update MacPorts completion
- Remove deprecated commands
- Add new commands(snapshot)
- Support variant completion
2026-02-18 18:04:28 +09:00
Shohei YOSHIDA 0b3d20b74b
Refactoring fail2ban and add other commands
- Add fail2ban-server and fail2ban-testcases completions
- fix broken syntax of fail2ban-client
- apply zsh standard naming convention to fail2ban-client functions
- unify fail2ban-client and fail2ban-regex completion
2026-02-18 13:19:37 +09:00
4 changed files with 817 additions and 530 deletions

417
src/_fail2ban Normal file
View File

@ -0,0 +1,417 @@
#compdef fail2ban-client fail2ban-regex fail2ban-server fail2ban-testcases
# ------------------------------------------------------------------------------
# Copyright (c) 2020 Github zsh-users - https://github.com/zsh-users
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for fail2ban-client (https://www.fail2ban.org/).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Felix Neumärker <xdch47@posteo.de> (fail2ban-client)
# * Jesse Ayala <jesserayala95@gmail.com> (fail2ban-regex)
# * Shohei Yoshida (https://github.com/syohex) <syohex@gmail.com>
#
# ------------------------------------------------------------------------------
_fail2ban_client_jail_list() {
LANG=C fail2ban-client status 2> /dev/null | sed -n -e 's/.*Jail list:\s\+//' -e 'T' -e 's/,\s\+/\'$'\n/g' -e 'p'
}
_fail2ban_client_subcommands() {
local -a cmds=(
'unban:unbans all IP addresses'
'set:set property'
'get:get property'
'status:gets the current status of the server'
'reload:reloads the configuration/jails'
'restart:restarts the server'
'start:starts the server and the jails'
'stop:stops all jails and terminate the server'
'ping:tests if the server is alive'
'flushlogs:flushes the logtarget if a file and reopens it'
'help:return this output'
'version:return the server version'
)
_describe -V "fail2ban commands" cmds
}
_fail2ban_client_command_args() {
local f2barg="$words[$NORMARG]"
case "$f2barg" in
(unban)
local jail
if (( $words[(I)(--all)] == 0 )) ; then
for jail in $(_fail2ban_client_jail_list) ; do
_fail2ban_client_ips $jail
done
local unban_opts=(--all)
_describe -o "unban options" unban_opts
else
_nothing
fi
;;
(set|get)
if (( $NORMARG + 1 == $CURRENT )); then
_fail2ban_client_jails
_fail2ban_client_settings
elif [[ $f2barg == "get" ]]; then
_fail2ban_client_jail_get
elif [[ $f2barg == "set" ]]; then
_fail2ban_client_jail_set
fi
;;
(status)
if (( $NORMARG + 1 == $CURRENT )); then
_fail2ban_client_jails
elif (( $NORMARG + 2 == $CURRENT )); then
_values "flavor" basic cymru
else
_nothing
fi
;;
esac
}
_fail2ban_client_jails() {
local jails=($(_fail2ban_client_jail_list))
_describe -V "jails" jails
}
_fail2ban_client_ips() {
local ips=("${(@f)$(LANG=C fail2ban-client status $1 2> /dev/null | sed -n -e 's/^.*Banned IP list:\s\+//' -e 'T' -e 's/\s\+/\'$'\n/g' -e 'p')}")
if [[ -n "${ips[@]}" ]] ; then
_describe -t "f2b_jail_$1" -V "banned ips of jail $1" ips
else
_nothing
fi
}
_fail2ban_client_jail_set() {
if (( $NORMARG + 2 == $CURRENT )) ; then
case $words[$NORMARG+1] in
(loglevel)
local loglevel=(CRITICAL ERROR WARNING NOTICE INFO DEBUG TRACEDEBUG HEAVYDEBUG)
_describe -V "loglevel" loglevel
;;
(logtarget)
local logtarget=(STDOUT STDERR SYSLOG)
_describe -V "logtarget" logtarget
_files
;;
(syslogsocket)
local syslogsocket=(auto)
_describe -V "logtarget" syslogsocket
_files
;;
(dbfile)
_files
;;
(dbpurgeage)
_message "sets the max age in <SECONDS> that history of bans will be kept"
;;
(*)
# jail
local jailsettings=(
unbanip banip action addaction addfailregex addignoreip
addignoreregex addjournalmatch addlogpath bantime
datepattern delaction delfailregex delignoreip
delignorerexgex deljournalmatch dellogpath findtime idle
ignorecache ignorecommand ignoreself logencoding maxlines
maxretry usedns
)
_describe -t "f2b_jail_setting" -V "jail setting" jailsettings
;;
esac
else
local jail="$words[$NORMARG+1]"
if (( $NORMARG + 3 == $CURRENT )); then
case $words[$NORMARG+2] in
(unbanip)
_fail2ban_client_ips "$jail"
;;
(delfailregex)
_fail2ban_client_regex fail "$jail"
;;
(delignorerexgex)
_fail2ban_client_regex ignore "$jail"
;;
(dellogpath)
local filelist=("${(@f)$(LANG=C fail2ban-client status $jail 2> /dev/null | sed -n -e 's/^.*File list:\s\+//' -e 'T' -e 's/\s\+/\'$'\n/g' -e 'p')}")
if [[ -n "${filelist[@]}" ]]; then
_describe -t "f2b_filelist" -V "filelist of jail $1" filelist
else
_nothing
fi
;;
(idle)
_values 'fail2ban idle' on off
;;
(ignoreself)
_values 'fail2ban ignoreself' true false
;;
(delignoreip)
local ignoreips=("${(@f)$(fail2ban-client get "$jail" ignoreip 2> /dev/null | sed -e 's/^[|`]-\s\+//p')}")
if [[ -n "${ignoreips[@]}" ]]; then
_describe -t "f2b_ignoreip" -V "fail2ban ignored ips" ignoreips
else
_nothing
fi
;;
(delaction|action)
_fail2ban_client_jail_actions "$jail"
;;
(addlogpath)
_files
;;
(*)
_message "No completion for ${words[NORMARG+2]}"
;;
esac
elif (( $NORMARG + 4 == $CURRENT )) ; then
case $words[$NORMARG+2] in
(action)
_fail2ban_client_action_properties "$jail" $words[$NORMARG+3]
;;
(addaction)
_files
;;
(*)
_nothing
;;
esac
else
_nothing
fi
fi
}
_fail2ban_client_jail_get() {
if (( $NORMARG + 2 == $CURRENT )); then
case $words[$NORMARG+1] in
(loglevel|logtarget|syslogsocket|dbfile|dbpurgeage)
_nothing
;;
(*)
# jail
local jailprops=(
logpath logencoding journalmatch ignoreself ignoreip
ignorecommand failregex ignoreregex findtime bantime
datepattern usedns maxretry maxlines actions action
actionproperties actionmethods
)
_describe -t "f2b_jail_props" -V "jail properties" jailprops
;;
esac
else
local jail="$words[$NORMARG+1]"
if (( $NORMARG + 3 == $CURRENT )); then
case $words[$NORMARG+2] in
(action|actionproperties|actionmethods)
_fail2ban_client_jail_actions "$jail"
;;
(*)
_nothing
;;
esac
elif (( $NORMARG + 4 == $CURRENT )) ; then
case $words[$NORMARG+2] in
(action|actionproperties|actionmethods)
_fail2ban_client_action_properties "$jail" $words[$NORMARG+3]
;;
(*)
_nothing
;;
esac
else
_nothing
fi
fi
}
_fail2ban_client_jail_actions() {
local jailactions=("${(@f)$(fail2ban-client get $1 actions 2>/dev/null | sed -e '1d' -e 's/,\s\+/\'$'\n/g')}")
if [[ -n "${jailactions[@]}" ]] ; then
_describe -t "f2b_jail_actions" -V "jail actions" jailactions
else
_nothing
fi
}
_fail2ban_client_action_properties() {
local -a default_actionproperties=(
actionstart actionstop actioncheck actionban actionunban timeout
)
local -a all_actionproperties=("${(@f)$(fail2ban-client get $1 actionproperties $2 2>/dev/null | sed -e '1d' -e 's/,\s\+/\'$'\n/g')}")
local -a add_actionproperties=("${(@)all_actionproperties:|default_actionproperties}")
_describe -t "f2b_actions_defprops" -V "default action properties" default_actionproperties
if [[ -n "${add_actionproperties[@]}" ]]; then
_describe -t "f2b_actions_remprops" -V "additional action properties" add_actionproperties
else
_nothing
fi
}
_fail2ban_client_regex() {
local regex=("${(@f)$(fail2ban-client get $2 ${1}regex 2> /dev/null | sed -n -e 's/[|`]- \[\([0-9]\+\)\]:\s\+/\1:/p')}")
if [[ -n "${regex[@]}" ]]; then
_describe -t "f2b_regex" -V "jail $2 ${1}regex" regex
else
_nothing
fi
}
_fail2ban_client_settings() {
local setargs=(loglevel logtarget syslogsocket dbfile dbpurgeage)
_describe -t "f2b_settings" -V "fail2ban-client settings" setargs
}
_fail2ban_client() {
_arguments -A "-*" -n \
'-c[configuration directory]:_files -/' \
'-s[socket path]:_files' \
'-p[pidfile path]:_files' \
'--loglevel[logging level]:(CRITICAL ERROR WARNING, NOTICE INFO, DEBUG, TRACEDEBUG HEAVYDEBUG)' \
'--logtarget[logging target]:(stdout stderr syslog sysout)' \
'--syslogsocket:_files' \
'-d[dump configuration]' \
'(--dp --dump-pretty)'{--dp,--dump-pretty}'[dump the configuration using more human readable representation]' \
'(-t --test)'{-t,--test}'[test configuration]' \
'-i[interactive mode]' \
'-v[increase verbosity]' \
'-q[decrease verbosity]' \
'-x[force execution of the server (remove socket file)]' \
'-b[start server in background]' \
'-f[start server in foreground]' \
'--str2sec[convert time abbreviation format to seconds]:_message str2sec' \
'(-h --help)'{-h,--help}'[display this help message]' \
'(-V --version)'{-V,--version}'[print the version]' \
'1:fail2ban command:_fail2ban_client_subcommands' \
'*:fail2ban command argument:_fail2ban_client_command_args'
}
_fail2ban_regex() {
_arguments -A "-*" -n \
'--version[show program''s version number]' \
'(-h --help)'{-h,--help}'[display the help message]' \
'(-c --config)'{-c,--config=}'[set alternate config directory]:directory:_files -/' \
'(-d --datepattern)'{-d,--datepattern=}'[set custom pattern used to match date/times]:DATEPATTERN' \
'(--timezone= --TZ=)'{--timezone=,--TZ=}'[set time-zone used by convert time format]:TIMEZONE' \
'(-e --encoding=)'{-e,--encoding=}'[use different encoding from system locale]:ENCODING' \
'(-r --raw)'{-r,--raw}'[raw hosts,don''t resolve dns]' \
'--usedns=[DNS specified replacement of tags <HOST> in regexp]::((yes\:matches all form of hosts no\:IP addresses only))' \
'(-L --maxlines=)'{-L,--maxlines}'[maxlines for multi-line regex]:MAXLINES' \
'(-m --journalmatch=)'{-m,--journalmatch=}'[journalctl style matches overriding filter file; "systemd-journal" only]:JOURNALMATCH' \
'(-l --log-level=)'{-l,--log-level}'[log level for the Fail2Ban logger to use]:LOG_LEVEL' \
'-V[get version in machine-readable short format]' \
'--verbosity=[set numerical level of verbosity]:(0 1 2 3 4)' \
'(--verbose-date --VD)'{--verbose-date,--VD}'[verbose date patterns/regex in output]' \
'(-D --debuggex)'{-D,--debuggex}'[produce debuggex.com urls for debugging there]' \
'--no-check-all[disable check for all regexes]' \
'(-o --out)'{-o,--out}'[set token to print failure information only (row, id, ip, msg, host, ip4, ip6, dns, matches, ...)]:out' \
'--print-no-missed[do not print any missed lines]' \
'--print-no-ignored[do not print any ignored lines]' \
'--print-all-matched[print all matched lines]' \
'--print-all-missed[print all missed lines, no matter how many]' \
'--print-all-ignored[print all ignored lines, no matter how many]' \
'(-t --log-traceback)'{-t,--log-traceback}'[enrich log-messages with compressed tracebacks]' \
'--full-traceback[enrich log-messages with full, uncompressed tracebacks]:' \
'1:file:_files -g \*.log' \
'2:file:_files -W /etc/fail2ban/filter.d -g \*\.\(conf\|local\)' \
'3:file:_files -W /etc/fail2ban/filter.d -g \*\.\(conf\|local\)'
}
_fail2ban_server() {
_arguments \
'(- *)'{-h,--help}'[display help message]' \
'(- *)'{-V,--version}'[print the version]' \
'(-c --conf)'{-c,--conf}'[configuration directory]:dir:_files -/' \
'(-s --socket)'{-s,--socket}'[socket path]:socket:_files' \
'(-p --pidfile)'{-p,--pidfile}'[pidfile path]:file:_files' \
'--pname[name of the process]:name' \
'--loglevel[logging level]:level' \
'--logtarget[logging target]:target:_files' \
'--syslogsocket[syslog socket]:file:_files' \
'-d[dump configuration for debugging]' \
'(--dp --dump-pretty)'{--dp,--dump-pretty}'[dump the configuration using more human readable representation]' \
'(-t --test)'{-t,--test}'[test configuration]' \
'-i[interactive mode]' \
\*'-v[increase verbosity]' \
\*'-q[decrease verbosity]' \
'-x[force execution of the server(remove socket file)]' \
'(-b -f --async)-b[start server in background(default)]' \
'(-b -f --async)-f[start server in foreground]' \
'(-b -f --async)--async[start server in async mode for internal usage]' \
'--timeout[timeout to wait for the server for internal usage]' \
'--str2sec[convert time abbreviation format to seconds]:str' \
}
_fail2ban_testcases() {
_arguments -s \
'(- *)--version[show program version number and exit]' \
'(- *)'{-h,--help}'[show help message and exit]' \
'(-l --log-level)'{-l,--log-level}'[log level for the logger]:level' \
\*'-v[Increase verbosity]' \
'--verbosity=[set numerical level of verbosity]:level:(0 1 2 3 4)' \
'--log-direct[prevent lazy logging inside tests]' \
'(-n --no-network)'{-n,--no-network}'[do not run tests that require the network]' \
'(-m --memory-db)'{-m,--memory-db}'[run database tests using memory instead of the file]' \
'(-f --fast)'{-f,--fast}'[try to increase speed of tests]' \
\*{-i,--ignore}'[negate regexps filter to ignore tests]:regexp' \
'(-t --log-traceback)'{-t,--log-traceback}'[enrich log-messages with compressed tracebacks]' \
'--full-traceback[make the tracebacks full, not compressed]' \
'*::regexp'
}
case $service in
(fail2ban-client)
_fail2ban_client
;;
(fail2ban-regex)
_fail2ban_regex
;;
(fail2ban-server)
_fail2ban_server
;;
(fail2ban-testcases)
_fail2ban_testcases
;;
esac
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: set et sw=2 ts=2 ft=zsh:

View File

@ -1,339 +0,0 @@
#compdef fail2ban-client
# ------------------------------------------------------------------------------
# Copyright (c) 2020 Github zsh-users - https://github.com/zsh-users
# All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for fail2ban-client (https://www.fail2ban.org/).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Felix Neumärker <xdch47@posteo.de>
#
# ------------------------------------------------------------------------------
_f2bc_jails() {
LANG=C fail2ban-client status 2> /dev/null | sed -n -e 's/.*Jail list:\s\+//' -e 'T' -e 's/,\s\+/\'$'\n/g' -e 'p'
}
_complete_f2bc_cmds() {
local cmds=(
'unban:unbans all IP addresses'
'set:set property'
'get:get property'
'status:gets the current status of the server'
'reload:reloads the configuration/jails'
'restart:restarts the server'
'start:starts the server and the jails'
'stop:stops all jails and terminate the server'
'ping:tests if the server is alive'
'flushlogs:flushes the logtarget if a file and reopens it'
'help:return this output'
'version:return the server version'
)
_describe -V "fail2ban commands" cmds
}
_complete_f2bc_cmdargs() {
local f2barg="$words[$NORMARG]"
case "$f2barg" in
unban)
local jail
if (( $words[(I)(--all)] == 0 )) ; then
for jail in $(_f2bc_jails) ; do
_complete_f2bc_ips $jail
done
local unban_opts=(--all)
_describe -o "unban options" unban_opts
else
_nothing
fi
;;
(set|get))
if (( $NORMARG + 1 == $CURRENT )) ; then
_complete_f2bc_jails
_complete_f2bc_settings
else
_complete_f2bc_jail${f2barg}
fi
;;
status)
if (( $NORMARG + 1 == $CURRENT )) ; then
_complete_f2bc_jails
elif (( $NORMARG + 2 == $CURRENT )) ; then
_values "flavor" basic cymru
else
_nothing
fi
;;
esac
}
_complete_f2bc_jails() {
local jails=($(_f2bc_jails))
_describe -V "jails" jails
}
_complete_f2bc_ips() {
local ips=("${(@f)$(LANG=C fail2ban-client status $1 2> /dev/null | sed -n -e 's/^.*Banned IP list:\s\+//' -e 'T' -e 's/\s\+/\'$'\n/g' -e 'p')}")
if [[ -n "${ips[@]}" ]] ; then
_describe -t "f2b_jail_$1" -V "banned ips of jail $1" ips
else
_nothing
fi
}
_complete_f2bc_jailset() {
if (( $NORMARG + 2 == $CURRENT )) ; then
case $words[$NORMARG+1] in
loglevel)
local loglevel=(CRITICAL ERROR WARNING NOTICE INFO DEBUG TRACEDEBUG HEAVYDEBUG)
_describe -V "loglevel" loglevel ;;
logtarget)
local logtarget=(STDOUT STDERR SYSLOG)
_describe -V "logtarget" logtarget
_files ;;
syslogsocket)
local syslogsocket=(auto)
_describe -V "logtarget" syslogsocket
_files ;;
dbfile)
_files ;;
dbpurgeage)
_message "sets the max age in <SECONDS> that history of bans will be kept" ;;
*)
# jail
local jailsettings=(
unbanip
banip
action
addaction
addfailregex
addignoreip
addignoreregex
addjournalmatch
addlogpath
bantime
datepattern
delaction
delfailregex
delignoreip
delignorerexgex
deljournalmatch
dellogpath
findtime
idle
ignorecache
ignorecommand
ignoreself
logencoding
maxlines
maxretry
usedns
)
_describe -t "f2b_jail_setting" -V "jail setting" jailsettings ;;
esac
else
local jail="$words[$NORMARG+1]"
if (( $NORMARG + 3 == $CURRENT )) ; then
case $words[$NORMARG+2] in
unbanip)
_complete_f2bc_ips "$jail" ;;
delfailregex)
_complete_f2bc_regex fail "$jail" ;;
delignorerexgex)
_complete_f2bc_regex ignore "$jail" ;;
dellogpath)
local filelist=("${(@f)$(LANG=C fail2ban-client status $jail 2> /dev/null | sed -n -e 's/^.*File list:\s\+//' -e 'T' -e 's/\s\+/\'$'\n/g' -e 'p')}")
if [[ -n "${filelist[@]}" ]] ; then
_describe -t "f2b_filelist" -V "filelist of jail $1" filelist
else
_nothing
fi ;;
idle)
_values 'fail2ban idle' on off ;;
ignoreself)
_values 'fail2ban ignoreself' true false ;;
delignoreip)
local ignoreips=("${(@f)$(fail2ban-client get "$jail" ignoreip 2> /dev/null | sed -e 's/^[|`]-\s\+//p')}")
if [[ -n "${ignoreips[@]}" ]] ; then
_describe -t "f2b_ignoreip" -V "fail2ban ignored ips" ignoreips
else
_nothing
fi ;;
delaction|action)
_complete_f2bc_action "$jail" ;;
addlogpath)
_files ;;
*)
_message "No completion for ${words[NORMARG+2]}" ;;
esac
elif (( $NORMARG + 4 == $CURRENT )) ; then
case $words[$NORMARG+2] in
action)
_complete_f2bc_actionproperties "$jail" $words[$NORMARG+3] ;;
addaction)
_files ;;
*)
_nothing ;;
esac
else
_nothing
fi
fi
}
_complete_f2bc_jailget() {
if (( $NORMARG + 2 == $CURRENT )) ; then
case $words[$NORMARG+1] in
(loglevel|logtarget|syslogsocket|dbfile|dbpurgeage))
_nothing ;;
*)
# jail
local jailprops=(
logpath
logencoding
journalmatch
ignoreself
ignoreip
ignorecommand
failregex
ignoreregex
findtime
bantime
datepattern
usedns
maxretry
maxlines
actions
action
actionproperties
actionmethods
)
_describe -t "f2b_jail_props" -V "jail properties" jailprops ;;
esac
else
local jail="$words[$NORMARG+1]"
if (( $NORMARG + 3 == $CURRENT )) ; then
case $words[$NORMARG+2] in
(action|actionproperties|actionmethods))
_complete_f2bc_action "$jail" ;;
*)
_nothing ;;
esac
elif (( $NORMARG + 4 == $CURRENT )) ; then
case $words[$NORMARG+2] in
(action|actionproperties|actionmethods))
_complete_f2bc_actionproperties "$jail" $words[$NORMARG+3] ;;
*)
_nothing ;;
esac
else
_nothing
fi
fi
}
_complete_f2bc_action() {
local jailactions=("${(@f)$(fail2ban-client get $1 actions 2>/dev/null | sed -e '1d' -e 's/,\s\+/\'$'\n/g')}")
if [[ -n "${jailactions[@]}" ]] ; then
_describe -t "f2b_jail_actions" -V "jail actions" jailactions
else
_nothing
fi
}
_complete_f2bc_actionproperties() {
local default_actionproperties=(
actionstart
actionstop
actioncheck
actionban
actionunban
timeout
)
local all_actionproperties=("${(@f)$(fail2ban-client get $1 actionproperties $2 2>/dev/null | sed -e '1d' -e 's/,\s\+/\'$'\n/g')}")
local add_actionproperties=("${(@)all_actionproperties:|default_actionproperties}")
_describe -t "f2b_actions_defprops" -V "default action properties" default_actionproperties
if [[ -n "${add_actionproperties[@]}" ]] ; then
_describe -t "f2b_actions_remprops" -V "additional action properties" add_actionproperties
else
_nothing
fi
}
_complete_f2bc_regex() {
local regex=("${(@f)$(fail2ban-client get $2 ${1}regex 2> /dev/null | sed -n -e 's/[|`]- \[\([0-9]\+\)\]:\s\+/\1:/p')}")
if [[ -n "${regex[@]}" ]] ; then
_describe -t "f2b_regex" -V "jail $2 ${1}regex" regex
else
_nothing
fi
}
_complete_f2bc_settings() {
local setargs=(loglevel logtarget syslogsocket dbfile dbpurgeage)
_describe -t "f2b_settings" -V "fail2ban-client settings" setargs
}
integer NORMARG
_arguments -A "-*" -n \
'-c[configuration directory]:_files -/' \
'-s[socket path]:_files' \
'-p[pidfile path]:_files' \
'--loglevel[logging level]:(CRITICAL ERROR WARNING, NOTICE INFO, DEBUG, TRACEDEBUG HEAVYDEBUG)' \
'--logtarget[logging target]:(stdout stderr syslog sysout)' \
'--syslogsocket:_files' \
'-d[dump configuration]' \
'(--dp --dump-pretty)'{--dp,--dump-pretty}'[dump the configuration using more human readable representation]' \
'(-t --test)'{-t,--test}'[test configuration]' \
'-i[interactive mode]' \
'-v[increase verbosity]' \
'-q[decrease verbosity]' \
'-x[force execution of the server (remove socket file)]' \
'-b[start server in background]' \
'-f[start server in foreground]' \
'--str2sec[convert time abbreviation format to seconds]:_message str2sec' \
'(-h --help)'{-h,--help}'[display this help message]' \
'(-V --version)'{-V,--version}'[print the version]' \
'1:fail2ban command:_complete_f2bc_cmds' \
'*:fail2ban command argument:_complete_f2bc_cmdargs'
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: set et sw=2 ts=2 ft=zsh:

View File

@ -1,57 +0,0 @@
#compdef fail2ban-regex
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for fail2ban-regex (https://www.fail2ban.org/).
# Environment:
# Linux 6.14.10-arch1-1 x86_64 GNU/Linux
# zsh 5.9 (x86_64-pc-linux-gnu)
# fail2ban 1.1.0-7
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Jesse Ayala <jesserayala95@gmail.com>
#
# ------------------------------------------------------------------------------
integer NORMARG
_arguments -A "-*" -n \
'--version[show program''s version number]' \
'(-h --help)'{-h,--help}'[display the help message]' \
'(-c --config)'{-c,--config=}'[set alternate config directory]:directory:_files -/' \
'(-d --datepattern)'{-d,--datepattern=}'[set custom pattern used to match date/times]:DATEPATTERN' \
'(--timezone= --TZ=)'{--timezone=,--TZ=}'[set time-zone used by convert time format]:TIMEZONE' \
'(-e --encoding=)'{-e,--encoding=}'[use different encoding from system locale]:ENCODING' \
'(-r --raw)'{-r,--raw}'[raw hosts,don''t resolve dns]' \
'--usedns=[DNS specified replacement of tags <HOST> in regexp]::((yes\:matches all form of hosts no\:IP addresses only))' \
'(-L --maxlines=)'{-L,--maxlines}'[maxlines for multi-line regex]:MAXLINES' \
'(-m --journalmatch=)'{-m,--journalmatch=}'[journalctl style matches overriding filter file; "systemd-journal" only]:JOURNALMATCH' \
'(-l --log-level=)'{-l,--log-level}'[log level for the Fail2Ban logger to use]:LOG_LEVEL' \
'-V[get version in machine-readable short format]' \
'--verbosity=[set numerical level of verbosity]:(0 1 2 3 4)' \
'(--verbose-date --VD)'{--verbose-date,--VD}'[verbose date patterns/regex in output]' \
'(-D --debuggex)'{-D,--debuggex}'[produce debuggex.com urls for debugging there]' \
'--no-check-all[disable check for all regexes]' \
'(-o --out)'{-o,--out}'[set token to print failure information only (row, id, ip, msg, host, ip4, ip6, dns, matches, ...)]:out' \
'--print-no-missed[do not print any missed lines]' \
'--print-no-ignored[do not print any ignored lines]' \
'--print-all-matched[print all matched lines]' \
'--print-all-missed[print all missed lines, no matter how many]' \
'--print-all-ignored[print all ignored lines, no matter how many]' \
'(-t --log-traceback)'{-t,--log-traceback}'[enrich log-messages with compressed tracebacks]' \
'--full-traceback[enrich log-messages with full, uncompressed tracebacks]:' \
'1:file:_files -g \*.log' \
'2:file:_files -W /etc/fail2ban/filter.d -g \*\.\(conf\|local\)' \
'3:file:_files -W /etc/fail2ban/filter.d -g \*\.\(conf\|local\)'
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: set et sw=2 ts=2 ft=zsh:

534
src/_port
View File

@ -3,7 +3,7 @@
# Description
# -----------
#
# Completion script for MacPorts (https://www.macports.org/).
# Completion script for MacPorts 2.12.1 (https://www.macports.org/).
#
# ------------------------------------------------------------------------------
# Authors
@ -43,57 +43,309 @@
#
# ------------------------------------------------------------------------------
# global variable
#_port_available_packages
#_port_installed_packages
_port() {
local -a revupgrade_options select_options \
pseudo_common pseudo_advanced port_prefix
typeset -A opt_args
local context state line
local curcontext="$curcontext"
local ret=1
local port_path=$(which port)
port_prefix=${port_path%/bin/port}
pseudo_common=(all current active inactive actinact installed uninstalled outdated
obsolete requested unrequested leaves rleaves)
pseudo_advanced=('variants:' 'variant:' 'description:' 'depends:'
'depends_lib:' 'depends_run:' 'depends_build:' 'depends_fetch:' 'depends_extract:'
'portdir:' 'homepage:' 'epoch:' 'platforms:' 'platform:' 'name:' 'long_description:'
'maintainers:' 'maintainer:' 'categories:' 'category:' 'version:' 'revision:' 'license:')
select_options=(
'--summary:Display summary of selected options'
'--list:List available versions for the group'
'--set:Select the given version for the group'
'--show:Show which version is currently selected for the group (default if none given)'
)
revupgrade_options=('--id-loadcmd-check:Run more checks against a special loadcommand in Mach-O binaries')
local port_prefix=${commands[port]%/bin/port}
_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)]' \
'-N[Non-interactive mode]' \
"-n[Don't follow dependencies in upgrade (affects upgrade and install)]" \
"-R[Also upgrade dependents (only affects upgrade) ]" \
'-u[Uninstall inactive ports when upgrading and uninstalling]' \
'-y[Perform a dry run]' \
'-s[Source-only mode (build and install from source)]' \
'-b[Binary-only mode (build and install from binary archives)]' \
'-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 (macOS).]' \
'-p[Despite any errors encountered, proceed to process multiple ports and commands]' \
'-o[Honor state files even if the Portfile has been modified since]' \
'-t[Enable trace mode debug facilities on platforms that support it]' \
'-f[Force mode, ignore state file]' \
'-D[Specify portdir]:dir:_files -/' \
'-F[Read and process the file of commands specified by the argument]:file:_files' \
"1:Port actions:_port_actions" \
'::Per-action arguments:_port_dispatch' \
&& return 0
'*::arg:->args' \
&& ret=0
case "$state" in
(args)
local subcmd=$words[1]
local cache_policy
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
zstyle ":completion:${curcontext}:" cache-policy ${cache_policy:-_port_caching_policy}
local -a log_phases=('fetch' 'checksum' 'extract' 'patch' 'configure' 'build' 'destroot')
local -a no_portname_commands=(
'help' 'diagnose' 'migrate' 'outdated' 'platform' 'provides' 'reclaim' 'restore'
'rev-upgrade' 'search' 'select' 'selfupdate' 'snapshot' 'sync' 'usage'
)
local -a show_installed_package_commands=(
contents deactivate setrequested space unsetrequested uninstall
)
local -a options=()
case $subcmd in
(activate|deactivate)
options+=('--no-exec[Do not execute any stored pre- or post-uninstall procedures]')
;;
(archivefetch)
options+=('-p[Proceed even if a port fails to fetch]')
;;
(fetch|checksum|extract|patch|configure|build|destroot|test)
options+=('--no-mirrors[Only fetch files from URLs in master_sites]')
;;
(bump)
options+=('--patch[Create a Portfile.patch file instead of directly overwriting the Portfile]')
;;
(clean)
options+=(
'--archive[Remove partially downloaded binary archives]'
'--dist[Delete source code archives, the so-called distfiles]'
'--logs[Delete log files]'
'--work[Delete the work directory of a port]'
'--all[Remove all temporary files]'
)
;;
(contents)
options+=(
"--size[Enable printing a human-readable representation of the files' size]"
'--units[Used in conjunction with --size to choose the unit in which the size is given]:units:_port_units'
)
;;
(deps|rdeps)
options+=(
'--index[Do not read Portfiles, but instead rely solely on the PortIndex information]'
'--no-build[Exclude dependencies only required at build time]'
'--no-test[Exclude test dependencies]'
)
if [[ $subcmd == "rdeps" ]]; then
options+=('--full[Display all branches of the dependency tree instead of listing each dependency only once]')
fi
;;
(diagnose)
options+=('--quiet[Only display warnings or errors]')
;;
(edit)
options+=('--editor[Use the specified editor]:editor')
;;
(help)
options+=('1:action:_port_actions')
;;
(info)
options+=(
'--index[Do not read the Portfile, but rely solely on the port index information]'
'--line[Print a single line for each port]'
'--pretty[Format the output in a convenient, human-readable fashion]'
'(--category --categories)'{--category,--categories}'[List the categories of a port]'
'--conflicts[List other ports that cannot be activate at the same time as the given port]'
'--depends_fetch[List the fetch dependencies of a port]'
'--depends_extract[List the extract dependencies of a port]'
'--depends_build[List the build dependencies of a port]'
'--depends_lib[List the lib dependencies of a port]'
'--depends_run[List the run dependencies of a port]'
'--depends[List the all dependencies of a port]'
'(--description --long_description)--description[Print the short description of a port]'
'(--description --long_description)--long_description[Print the long description of a port]'
'--epoch[List the epoch components of a MacPorts]'
'--version[List the version components of a MacPorts]'
'--revision[List the revision components of a MacPorts]'
'--fullname[Print name and the full MacPorts version tuple]'
'--heading[Like --fullname but including the categories]'
'--homepage[List the homepage of a port]'
'--license[Print the license that applies to the source code of a port]'
'(--maintainer --maintainers)'{--maintainer,--maintainers}"[List the email address(es) of a port's maintainer(s)]"
'--name[Print the name of a port]'
'--pathfiles[List the patches that will be applied to the port]'
'(--platform --platforms)'{--platform,--platforms}'[List the platforms supported by a port]'
"--portdir[Print the path to a port's directory]"
'--replaced_by[List the name of the port that replaces a port]'
"--subports[Print a list of subports defined by this port's Portfile]"
'(--variant --variants)'{--variant,--variants}'[List the variants defined by a port by name]'
)
;;
(install)
options+=(
'--allow-failing[Attempt installation even if the specified port is known to fail]'
'--no-replace[Attempt to install specified port even if it is replaced by another port]'
'--no-rev-upgrade[Do not run rev-upgrade after installation]'
'--unrequested[Do not mark the installed ports as requested]'
)
;;
(lint)
options+=('--nitpick[Enable additional checks that are mostly whitespace-related and best practices]')
;;
(log)
options+=(
'--level[Log level]:level:(error warn msg info debug)'
'--phase[Only print messages that were generated in the given installation phase]:phase:($log_phases)'
)
;;
(migrate)
options+=(
'--all[Migrate all ports including unrequested ones]'
'--continue[Continue with migration of ports]'
)
;;
(mirror)
options+=('--new[Delete the existing database of mirrored files and re-create it from scratch]')
;;
(provides)
options+=('*::file:_files')
;;
(reclaim)
options+=(
'--keep-build-deps[Consider build-time dependency ports to be considered needed]'
'(--enable-reminders --disable-reminders)--enable-reminders[Enable regular reminders to run "port reclaim"]'
'(--enable-reminders --disable-reminders)--disable-reminders[Disable reminders to run "port reclaim"]'
)
;;
(restore)
options+=(
'--snapshot-id[Restore the snapshot with the specified ID]:id:_port_snapshot_ids'
'--last[Restore the last created snapshot]'
'--all[Restore all ports in the snapshot including unrequested ones]'
)
;;
(rev-upgrade)
options+=('--id-loadcmd-check[Check the ID load command in each library installed by MacPorts]')
;;
(search)
options+=(
'--case-sensitive[Do not ignore case when searching for the given keyword]'
'(--exact --glob --regex)--exact[Search for the given string exactly]'
'(--exact --glob --regex)--glob[Treat the keyword(s) as wildcard]'
'(--exact --glob --regex)--regex[Treat the given string as a Tcl regular expression]'
'--line[Print one match per line]'
'(--category --categories)'{--category,--categories}'[Search the category]'
'--depends_fetch[Search the fetch dependencies of a port]'
'--depends_extract[Search the extract dependencies of a port]'
'--depends_build[Search the build dependencies of a port]'
'--depends_lib[Search the lib dependencies of a port]'
'--depends_run[Search the run dependencies of a port]'
'--depends[Search the all dependencies of a port]'
'(--description --long_description)--description[Test the search string against the description]'
'(--description --long_description)--long_description[Test the search string against the long description]'
'--homepage[Search for the keyword(s) in the homepage property]'
'(--maintainer --maintainers)'{--maintainer,--maintainers}"[Search for maintainers]"
'--name[Search in ports name]'
"--portdir[Test the search string against the path of the directory that contains the port]"
'(--variant --variants)'{--variant,--variants}'[Search for variant names]'
)
;;
(select)
options+=(
'--summary:Display summary of selected options'
'--list:List available versions for the group'
'--set:Select the given version for the group'
'--show:Show which version is currently selected for the group (default if none given)'
'1:group:_port_select_groups'
'2:variant:_port_select_variants'
)
;;
(selfupdate)
options+=(
'--no-sync[Only check for updates and install if available]'
'--migrate[Rebuild even if no new version is available]'
'--rsync[Use the older rsync method for downloading the new version of MacPorts]'
)
;;
(snapshot)
options+=(
'--create[Create a new snapshot that records the current active ports]'
'--note[Label with the given note when creating a snapshot]:note'
'--list[Display a list of all snapshots that currently exist]'
'--diff[Display the differences between the given snapshot ID and currently installed ports]:id:_port_snapshot_ids'
'--all[Consider all ports when displaying diffs]'
'--delete[Delete the snapshot with the given ID number]:id:_port_snapshot_ids'
'--export[Generate a JSON representation of the snapshot with the given ID number]:id:_port_snapshot_ids'
'--import[Create a new snapshot from the information in the given file]:file:_files'
'(- *)--help[Display brief usage information]'
)
;;
(space)
options+=(
'--total[Only print the total amount of space used by all given ports]'
'--units[Choose the unit in which the size is given]:unit:_port_units'
)
;;
(uninstall)
options+=(
'--follow-dependents[Also uninstall all ports recursively depending directly or indirectly]'
'--follow-dependencies[Also recursively uninstall all ports that the given port depends on]'
'--no-exec[Do not execute any stored pre- or post-uninstall procedures]'
)
;;
(upgrade)
options+=(
'--enforce-variants[Upgrade all given ports and their dependencies]'
'--force[Ignore circumstances that would normally cause ports to be skipped]'
'--no-replace[Do not automatically install ports that replace a new-obsolete port you have installed]'
'--no-rev-upgrade[Do not run rev-upgrade after upgrading]'
)
;;
(variants)
options+=('--index[Do not read the Portfile]')
;;
esac
if (( $no_portname_commands[(Ie)$subcmd] )); then
_arguments \
$options[@] \
&& ret=0
else
local -a pseudo_port_names=(
all current active inactive actinact installed uninstalled outdated
obsolete requested unrequested leaves rleaves
)
local -a selectors=(
'variants:' 'variant:' 'description:' 'depends:'
'depends_lib:' 'depends_run:' 'depends_build:' 'depends_fetch:' 'depends_extract:'
'portdir:' 'homepage:' 'epoch:' 'platforms:' 'platform:' 'name:' 'long_description:'
'maintainers:' 'maintainer:' 'categories:' 'category:' 'version:' 'revision:' 'license:'
'depof:' 'rdepof:' 'rdepends:' 'dependentof:' 'rdependentof:'
)
if (( $show_installed_package_commands[(Ie)$subcmd] )); then
_port_update_cache "installed"
_arguments \
$options[@] \
'1: :_port_installed_ports' \
'*: :_port_options' \
&& ret=0
else
_port_update_cache "all"
_arguments \
$options[@] \
'1: :_port_available_ports' \
'*: :_port_options' \
&& ret=0
fi
fi
;;
esac
return ret
}
(( $+functions[_port_actions] )) ||
_port_actions() {
local -a actions
actions=(
local -a 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'
@ -113,7 +365,6 @@ _port_actions() {
'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'
@ -132,6 +383,7 @@ _port_actions() {
'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'
'migrate:Update MacPorts for a new platform'
'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'
@ -143,14 +395,16 @@ _port_actions() {
'rdependents:Recursive version of dependents'
'rdeps:Display a recursive dependency listing for the given ports'
'reclaim:Reclaims disk space'
'reload:Restart daemon'
'restore:Restore snapshots of installed 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'
'setunrequested:Marks each of the given ports as unrequested'
'snapshot:Create and manage snapshots of installed ports'
'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'
@ -168,118 +422,130 @@ _port_actions() {
_describe -t actions 'actions' actions
}
_port_dispatch() {
local cache_policy
zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
zstyle ":completion:${curcontext}:" cache-policy ${cache_policy:-_port_caching_policy}
(( $+functions[_port_options] )) ||
_port_options() {
local current_arg=$words[CURRENT]
case "$words[2]" in
provides)
_files
;;
search)
_message 'pattern'
;;
help)
_port_actions
;;
select)
_call_function - _port_select
;;
contents|deactivate|setrequested|space|uninstall|unsetrequested)
# Cache the list of installed ports.
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 -q echo installed") )
_store_cache PORT_INSTALLED_PACKAGES _port_installed_packages
fi
_alternative \
"ports:Installed ports:($_port_installed_packages)" \
"pseudo-common:Common Pseudo-portnames:($pseudo_common)" \
"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 -q echo outdated") )
_alternative -- \
"upgrade-options:Upgrade options:_port_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
_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 ) &&
! _retrieve_cache PORT_AVAILABLE_PACKAGES;
then
_port_available_packages=( $(_call_program path-all "port -q echo all") )
_store_cache PORT_AVAILABLE_PACKAGES _port_available_packages
fi
_alternative \
"ports:Available ports:($_port_available_packages)" \
"pseudo-common:Common Pseudo-portnames:($pseudo_common)" \
"pseudo-advanced:Advanced Pseudo-portnames:($pseudo_advanced)"
;;
esac
}
(( $+functions[_port_upgrade_options] )) ||
_port_upgrade_options() {
local -a options
options=(
'--enforce-variants:Upgrade all given ports and their dependencies'
'--force:Ignore circumstances that would normally cause ports to be skipped'
'--no-replace:Do not automatically install ports that replace a new-obsolete port you have installed'
'--no-rev-upgrade:Do not run rev-upgrade after upgrading'
)
_describe -t options 'options' options
}
_port_select() {
if (( CURRENT == 3 )); then
_describe 'Port select options' select_options
elif (( CURRENT == 4 )); then
local select_group=($port_prefix/etc/select/*(N:t))
_describe "Port select groups" select_group
elif [[ $CURRENT -eq 5 && $words[3] == '--set' ]]; then
local select_variants
select_variants=("${(f)$(port select --list $words[4] | sed -e '1 d' -e 's/^[ \t]*//' -e 's/ (active)$//')}")
_describe "Port select group $words[4] variants" select_variants
# complete variants
if [[ $current_arg == +* || $current_arg == -* ]]; then
IPREFIX=$current_arg[1]
PREFIX=$current_arg[2,-1]
_port_variants $words[2]
fi
}
(( $+functions[_port_available_ports] )) ||
_port_available_ports() {
_alternative \
'ports:Available ports:($_port_available_packages)' \
'pseudo-common:Common Pseudo-portnames:($pseudo_port_names)' \
'selectors:Pseudo portname selectors:($selectors)'
}
(( $+functions[_port_installed_ports] )) ||
_port_installed_ports() {
_alternative \
"ports:Installed ports:($_port_installed_packages)" \
"pseudo-common:Common Pseudo-portnames:($pseudo_port_names)" \
"selectors:Pseudo portname selectors:($selectors)"
}
(( $+functions[_port_caching_policy] )) ||
_port_caching_policy() {
local reg_time comp_time check_file
zmodload -F zsh/stat b:zstat 2> /dev/null
case "${1##*/}" in
PORT_INSTALLED_PACKAGES)
(PORT_INSTALLED_PACKAGES)
check_file=$port_prefix/var/macports/registry/registry.db
;;
PORT_AVAILABLE_PACKAGES)
(PORT_AVAILABLE_PACKAGES)
check_file=${$(port dir MacPorts)%/*/*}/PortIndex
;;
esac
reg_time=$(zstat +mtime $check_file)
comp_time=$(zstat +mtime $1)
return $(( reg_time < comp_time ))
}
(( $+functions[_port_update_cache] )) ||
_port_update_cache() {
local cache_type=$1
case "$cache_type" in
(all)
# Cache the list of all ports.
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 -q echo all") )
_store_cache PORT_AVAILABLE_PACKAGES _port_available_packages
fi
;;
(installed)
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 -q echo installed") )
_store_cache PORT_INSTALLED_PACKAGES _port_installed_packages
fi
;;
esac
}
(( $+functions[_port_select_groups] )) ||
_port_select_groups() {
local -a groups=($port_prefix/etc/select/*(N:t))
_describe "Port select groups" groups
}
(( $+functions[_port_select_variants] )) ||
_port_select_variants() {
local group=$words[2]
local -a variants=("${(f)$(port select --list $group | awk '/^[ \t]+/{print $1}')}")
_describe "Port select group $words[4] variants" variants
}
(( $+functions[_port_snapshot_ids] )) ||
_port_snapshot_ids() {
local -a snapshot_ids=()
if (( $+commands[perl] )); then
local perl_expr='m{^\s+(\d+)\s+(.*)$} and printf "%s:%s\n", $1, $2'
snapshot_ids=("${(f)$(port snapshot --list | perl -wln -e $perl_expr)}")
else
local awk_expr='NR > 2 { printf("%s:%s %s\n", $1, $2, $3) }'
snapshot_ids=("${(f)$(port snapshot --list | awk $awk_expr)}")
fi
_describe "Port snapshot IDs" snapshot_ids
}
(( $+functions[_port_variants] )) ||
_port_variants() {
local name=$1
if (( $+commands[perl] )); then
local -a variants=($(port variants $name | perl -wln -e 'm{^(?:\s+|\[\+\])([^:]+):} and print $1'))
if [[ ${#variants} != 0 ]]; then
_values 'variant' $variants
fi
fi
}
(( $+functions[_port_units] )) ||
_port_units() {
local -a units=(
"B[List sizes in bytes]"
{K,Ki,KiB}"[List sizes in KiB, 1024 bytes]"
{Mi,MiB}'[List sizes in MiB, 1024 * 1024 bytes]'
{Gi,GiB}'[List sizes in GiB, 1024 * 1024 * 1024 bytes]'
{k,kB}'[List sizes in kB, 1000 bytes]'
{M,MB}'[List sizes in kB, 1000 * 1000 bytes]'
{G,GB}'[List sizes in kB, 1000 * 1000 * 1000 bytes]'
)
_values 'unit' $units
}
_port "$@"
# Local Variables: