diff --git a/src/_chromium b/src/_chromium index 96e76b1..25aa19b 100644 --- a/src/_chromium +++ b/src/_chromium @@ -108,8 +108,8 @@ _chromium_proxyurls () { do while _next_label prefixes expl 'URL prefix' -S '' "$@" do - compset -S '[^:/]*' && compstate[to_end]='' - compadd "$expl[@]" http:// socks:// socks4:// socks5:// && ret=0 + compset -S '[^:/]*' && compstate[to_end]='' + compadd "$expl[@]" http:// socks:// socks4:// socks5:// && ret=0 done (( ret )) || return 0 done @@ -123,27 +123,27 @@ _chromium_proxyurls () { return fi ;; (file) [[ -prefix //(127.0.0.1|localhost)/ ]] && compset -P '//(127.0.0.1|localhost)' - [[ -prefix /// ]] && compset -P // - if ! compset -P // - then - _tags -C file files - while _tags - do - while _next_label files expl 'local file' - do - if [[ -prefix / ]] - then - _path_files "$expl[@]" -S '' "${glob[@]}" && ret=0 - _path_files "$expl[@]" -S/ -r '/' -/ && ret=0 - elif [[ -z "$PREFIX" ]] - then - compadd -S '/' -r '/' "$expl[@]" "$@" - "${PWD%/}" && ret=0 - fi - done - (( ret )) || return 0 - done - return 1 - fi ;; + [[ -prefix /// ]] && compset -P // + if ! compset -P // + then + _tags -C file files + while _tags + do + while _next_label files expl 'local file' + do + if [[ -prefix / ]] + then + _path_files "$expl[@]" -S '' "${glob[@]}" && ret=0 + _path_files "$expl[@]" -S/ -r '/' -/ && ret=0 + elif [[ -z "$PREFIX" ]] + then + compadd -S '/' -r '/' "$expl[@]" "$@" - "${PWD%/}" && ret=0 + fi + done + (( ret )) || return 0 + done + return 1 + fi ;; esac if ! compset -P '(#b)([^:/]#)([:/])' then @@ -153,10 +153,10 @@ _chromium_proxyurls () { do while _next_label hosts expl host do - compset -S '[:/]*' || suf="/" - (( $#uhosts )) || _hosts -S "$suf" -r '/:' "$expl[@]" && ret=0 - [[ "$scheme" = http ]] && uhosts=($uhosts $localhttp_servername) - compadd -S "$suf" -r '/:' "$expl[@]" -a uhosts && ret=0 + compset -S '[:/]*' || suf="/" + (( $#uhosts )) || _hosts -S "$suf" -r '/:' "$expl[@]" && ret=0 + [[ "$scheme" = http ]] && uhosts=($uhosts $localhttp_servername) + compadd -S "$suf" -r '/:' "$expl[@]" -a uhosts && ret=0 done (( ret )) || return 0 done @@ -171,28 +171,28 @@ _chromium_proxyurls () { then if ! compset -P '(#b)([^/]#)/' then - _users -S/ "$@" - return + _users -S/ "$@" + return fi user="$match[1]" while _tags do - while _next_label files expl 'local file' - do - _path_files "$expl[@]" "$@" -W ~$user/$localhttp_userdir "${glob[@]}" && ret=0 - _path_files -S/ -r '/' "$expl[@]" -W ~$user/$localhttp_userdir-/ && ret=0 - done - (( ret )) || return 0 + while _next_label files expl 'local file' + do + _path_files "$expl[@]" "$@" -W ~$user/$localhttp_userdir "${glob[@]}" && ret=0 + _path_files -S/ -r '/' "$expl[@]" -W ~$user/$localhttp_userdir-/ && ret=0 + done + (( ret )) || return 0 done else while _tags do - while _next_label files expl 'local file' - do - _path_files "$expl[@]" "$@" -W $localhttp_documentroot "${glob[@]}" && ret=0 - _path_files -S/ -r '/' "$expl[@]" -W $localhttp_documentroot -/ && ret=0 - done - (( ret )) || return 0 + while _next_label files expl 'local file' + do + _path_files "$expl[@]" "$@" -W $localhttp_documentroot "${glob[@]}" && ret=0 + _path_files -S/ -r '/' "$expl[@]" -W $localhttp_documentroot -/ && ret=0 + done + (( ret )) || return 0 done fi else @@ -200,8 +200,8 @@ _chromium_proxyurls () { do (( $#urls )) && while _next_label files expl 'local file' do - _path_files "$expl[@]" "$@" -W $urls/$scheme/$host "${glob[@]}" && ret=0 - _path_files -S/ -r '/' "$expl[@]" -W $urls/$scheme/$host -/ && ret=0 + _path_files "$expl[@]" "$@" -W $urls/$scheme/$host "${glob[@]}" && ret=0 + _path_files -S/ -r '/' "$expl[@]" -W $urls/$scheme/$host -/ && ret=0 done [[ $scheme = (scp|sftp) ]] && _requested remote-files && _remote_files -h $host -- ssh && ret=0 (( ret )) || return 0 diff --git a/src/_git-flow b/src/_git-flow index 55bc63c..b71063b 100644 --- a/src/_git-flow +++ b/src/_git-flow @@ -40,397 +40,367 @@ # # ------------------------------------------------------------------------------ +_git-flow () { + local curcontext="$curcontext" state line + typeset -A opt_args -_git-flow () -{ - local curcontext="$curcontext" state line - typeset -A opt_args + _arguments -C \ + ':command:->command' \ + '*::options:->options' - _arguments -C \ - ':command:->command' \ - '*::options:->options' + case $state in + (command) + local -a subcommands + subcommands=( + 'init:Initialize a new git repo with support for the branching model.' + 'feature:Manage your feature branches.' + 'release:Manage your release branches.' + 'hotfix:Manage your hotfix branches.' + 'support:Manage your support branches.' + 'version:Shows version information.' + ) + _describe -t commands 'git flow' subcommands + ;; - case $state in - (command) + (options) + case $line[1] in + (init) + _arguments \ + -f'[Force setting of gitflow branches, even if already configured]' \ + -d'[Use default branch naming conventions and prefixes]' + ;; + (version) + ;; + (hotfix) + __git-flow-hotfix + ;; + (release) + __git-flow-release + ;; + (feature) + __git-flow-feature + ;; + (support) + __git-flow-support + ;; - local -a subcommands - subcommands=( - 'init:Initialize a new git repo with support for the branching model.' - 'feature:Manage your feature branches.' - 'release:Manage your release branches.' - 'hotfix:Manage your hotfix branches.' - 'support:Manage your support branches.' - 'version:Shows version information.' - ) - _describe -t commands 'git flow' subcommands - ;; - - (options) - case $line[1] in - - (init) - _arguments \ - -f'[Force setting of gitflow branches, even if already configured]' \ - -d'[Use default branch naming conventions and prefixes]' - ;; - - (version) - ;; - - (hotfix) - __git-flow-hotfix - ;; - - (release) - __git-flow-release - ;; - - (feature) - __git-flow-feature - ;; - - (support) - __git-flow-support - ;; - - esac - ;; - esac + esac + ;; + esac } -__git-flow-release () -{ - local curcontext="$curcontext" state line - typeset -A opt_args +__git-flow-release () { + local curcontext="$curcontext" state line + typeset -A opt_args - _arguments -C \ - ':command:->command' \ - '*::options:->options' + _arguments -C \ + ':command:->command' \ + '*::options:->options' - case $state in - (command) + case $state in + (command) + local -a subcommands + subcommands=( + 'start:Start a new release branch.' + 'finish:Finish a release branch.' + 'list:List all your release branches. (Alias to `git flow release`)' + 'publish:Publish this release branch to origin.`)' + 'track:Track a release branch from origin.`)' + ) + _describe -t commands 'git flow release' subcommands + _arguments \ + -v'[Verbose (more) output]' + ;; - local -a subcommands - subcommands=( - 'start:Start a new release branch.' - 'finish:Finish a release branch.' - 'list:List all your release branches. (Alias to `git flow release`)' - 'publish:Publish this release branch to origin.`)' - 'track:Track a release branch from origin.`)' - ) - _describe -t commands 'git flow release' subcommands - _arguments \ - -v'[Verbose (more) output]' - ;; - - (options) - case $line[1] in - - (start) - _arguments \ - -F'[Fetch from origin before performing finish]'\ - ':version:__git_flow_version_list' - ;; - - (finish) - _arguments \ - -F'[Fetch from origin before performing finish]' \ - -s'[Sign the release tag cryptographically]'\ - -u'[Use the given GPG-key for the digital signature (implies -s)]'\ - -m'[Use the given tag message]'\ - -n'[Don'\''t tag this release]'\ - -p'[Push to $ORIGIN after performing finish]'\ - -k'[Keep branch after performing finish]'\ - ':version:__git_flow_version_list' - ;; - - (publish) - _arguments \ - ':version:__git_flow_version_list' - ;; - - (track) - _arguments \ - ':version:__git_flow_version_list' - ;; - - - - *) - _arguments \ - -v'[Verbose (more) output]' - ;; - esac - ;; - esac + (options) + case $line[1] in + (start) + _arguments \ + -F'[Fetch from origin before performing finish]'\ + ':version:__git_flow_version_list' + ;; + (finish) + _arguments \ + -F'[Fetch from origin before performing finish]' \ + -s'[Sign the release tag cryptographically]'\ + -u'[Use the given GPG-key for the digital signature (implies -s)]'\ + -m'[Use the given tag message]'\ + -n'[Don'\''t tag this release]'\ + -p'[Push to $ORIGIN after performing finish]'\ + -k'[Keep branch after performing finish]'\ + ':version:__git_flow_version_list' + ;; + (publish) + _arguments \ + ':version:__git_flow_version_list' + ;; + (track) + _arguments \ + ':version:__git_flow_version_list' + ;; + *) + _arguments \ + -v'[Verbose (more) output]' + ;; + esac + ;; + esac } -__git-flow-hotfix () -{ - local curcontext="$curcontext" state line - typeset -A opt_args +__git-flow-hotfix () { + local curcontext="$curcontext" state line + typeset -A opt_args - _arguments -C \ - ':command:->command' \ - '*::options:->options' + _arguments -C \ + ':command:->command' \ + '*::options:->options' - case $state in - (command) + case $state in + (command) + local -a subcommands + subcommands=( + 'start:Start a new hotfix branch.' + 'finish:Finish a hotfix branch.' + 'list:List all your hotfix branches. (Alias to `git flow hotfix`)' + 'publish:Publish this hotfix branch to origin`)' + ) + _describe -t commands 'git flow hotfix' subcommands + _arguments \ + -v'[Verbose (more) output]' + ;; - local -a subcommands - subcommands=( - 'start:Start a new hotfix branch.' - 'finish:Finish a hotfix branch.' - 'list:List all your hotfix branches. (Alias to `git flow hotfix`)' - 'publish:Publish this hotfix branch to origin`)' - ) - _describe -t commands 'git flow hotfix' subcommands - _arguments \ - -v'[Verbose (more) output]' - ;; + (options) + case $line[1] in + (start) + _arguments \ + -F'[Fetch from origin before performing finish]'\ + ':hotfix:__git_flow_version_list'\ + ':branch-name:__git_branch_names' + ;; - (options) - case $line[1] in + (finish) + _arguments \ + -F'[Fetch from origin before performing finish]' \ + -s'[Sign the release tag cryptographically]'\ + -u'[Use the given GPG-key for the digital signature (implies -s)]'\ + -m'[Use the given tag message]'\ + -p'[Push to $ORIGIN after performing finish]'\ + ':hotfix:__git_flow_hotfix_list' + ;; - (start) - _arguments \ - -F'[Fetch from origin before performing finish]'\ - ':hotfix:__git_flow_version_list'\ - ':branch-name:__git_branch_names' - ;; + (publish) + _arguments \ + ':hotfix:__git_flow_hotfix_list' + ;; - (finish) - _arguments \ - -F'[Fetch from origin before performing finish]' \ - -s'[Sign the release tag cryptographically]'\ - -u'[Use the given GPG-key for the digital signature (implies -s)]'\ - -m'[Use the given tag message]'\ - -p'[Push to $ORIGIN after performing finish]'\ - ':hotfix:__git_flow_hotfix_list' - ;; - - (publish) - _arguments \ - ':hotfix:__git_flow_hotfix_list' - ;; - - *) - _arguments \ - -v'[Verbose (more) output]' - ;; - esac - ;; - esac + *) + _arguments \ + -v'[Verbose (more) output]' + ;; + esac + ;; + esac } -__git-flow-feature () -{ - local curcontext="$curcontext" state line - typeset -A opt_args +__git-flow-feature () { + local curcontext="$curcontext" state line + typeset -A opt_args - _arguments -C \ - ':command:->command' \ - '*::options:->options' + _arguments -C \ + ':command:->command' \ + '*::options:->options' - case $state in - (command) - - local -a subcommands - subcommands=( - 'start:Start a new feature branch.' - 'finish:Finish a feature branch.' - 'list:List all your feature branches. (Alias to `git flow feature`)' - 'publish:Publish this feature branch to origin.' - 'track:Track a feature branch from origin.' - 'diff:Show a diff of changes since this feature branched off.' - 'rebase:Rebase a feature branch on top of develop.' + case $state in + (command) + local -a subcommands + subcommands=( + 'start:Start a new feature branch.' + 'finish:Finish a feature branch.' + 'list:List all your feature branches. (Alias to `git flow feature`)' + 'publish:Publish this feature branch to origin.' + 'track:Track a feature branch from origin.' + 'diff:Show a diff of changes since this feature branched off.' + 'rebase:Rebase a feature branch on top of develop.' 'checkout:Check out (switch to) the given feature branch.' - 'pull:Pull a feature branch from a remote peer.' - ) - _describe -t commands 'git flow feature' subcommands - _arguments \ - -v'[Verbose (more) output]' - ;; + 'pull:Pull a feature branch from a remote peer.' + ) + _describe -t commands 'git flow feature' subcommands + _arguments \ + -v'[Verbose (more) output]' + ;; - (options) - case $line[1] in + (options) + case $line[1] in + (start) + _arguments \ + -F'[Fetch from origin before performing finish]'\ + ':feature:__git_flow_feature_list'\ + ':branch-name:__git_branch_names' + ;; - (start) - _arguments \ - -F'[Fetch from origin before performing finish]'\ - ':feature:__git_flow_feature_list'\ - ':branch-name:__git_branch_names' - ;; + (finish) + _arguments \ + -F'[Fetch from origin before performing finish]' \ + -r'[Finish branch by rebasing first]'\ + -k'[Keep branch after performing finish]'\ + -D'[Force delete feature branch after finish]'\ + ':feature:__git_flow_feature_list' + ;; - (finish) - _arguments \ - -F'[Fetch from origin before performing finish]' \ - -r'[Finish branch by rebasing first]'\ - -k'[Keep branch after performing finish]'\ - -D'[Force delete feature branch after finish]'\ - ':feature:__git_flow_feature_list' - ;; + (publish) + _arguments \ + ':feature:__git_flow_feature_list'\ + ;; - (publish) - _arguments \ - ':feature:__git_flow_feature_list'\ - ;; + (track) + _arguments \ + ':feature:__git_flow_feature_list'\ + ;; - (track) - _arguments \ - ':feature:__git_flow_feature_list'\ - ;; + (diff) + _arguments \ + ':branch:__git_branch_names'\ + ;; - (diff) - _arguments \ - ':branch:__git_branch_names'\ - ;; + (rebase) + _arguments \ + -i'[Do an interactive rebase]' \ + ':branch:__git_branch_names' + ;; - (rebase) - _arguments \ - -i'[Do an interactive rebase]' \ - ':branch:__git_branch_names' - ;; + (checkout) + _arguments \ + ':branch:__git_flow_feature_list'\ + ;; - (checkout) - _arguments \ - ':branch:__git_flow_feature_list'\ - ;; + (pull) + _arguments \ + ':remote:__git_remotes'\ + ':branch:__git_branch_names' + ;; - (pull) - _arguments \ - ':remote:__git_remotes'\ - ':branch:__git_branch_names' - ;; - - *) - _arguments \ - -v'[Verbose (more) output]' - ;; - esac - ;; - esac + *) + _arguments \ + -v'[Verbose (more) output]' + ;; + esac + ;; + esac } -__git-flow-support () -{ - local curcontext="$curcontext" state line - typeset -A opt_args +__git-flow-support () { + local curcontext="$curcontext" state line + typeset -A opt_args - _arguments -C \ - ':command:->command' \ - '*::options:->options' + _arguments -C \ + ':command:->command' \ + '*::options:->options' - case $state in - (command) + case $state in + (command) - local -a subcommands - subcommands=( - 'start:Start a new support branch.' - 'list:List all your support branches. (Alias to `git flow support`)' - ) - _describe -t commands 'git flow support' subcommands - _arguments \ - -v'[Verbose (more) output]' - ;; + local -a subcommands + subcommands=( + 'start:Start a new support branch.' + 'list:List all your support branches. (Alias to `git flow support`)' + ) + _describe -t commands 'git flow support' subcommands + _arguments \ + -v'[Verbose (more) output]' + ;; - (options) - case $line[1] in + (options) + case $line[1] in - (start) - _arguments \ - -F'[Fetch from origin before performing finish]'\ - ':feature:__git_flow_support_list'\ - ':branch-name:__git_branch_names' - ;; + (start) + _arguments \ + -F'[Fetch from origin before performing finish]'\ + ':feature:__git_flow_support_list'\ + ':branch-name:__git_branch_names' + ;; - *) - _arguments \ - -v'[Verbose (more) output]' - ;; - esac - ;; - esac + *) + _arguments \ + -v'[Verbose (more) output]' + ;; + esac + ;; + esac } -__git_flow_version_list () -{ - local expl - declare -a versions +__git_flow_version_list () { + local expl + declare -a versions - versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}}) - __git_command_successful || return + versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}}) + __git_command_successful || return - _wanted versions expl 'version' compadd $versions + _wanted versions expl 'version' compadd $versions } -__git_flow_feature_list () -{ - local expl - declare -a features +__git_flow_feature_list () { + local expl + declare -a features - features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}}) - __git_command_successful || return + features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}}) + __git_command_successful || return - _wanted features expl 'feature' compadd $features + _wanted features expl 'feature' compadd $features } __git_remotes () { - local expl gitdir remotes + local expl gitdir remotes - gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null) - __git_command_successful || return + gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null) + __git_command_successful || return - remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]}) - __git_command_successful || return + remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]}) + __git_command_successful || return - # TODO: Should combine the two instead of either or. - if (( $#remotes > 0 )); then - _wanted remotes expl remote compadd $* - $remotes - else - _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*" - fi + # TODO: Should combine the two instead of either or. + if (( $#remotes > 0 )); then + _wanted remotes expl remote compadd $* - $remotes + else + _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*" + fi } -__git_flow_hotfix_list () -{ - local expl - declare -a hotfixes +__git_flow_hotfix_list () { + local expl + declare -a hotfixes - hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}}) - __git_command_successful || return + hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}}) + __git_command_successful || return - _wanted hotfixes expl 'hotfix' compadd $hotfixes + _wanted hotfixes expl 'hotfix' compadd $hotfixes } -__git_flow_support_list () -{ - local expl - declare -a support +__git_flow_support_list () { + local expl + declare -a support - support=(${${(f)"$(_call_program support git flow support list 2> /dev/null | tr -d ' |*')"}}) - __git_command_successful || return + support=(${${(f)"$(_call_program support git flow support list 2> /dev/null | tr -d ' |*')"}}) + __git_command_successful || return - _wanted hotfixes expl 'support' compadd $support + _wanted hotfixes expl 'support' compadd $support } - __git_branch_names () { - local expl - declare -a branch_names + local expl + declare -a branch_names - branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/}) - __git_command_successful || return + branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/}) + __git_command_successful || return - _wanted branch-names expl branch-name compadd $* - $branch_names + _wanted branch-names expl branch-name compadd $* - $branch_names } __git_command_successful () { - if (( ${#pipestatus:#0} > 0 )); then - _message 'not a git repository' - return 1 - fi - return 0 + if (( ${#pipestatus:#0} > 0 )); then + _message 'not a git repository' + return 1 + fi + return 0 } _git-flow "$@" diff --git a/src/_language_codes b/src/_language_codes index 2dae9d7..033e756 100644 --- a/src/_language_codes +++ b/src/_language_codes @@ -230,7 +230,7 @@ _language_codes() { case $command in ISO-639-1) - _language_codes_${${command//-/_}:l} "${@[1,-2]}" && ret=0 + _language_codes_${${command//-/_}:l} "${@[1,-2]}" && ret=0 ;; *) _message "unknown command: $command" diff --git a/src/_nftables b/src/_nftables index 6046760..a7ee12c 100644 --- a/src/_nftables +++ b/src/_nftables @@ -12,278 +12,280 @@ # * Markus Richter ( https://github.com/mqus , ) # # ------------------------------------------------------------------------------ + _nft(){ -local -a rules states prev args families options descriptors -local state="start" line nextstate cmd_obj cmd_subcmd cmd_fam cmd_tab cmd_chain #curcontext="$curcontext" + local -a rules states prev args families options descriptors + local state="start" line nextstate cmd_obj cmd_subcmd cmd_fam cmd_tab cmd_chain #curcontext="$curcontext" -options=( - '(-)'{-h,--help}'[show help]' \ - '(-)'{-v,--version}'[print version information]' \ - "(-i --interactive)"{-i,--interactive}'[read input from interactive CLI]: :->end' \ - "(-f --file)"{-f,--file}'[read input from ]:nftables rule file:_files' \ - '(-c --check -n --numeric -N)'{-c,--check}"[check command's validity without actually applying the changes]" \ - '(-j --json)'{-j,--json}'[format output in json]' \ - '(-c --check -N)*'{-n,--numeric}'[can be specified up to 3 times, Shows 1:network addresses(default behaviour), 2:internet services (port numbers) and 3:protocols, user IDs, and group IDs numerically]' \ - '(-s --stateless)'{-s,--stateless}'[omit stateful information of ruleset]' \ - '(-N -n --numeric -c --check)'-N'[translate IP addresses to names]' \ - '(-a --handle)'{-a,--handle}'[output rule handle]' \ - '(-e --echo)'{-e,--echo}'[echo what has been added, inserted or replaced]' \ - {-I,--includepath}'[add specified directory to the paths searched for include files]:include directory [/usr/share]:include directory:_directories' -) + options=( + '(-)'{-h,--help}'[show help]' + '(-)'{-v,--version}'[print version information]' + "(-i --interactive)"{-i,--interactive}'[read input from interactive CLI]: :->end' + "(-f --file)"{-f,--file}'[read input from ]:nftables rule file:_files' + '(-c --check -n --numeric -N)'{-c,--check}"[check command's validity without actually applying the changes]" + '(-j --json)'{-j,--json}'[format output in json]' + '(-c --check -N)*'{-n,--numeric}'[can be specified up to 3 times, Shows 1:network addresses(default behaviour), 2:internet services (port numbers) and 3:protocols, user IDs, and group IDs numerically]' + '(-s --stateless)'{-s,--stateless}'[omit stateful information of ruleset]' + '(-N -n --numeric -c --check)'-N'[translate IP addresses to names]' + '(-a --handle)'{-a,--handle}'[output rule handle]' + '(-e --echo)'{-e,--echo}'[echo what has been added, inserted or replaced]' + {-I,--includepath}'[add specified directory to the paths searched for include files]:include directory [/usr/share]:include directory:_directories' + ) -# start a state machine. The state is modified by _arguments if the -# current argument (descriptors) cannot be completed. Each state has to define is successive state and the -# 'descriptors' for _arguments, which essentially tells _arguments how to complete -local _i=0 -while true;do - (( _i+=1 )) - #Guard for endless loops - [[ $_i -gt 100 ]] && return 1 + # start a state machine. The state is modified by _arguments if the + # current argument (descriptors) cannot be completed. Each state has to define is successive state and the + # 'descriptors' for _arguments, which essentially tells _arguments how to complete + local _i=0 + while true;do + (( _i+=1 )) + #Guard for endless loops + [[ $_i -gt 100 ]] && return 1 - descriptors=() - nextstate="end" - case $state in - (start) - ##if line is empty (at the start) or ends with semicolon, autocomplete subcommands, - # else if we are after a space,complete a semicolon (end the current nft command) and start anew - if [[ $line[1] = "" || $line[1] =~ ';$' ]] ; then - descriptors=( ":: :_nft_subcommands" ) - nextstate="category" - else - if [[ $words =~ ' $' ]]; then - descriptors=(':: :(\;)') - else - descriptors=(':argument: ') - fi + descriptors=() + nextstate="end" + case $state in + (start) + ##if line is empty (at the start) or ends with semicolon, autocomplete subcommands, + # else if we are after a space,complete a semicolon (end the current nft command) and start anew + if [[ $line[1] = "" || $line[1] =~ ';$' ]] ; then + descriptors=( ":: :_nft_subcommands" ) + nextstate="category" + else + if [[ $words =~ ' $' ]]; then + descriptors=(':: :(\;)') + else + descriptors=(':argument: ') + fi + nextstate="start" + fi + ;; + (category) + case $line[1] in + (add | list | flush | delete | create | rename | insert | replace | reset) + descriptors=( ":: :_nft_${line[1]}" ) + nextstate=$line[1] + ;; + (monitor) + descriptors=( ":: : _nft_mon_filter" ) + nextstate="mon1" + ;; + (export) + descriptors=( ":: :(ruleset)" ":: :_nft_out_format" ) + nextstate="preend" + ;; + (describe) + descriptors=( ":expression: ") + nextstate="start" #x restart + ;; + (*) + return 1; + ;; + esac + + #descriptors=( "(ruleset)" ) + #nextstate="end" + ;; + (mon1) + case $line[1] in + (new | destroy) + # descriptors=( ":: :_nft_mon_keywords" ":: :_nft_out_format") + descriptors=( ":: : _nft_mon_keywords") + nextstate="mon1" + ;; + (tables | chains | sets | rules | elements | ruleset) + descriptors=( ":: : _nft_out_format") + nextstate="preend" + ;; + esac + ;; + #all completions for create and insert match with the completions of add + (create | insert) + state="add" + ;| + #all completions for reset and flush match with the completions of list + (reset | flush) + state="list" + ;| + #(add(^table)/create(^table)/delete/flush(^ruleset)/insert/list(^ruleset)/rename/replace)[family]table + (reset | delete | insert | rename | replace | add | create | flush | list) + if [[ $state = "add" && $line[1] = "table" ]]; then + descriptors=( ":: :_nft_families" ":table name:") + nextstate="start" #x restart + elif [[ $state = "list" && ( $line[1] = "ruleset" || $line[1] = "tables" ) ]]; then + descriptors=( ":: :_nft_families") + nextstate="start" #x restart + elif [[ $state = "delete" && $line[1] = "table" ]]; then + descriptors=(": : _nft_table all-handle") + nextstate="tcomplete-delete-table" + else + cmd_obj=$line[1] + cmd_subcmd=$state + descriptors=(": : _nft_table all") + nextstate="tcomplete" + fi + ;; + (tcomplete-delete-table) + # if only a family was completed, complete the table name. + case $line[1] in + (arp | bridge | inet | ip | ip6 | netdev) + descriptors=(": : _nft_table ${line[1]}-handle") + cmd_fam=$line[1] + ;; + # if 'handle' was completed, complete the handle number. + (handle) + descriptors=(": : _nft_table_handle_all " ) + ;; + # else, complete nothing and go to the next state. default family is 'ip' + (*) + descriptors=() + cmd_fam="ip" + ;; + esac + nextstate="delete-table" + ;; + (tcomplete) + # if only a family was completed, complete the table name. + case $line[1] in + (arp | bridge | inet | ip | ip6 | netdev) + descriptors=(": : _nft_table ${line[1]}") + cmd_fam=$line[1] + ;; + # else, complete nothing and go to the next state. default family is 'ip' + (*) + descriptors=() + cmd_fam="ip" + ;; + esac + nextstate="$cmd_subcmd-$cmd_obj" + ;; + (list-table) + descriptors=(":: :(\;)") + nextstate="start" + ;; + (delete-table) + #if family AND handle were input, complete handle number for given family. + if [[ $line[1] == "handle" ]]; then + descriptors=(":table handle: _nft_table_handle $cmd_fam" ) + else + descriptors=() + fi + nextstate="start" + ;; + (delete-chain | delete-set | delete-quota | delete-counter | delete-ct\\ helper) + cmd_tab=$line[1] + descriptors=(": : _nft_object $cmd_fam $cmd_tab $cmd_obj true") + nextstate="delete-obj-handle" + ;; + (delete-obj-handle) + if [[ $line[1] == "handle" ]]; then + descriptors=(": : _nft_object_handle $cmd_fam $cmd_tab $cmd_obj") + else + descriptors=(": :(\;)") + fi + nextstate="start" + ;; + (add-chain) + descriptors=(":chain name:") + nextstate="start" + ;; + (rename-chain) + cmd_tab=$line[1] + descriptors=(": : _nft_object $cmd_fam $cmd_tab chain false") + nextstate="add-chain" + ;; + (replace-rule | delete-rule) + cmd_tab=$line[1] + descriptors=(": : _nft_object $cmd_fam $cmd_tab chain false") + nextstate="repdel-rule" + ;; + (repdel-rule) + cmd_chain=$line[1] + descriptors=(": :(handle)" ": : _nft_rule_handle $cmd_fam $cmd_tab ${line[1]}") + if [[ $cmd_subcmd = "replace" ]];then + nextstate="rule-stmt" + else + nextstate="start" + fi + ;; + (add-rule) + cmd_tab=$line[1] + descriptors=(": : _nft_object $cmd_fam $cmd_tab chain false") + nextstate="add-rule-2" + ;; + (add-rule-2) + cmd_chain=$line[1] + descriptors=(": :(handle index position)") + nextstate="add-rule-3" + ;; + (add-rule-3) + case $line[1] in + (index | position) + descriptors=(":${line[1]}:") + ;; + (handle) + descriptors=(": : _nft_rule_handle $cmd_fam $cmd_tab $cmd_chain") + ;; + (*) + descriptors=() + ;; + esac + nextstate="rule-stmt" + ;; + (rule-stmt) + #TODO + # _nft_rule $cmd_fam $cmd_tab $cmd_chain\ + # && return 0; + descriptors=(":expression: ") + nextstate="start" + ;; + (list-set | list-map | delete-map | list-chain | list-flowtable | delete-flowtable | list-ct\\ helper | list-counter | list-quota | list-meter) + cmd_tab=$line[1] + descriptors=(": : _nft_object $cmd_fam $cmd_tab $cmd_obj false") nextstate="start" - fi - ;; - (category) - case $line[1] in - (add | list | flush | delete | create | rename | insert | replace | reset) - descriptors=( ":: :_nft_${line[1]}" ) - nextstate=$line[1] - ;; - (monitor) - descriptors=( ":: : _nft_mon_filter" ) - nextstate="mon1" - ;; - (export) - descriptors=( ":: :(ruleset)" ":: :_nft_out_format" ) - nextstate="preend" - ;; - (describe) - descriptors=( ":expression: ") - nextstate="start" #x restart - ;; - (*) - return 1; - ;; - esac + ;; + (add-element | delete-element) + cmd_tab=$line[1] + descriptors=(": : _nft_object $cmd_fam $cmd_tab '\(map\|set\)' false") + nextstate="start" + ;; + #TODO: + #(add-set | add-map) + #(add-flowtable) + #("add-ct\ helper") + #(add-counter) + #(add-quota) - #descriptors=( "(ruleset)" ) - #nextstate="end" - ;; - (mon1) - case $line[1] in - (new | destroy) -# descriptors=( ":: :_nft_mon_keywords" ":: :_nft_out_format") - descriptors=( ":: : _nft_mon_keywords") - nextstate="mon1" - ;; - (tables | chains | sets | rules | elements | ruleset) - descriptors=( ":: : _nft_out_format") - nextstate="preend" - ;; + (*) + return 1; + ;; esac - ;; - #all completions for create and insert match with the completions of add - (create | insert) - state="add" - ;| - #all completions for reset and flush match with the completions of list - (reset | flush) - state="list" - ;| - #(add(^table)/create(^table)/delete/flush(^ruleset)/insert/list(^ruleset)/rename/replace)[family]table - (reset | delete | insert | rename | replace | add | create | flush | list) - if [[ $state = "add" && $line[1] = "table" ]]; then - descriptors=( ":: :_nft_families" ":table name:") - nextstate="start" #x restart - elif [[ $state = "list" && ( $line[1] = "ruleset" || $line[1] = "tables" ) ]]; then - descriptors=( ":: :_nft_families") - nextstate="start" #x restart - elif [[ $state = "delete" && $line[1] = "table" ]]; then - descriptors=(": : _nft_table all-handle") - nextstate="tcomplete-delete-table" - else - cmd_obj=$line[1] - cmd_subcmd=$state - descriptors=(": : _nft_table all") - nextstate="tcomplete" - fi - ;; - (tcomplete-delete-table) - # if only a family was completed, complete the table name. - case $line[1] in - (arp | bridge | inet | ip | ip6 | netdev) - descriptors=(": : _nft_table ${line[1]}-handle") - cmd_fam=$line[1] - ;; - # if 'handle' was completed, complete the handle number. - (handle) - descriptors=(": : _nft_table_handle_all " ) - ;; - # else, complete nothing and go to the next state. default family is 'ip' - (*) - descriptors=() - cmd_fam="ip" - ;; - esac - nextstate="delete-table" - ;; - (tcomplete) - # if only a family was completed, complete the table name. - case $line[1] in - (arp | bridge | inet | ip | ip6 | netdev) - descriptors=(": : _nft_table ${line[1]}") - cmd_fam=$line[1] - ;; - # else, complete nothing and go to the next state. default family is 'ip' - (*) - descriptors=() - cmd_fam="ip" - ;; - esac - nextstate="$cmd_subcmd-$cmd_obj" - ;; - (list-table) - descriptors=(":: :(\;)") - nextstate="start" - ;; - (delete-table) - #if family AND handle were input, complete handle number for given family. - if [[ $line[1] == "handle" ]]; then - descriptors=(":table handle: _nft_table_handle $cmd_fam" ) - else - descriptors=() - fi - nextstate="start" - ;; - (delete-chain | delete-set | delete-quota | delete-counter | delete-ct\\ helper) - cmd_tab=$line[1] - descriptors=(": : _nft_object $cmd_fam $cmd_tab $cmd_obj true") - nextstate="delete-obj-handle" - ;; - (delete-obj-handle) - if [[ $line[1] == "handle" ]]; then - descriptors=(": : _nft_object_handle $cmd_fam $cmd_tab $cmd_obj") - else - descriptors=(": :(\;)") - fi - nextstate="start" - ;; - (add-chain) - descriptors=(":chain name:") - nextstate="start" - ;; - (rename-chain) - cmd_tab=$line[1] - descriptors=(": : _nft_object $cmd_fam $cmd_tab chain false") - nextstate="add-chain" - ;; - (replace-rule | delete-rule) - cmd_tab=$line[1] - descriptors=(": : _nft_object $cmd_fam $cmd_tab chain false") - nextstate="repdel-rule" - ;; - (repdel-rule) - cmd_chain=$line[1] - descriptors=(": :(handle)" ": : _nft_rule_handle $cmd_fam $cmd_tab ${line[1]}") - if [[ $cmd_subcmd = "replace" ]];then - nextstate="rule-stmt" - else - nextstate="start" - fi - ;; - (add-rule) - cmd_tab=$line[1] - descriptors=(": : _nft_object $cmd_fam $cmd_tab chain false") - nextstate="add-rule-2" - ;; - (add-rule-2) - cmd_chain=$line[1] - descriptors=(": :(handle index position)") - nextstate="add-rule-3" - ;; - (add-rule-3) - case $line[1] in - (index | position) - descriptors=(":${line[1]}:") - ;; - (handle) - descriptors=(": : _nft_rule_handle $cmd_fam $cmd_tab $cmd_chain") - ;; - (*) - descriptors=() - ;; - esac - nextstate="rule-stmt" - ;; - (rule-stmt) - #TODO - # _nft_rule $cmd_fam $cmd_tab $cmd_chain\ - # && return 0; - descriptors=(":expression: ") - nextstate="start" - ;; - (list-set | list-map | delete-map | list-chain | list-flowtable | delete-flowtable | list-ct\\ helper | list-counter | list-quota | list-meter) - cmd_tab=$line[1] - descriptors=(": : _nft_object $cmd_fam $cmd_tab $cmd_obj false") - nextstate="start" - ;; - (add-element | delete-element) - cmd_tab=$line[1] - descriptors=(": : _nft_object $cmd_fam $cmd_tab '\(map\|set\)' false") - nextstate="start" - ;; - #TODO: - #(add-set | add-map) - #(add-flowtable) - #("add-ct\ helper") - #(add-counter) - #(add-quota) + _arguments -C -s \ + "${options[@]}" \ + "${descriptors[@]}" \ + "*:: :->$nextstate" \ + && return 0; - (*) - return 1; - ;; - esac - _arguments -C -s \ - "${options[@]}" \ - "${descriptors[@]}" \ - "*:: :->$nextstate" \ - && return 0; - -done + done } # end _nft _nft_subcommands(){ local commands=( - 'add:add a table, chain, rule, set, map, or object' - 'list:list a ruleset, table, chain, set, map, or object' - 'flush:flush (delete everything from) a ruleset, table, chain, set, or map' - 'export:print the ruleset in a machine readable format (json or xml)' - 'delete:delete a table, chain, rule, set, element, map, or object' - 'create:similar to add but returns an error for existing chain' - 'rename:rename the specified chain' - 'insert:similar to the add command, but the rule is prepended to the beginning of the chain or before the rule at the given position' - 'replace:similar to the add command, but replaces the specified rule' - 'reset:list-and-reset stateful object' - 'monitor:listen to Netlink events' - 'describe:show information about the type of an expression and its data type' + 'add:add a table, chain, rule, set, map, or object' + 'list:list a ruleset, table, chain, set, map, or object' + 'flush:flush (delete everything from) a ruleset, table, chain, set, or map' + 'export:print the ruleset in a machine readable format (json or xml)' + 'delete:delete a table, chain, rule, set, element, map, or object' + 'create:similar to add but returns an error for existing chain' + 'rename:rename the specified chain' + 'insert:similar to the add command, but the rule is prepended to the beginning of the chain or before the rule at the given position' + 'replace:similar to the add command, but replaces the specified rule' + 'reset:list-and-reset stateful object' + 'monitor:listen to Netlink events' + 'describe:show information about the type of an expression and its data type' ) _describe -t commands 'nft subcommand' commands "$@" } + _nft_mon_filter(){ local monitor_filters=( 'new:show only events of created objects'