Compare commits
38 Commits
ad3d4828a2
...
0a355edd50
Author | SHA1 | Date |
---|---|---|
|
0a355edd50 | |
|
922abfe707 | |
|
ed034970c2 | |
|
fe11bbe8b0 | |
|
1ee071125e | |
|
6ba54212d0 | |
|
932c16fd0e | |
|
e07f6fb780 | |
|
d326bdc241 | |
|
335af5c72d | |
|
c29efd0bc3 | |
|
4625071e98 | |
|
21789376b8 | |
|
a221bd2653 | |
|
ab95699400 | |
|
99d000d880 | |
|
d1469c6e4f | |
|
77cad16cc7 | |
|
8af769e5f1 | |
|
67e6bdbc3c | |
|
98dd809126 | |
|
c4fca6525a | |
|
4f6441f9ee | |
|
4e0cdee2e7 | |
|
5359bbf0e7 | |
|
a3e89f7c56 | |
|
cf57a3266c | |
|
41896a6013 | |
|
0d8667bb6a | |
|
79c6d1715f | |
|
f5e58a5ca7 | |
|
6c8cd1b111 | |
|
eb711299c5 | |
|
d71c3c84cc | |
|
c3f1f7748d | |
|
45fd6f398a | |
|
26b538f012 | |
|
fd43209f3a |
|
@ -24,7 +24,7 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# Completion script for clang-check v15.0.2 (https://clang.llvm.org/docs/ClangCheck.html)
|
||||
# Completion script for clang-check v20.1.2 (https://clang.llvm.org/docs/ClangCheck.html)
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
# Authors
|
||||
|
@ -37,6 +37,8 @@
|
|||
_arguments \
|
||||
'(- *)--help[Display available options]' \
|
||||
'(- *)--help-hidden[Display available more options]' \
|
||||
'(- *)--help-list[Display list of available options]' \
|
||||
'(- *)--help-list-hidden[Display list of more available options]' \
|
||||
'(- *)--version[Display the version of this program]' \
|
||||
'--analyze[Run static analysis engine]' \
|
||||
'--analyzer-output-path=[Write output to file]: :_files' \
|
||||
|
@ -49,6 +51,8 @@ _arguments \
|
|||
'--fix-what-you-can[Apply fix-it advice even in the presence of unfixable errors]' \
|
||||
'--fixit[Apply fix-it advice to the input source]' \
|
||||
'-p[Build directory where compile_commands.json is]: :_files -/' \
|
||||
'--print-all-options[Print all option values after command line parsing]' \
|
||||
'--print-options[Print non-default options after command line parsing]' \
|
||||
'--syntax-tree-dump[dump the syntax tree]' \
|
||||
'--tokens-dump[dump the preprocessed tokens]' \
|
||||
'*: :_files'
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# Completion script for clang-format v15.0.2 (https://clang.llvm.org/docs/ClangFormat.html)
|
||||
# Completion script for clang-format v20.1.2 (https://clang.llvm.org/docs/ClangFormat.html)
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
# Authors
|
||||
|
@ -41,24 +41,31 @@ _arguments \
|
|||
'(- *)--help-hidden[Display available more options]' \
|
||||
'(- *)--help-list[Display list of available options]' \
|
||||
'(- *)--help-list-hidden[Display list of more available options]' \
|
||||
'--Wclang-format-violations[Warnings about individual formatting changes needed]' \
|
||||
'--Werror=[If set, changes formatting warnings to errors]' \
|
||||
'*--Wno-error=[If set, do not error out on the specified warning type]:warn' \
|
||||
'--assume-filename=[Set filename used to determine the language and to find .clang-format file]: :_files' \
|
||||
'--cursor=[The position of the cursor when invoking clang-format from an editor integration]:pos' \
|
||||
'(-n --dry-run)'{-n,--dry-run}'[If set, do not actually make the formatting changes]' \
|
||||
'--dump-config[Dump configuration options to stdout and exit]' \
|
||||
'--fail-on-incomplete-format[If set, fail with exit code 1 on incomplete format]' \
|
||||
'--fallback-style=[The name of the predefined style used as a fallback]: :'"($styles)" \
|
||||
'--ferror-limit=[Set the maximum number of clang-format errors to emit before stopping]:limit' \
|
||||
'*--files=[Provide a list of files to run clang-format]: :_files' \
|
||||
'--fno-color-diagnostics[If set, not to print diagnostics in color]' \
|
||||
'-i[Inplace edit files, if specified]' \
|
||||
'--length=[Format a range of this length(in bytes)]:bytes' \
|
||||
'--lines=[format a range of lines]:format' \
|
||||
'--list-ignored[List ignored files]' \
|
||||
'--offset=[Format a range starting at this byte offset]' \
|
||||
'--output-replacements-xml[Output replacements as XML]' \
|
||||
'--print-all-options[Print all option values after command line parsing]' \
|
||||
'--print-options[Print non default options after command line parsing]' \
|
||||
'--qualifier-alignment=[If set, overrides the qualifier alignment style determined by the QualifierAlignment style flag]' \
|
||||
'--sort-includes[If set, overrides the include sorting behavior determined by the SortIncludes style flag]' \
|
||||
'--style=[Set coding style]: :'"($styles)" \
|
||||
'--verbose[If set, show the list of processed files]' \
|
||||
'(- *)--version[Display the version of this program]' \
|
||||
'*: :_files'
|
||||
|
||||
# Local Variables:
|
||||
|
|
|
@ -41,12 +41,14 @@ _arguments \
|
|||
'(- *)--help-hidden[Display available more options]' \
|
||||
'(- *)--help-list[Display list of available options]' \
|
||||
'(- *)--help-list-hidden[Display list of more available options]' \
|
||||
'--allow-no-checks[Allow empty enabled checks]' \
|
||||
'--checks=[Comma-separated list of globs with optional "-" prefix]:checks' \
|
||||
'--config=[Specifies a configuration in YAML/JSON format]:conf' \
|
||||
'--config-file=[Specify the path of .clang-tidy or custom config-file]: :_files' \
|
||||
'--dump-config[Dumps configuration in the YAML format to stdout]' \
|
||||
'--enable-check-profile[Enable per-check timing profiles, and print a report to stderr]' \
|
||||
'--enable-module-headers-parsing[Enable preprocessor-level module header parsing for C++20 and above]' \
|
||||
'--exclude-header-filter=[Regular expression of headers to exclude diagnostics from]:filter' \
|
||||
'--explain-config[For each enabled check explains, where it is enabled]' \
|
||||
'--export-fixes=[YAML file to store suggested fixes in]: :_files' \
|
||||
'*--extra-arg[Additional argument to append to the compiler command line]:arg' \
|
||||
|
@ -54,16 +56,19 @@ _arguments \
|
|||
'--fix[Apply suggested fixes]' \
|
||||
'--fix-errors[Apply suggested fixes even if compilation errors were found]' \
|
||||
'--fix-notes[If a warning has no fix, but a single fix can be found through an associated diagnostic node, apply the fix]' \
|
||||
'--format-style=[Style for formatting code around applied fixes]: :(llvm google webkit mozilla)' \
|
||||
'--format-style=[Style for formatting code around applied fixes]: :(none file llvm google webkit mozilla)' \
|
||||
'--header-filter=[Regular expression matching the names of the headers to output diagnostics from]:regexp' \
|
||||
'--line-filter=[List of files with line ranges to filter the warnings]' \
|
||||
'(- *)--list-checks[List all enabled checks and exit]' \
|
||||
'--load=[Load the specified plugin]: :_files' \
|
||||
'-p[Build directory where compile_commands.json is]: :_files -/' \
|
||||
'--print-all-options[Print all option values after command line parsing]' \
|
||||
'--print-options[Print non default options after command line parsing]' \
|
||||
'--quiet[Run clang-tidy in quiet mode]' \
|
||||
'--store-check-profile=[These per-TU profiles are instead stored as JSON]:prefix' \
|
||||
'--system-headers[Display the errors from system headers]' \
|
||||
'--use-color[Use colors in diagnostics]' \
|
||||
'(- *)--version[Display the version of this program]' \
|
||||
'--verify-config[Check the config files to ensure each check and option is recognized]' \
|
||||
'--vfsoverlay=[Overlay the virtual filesystem described by file over the real file system]: :_files' \
|
||||
'--warnings-as-errors=[Upgrades warning to errors]:check' \
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# Completion script for CMake 3.25.0 (https://cmake.org).
|
||||
# Completion script for CMake 3.31.0 (https://cmake.org).
|
||||
#
|
||||
# -------------------------------------------------------------------------
|
||||
# Authors
|
||||
|
@ -77,6 +77,7 @@ local -a cmake_build_options=(
|
|||
|
||||
'--preset=[Specify a configure preset]:preset:_cmake_presets'
|
||||
'--list-presets[List available presets]'
|
||||
'--workflow[Run a workflow preset]'
|
||||
|
||||
'-E[CMake command mode]:command:_cmake_command_help'
|
||||
|
||||
|
@ -94,6 +95,7 @@ local -a cmake_build_options=(
|
|||
|
||||
'--graphviz=[Generate graphviz of dependencies, see CMakeGraphVizOptions.cmake for more]:graphviz output:_files'
|
||||
'--system-information[Dump information about this system]::system information output:_files'
|
||||
'--print-config-dir[Print CMake config directory for user-wide FileAPI queries]'
|
||||
|
||||
'--log-level=[Set the verbosity of messages from CMake files]:log level:(ERROR WARNING NOTICE STATUS VERBOSE DEBUG TRACE)'
|
||||
'--log-context[Prepend log messages with context, if given]'
|
||||
|
@ -101,6 +103,8 @@ local -a cmake_build_options=(
|
|||
'--debug-trycompile[Do not delete the try_compile build tree. Only useful on one try_compile at a time]'
|
||||
'--debug-output[Put cmake in a debug mode]'
|
||||
'--debug-find[Put cmake find in a debug mode]'
|
||||
'--debug-find-pkg=[Limit cmake debug-find to the comma-separated list of packages]:packages'
|
||||
'--debug-find-var=[Limit cmake debug-find to the comma-separated list of result variables]:variables'
|
||||
|
||||
'(--trace-expand)--trace[Put cmake in trace mode]'
|
||||
'(--trace)--trace-expand[Put cmake in trace mode with variable expansion]'
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
# Notes
|
||||
# -----
|
||||
#
|
||||
# Created for Cppcheck version 2.12 (https://github.com/danmar/cppcheck)
|
||||
# Created for Cppcheck version 2.17.1 (https://github.com/danmar/cppcheck)
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
@ -50,13 +50,17 @@ _cppcheck_files() {
|
|||
|
||||
_cppcheck() {
|
||||
local check_ids='(all warning style performance portability information unusedFunction missingInclude)'
|
||||
local platforms='(unix32 unix64 win32A win32W win64 avr8 elbrus-e1cp pic8 pic8-enhanced pic16 mips32 native unspecified)'
|
||||
local coding_standards='(normal autosar cert-c-2016 cert-cpp-2016 misra-c-2012 misra-c-2023 misra-cpp-2008 misra-cpp-2023)'
|
||||
|
||||
_arguments \
|
||||
"--addon=[Execute addon]" \
|
||||
"--addon-python=[Specify the python interpreter]: :_files" \
|
||||
"--cppcheck-build-dir=[Analysis output directory]:directory:_files -/" \
|
||||
"--check-config[Check cppcheck configuration]" \
|
||||
"--check-level=[Configure how much valueflow analysis you want]:level:(reduced normal exhaustive)" \
|
||||
"--check-library[Show information when library files have incomplete info]" \
|
||||
"--checkers-report=[Write a report of all the active checkers to the given file]:file:_files" \
|
||||
"--clang=[Use clang parser instead of the builtin Cppcheck parser]: :_files" \
|
||||
"--config-exclude=[Path to be excluded from configuration checking]:directory:_files -/" \
|
||||
"--config-exclude-files=[A file that contains a list of config-excludes]:file:_files" \
|
||||
|
@ -72,8 +76,10 @@ _cppcheck() {
|
|||
"--exitcode-suppressions=[Used when certain messages should be displayed but should not cause a non-zero exitcode]:_files" \
|
||||
"*--file-filter=[Analyze only those files matching the given filter str]:filter" \
|
||||
"--file-list=[Specify the files to check in a text file]:_files" \
|
||||
'(-f --force)'{-f,--force}"[Force checking of all configurations in files]" \
|
||||
'(- 1 *)'{-h,--help}"[Print this help]" \
|
||||
"(-f --force)"{-f,--force}"[Force checking of all configurations in files]" \
|
||||
"(--fsigned-char --funsigned-char)--fsigned-char[Treat char type as signed]" \
|
||||
"(--fsigned-char --funsigned-char)--funsigned-char[Treat char type as unsigned]" \
|
||||
"(- 1 *)"{-h,--help}"[Print this help]" \
|
||||
"-I[A file that contains a list of config-excludes]:directory:_files -/" \
|
||||
"--include-file=[Specify directory paths to search for included header files in a text file]:file:_files" \
|
||||
"--include=[Force inclusion of a file before the checked file]:file:_files" \
|
||||
|
@ -83,26 +89,34 @@ _cppcheck() {
|
|||
"-j[Number of threads to do the checking simultaneously]::num" \
|
||||
"-l[No new threads should be started if the load average is exceeds this value]::load_avg" \
|
||||
{-x,--language=}"[Forces cppcheck to check all files as the given language]:language:(c c++)" \
|
||||
"--library=[Load config file that contains information about types and functions]:config:_files" \
|
||||
"--max-configs=[Maximum number of configurations to check in a file]" \
|
||||
"--max-ctu-depth=[Maximum depth in whole program analysis]:num" \
|
||||
"--output-file=[File to save results]:file:_files" \
|
||||
"--output-format=[Specify the output format]:format:(text sarif xml)" \
|
||||
"--platform=[Specified platform specific types and sizes]:platform:$platforms" \
|
||||
"--plist-output=[Generate Clang-plist output files in folder]:_files" \
|
||||
"--project=[Run Cppcheck on project]:file:_files" \
|
||||
"--project-configuration=[Limit the configuration cppcheck should check]:configuration" \
|
||||
"--platform=[Set platform specific types and sizes]:platforms:(unix32 unix64 win32A win32W win64 avr8 elbrus-e1cp pic8 pic8-enhanced pic16 mips32 native unspecified)" \
|
||||
'(-q --quiet)'{-q,--quiet}"[Do not show progress reports]" \
|
||||
"(-q --quiet)"{-q,--quiet}"[Do not show progress reports]" \
|
||||
{-rp,--relative-paths}"=[Use relative paths in output (separated with ;)]:_files" \
|
||||
"--report-progress[Report progress messages while checking a file]" \
|
||||
"--report-type=[Add guideline and classification fields for specified coding standard]:standard:$coding_standards" \
|
||||
"--rule=[Match regular expression]:rule" \
|
||||
"--rule-file=[Use given rule file]:file:_files" \
|
||||
"--showtime=[show timing information]:type:(none file file-total summary top5_file top5_summary top5)" \
|
||||
"--std=[Set standard]:std:(c89 c99 c11 c++03 c++11 c++14 c++17 c++20)" \
|
||||
"--suppress=[Suppress warnings (format: \[error id\]:\[filename\]:\[line\])]" \
|
||||
"--suppressions-list=[Suppress warnings listed in the file]:_files" \
|
||||
"--suppress-xml=[Suppress warnings listed in a xml file]:_files" \
|
||||
"--template=[Format the error messages]" \
|
||||
"--template-location=[Format the error message location]" \
|
||||
"*-U[Undefine preprocessor symbol]:symbol" \
|
||||
"(-v --verbose)"{-v,--verbose}"[Output more detailed error information]" \
|
||||
"--version[Print out version number]" \
|
||||
"--xml[Write results in xml format to stderr]" \
|
||||
'*: :_cppcheck_files'
|
||||
"*: :_cppcheck_files"
|
||||
}
|
||||
|
||||
_cppcheck "$@"
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
#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:
|
4
src/_kak
4
src/_kak
|
@ -28,7 +28,7 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# Completion script for kak 2022.10.31 (https://github.com/mawww/kakoune)
|
||||
# Completion script for kak 2024.05.18 (https://github.com/mawww/kakoune)
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
# Authors
|
||||
|
@ -57,7 +57,7 @@ _kak() {
|
|||
"-f[enter in 'filter mode':select the whole file, then execute keys]:keys" \
|
||||
'-i[backup the files on which a filter is applied using the given suffix]:suffix' \
|
||||
'-q[in filter mode, do not print any errors]' \
|
||||
'-ui[set the type of user interface to use (ncurses, dummy, or json)]:ui_type:(ncurses dummy json)' \
|
||||
'-ui[set the type of user interface to use (terminal, dummy, or json)]:ui_type:(terminal dummy json)' \
|
||||
'-l[list existing sessions]:session_id:_kak_sessions' \
|
||||
'-clear[clear dead sessions]' \
|
||||
'-debug[initial debug option value]:arg' \
|
||||
|
|
11
src/_node
11
src/_node
|
@ -28,7 +28,7 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# Completion script for Node.js v23.8.0 (https://nodejs.org)
|
||||
# Completion script for Node.js v24.4.0 (https://nodejs.org)
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
# Authors
|
||||
|
@ -49,7 +49,7 @@ _node_files() {
|
|||
fi
|
||||
done
|
||||
|
||||
_files -g "*.(js|mjs)"
|
||||
_files -g "*.(js|mjs|ts|mts)"
|
||||
}
|
||||
|
||||
_node_args() {
|
||||
|
@ -93,6 +93,7 @@ _arguments -C \
|
|||
'--cpu-prof-name=[file name of the V8 profile generated with --cpu-prof]: :_files' \
|
||||
'--diagnostic-dir=[set dir for all output files(default: current working directory)]:dir:_files -/' \
|
||||
'--disable-proto=[disable Object.prototype.__proto__]:mode:(delete throw)' \
|
||||
'--disable-sigusr1[disable inspector thread to be listening for SIGUSR1 signal]' \
|
||||
'*--disable-warning=[silence specific process warnings]:warn type' \
|
||||
'--disable-wasm-trap-handler[disable trap-handler-based WebAssembly bound checks]' \
|
||||
'--disallow-code-generation-from-strings[disallow eval and friends]' \
|
||||
|
@ -105,7 +106,8 @@ _arguments -C \
|
|||
'*--env-file-if-exists=[set environment variables from supplied file if exists]:envfile:_files' \
|
||||
'(- 1 *)'{-e,--eval}'[evaluate script]:inline JavaScript' \
|
||||
'--experimental-addon-modules[enable experimental import support for addons]' \
|
||||
'--experimental-async-context-frame[improve AsyncLocalStorage performance with AsyncContextFrame]' \
|
||||
'--experimental-config-file=[set config file from supplied file]:file:_files' \
|
||||
'--experimental-default-config-file[set config file from default config file]' \
|
||||
'--experimental-eventsource[enable experimental EventSource API]' \
|
||||
'--experimental-import-meta-resolve[experimental ES Module import.meta.resolve() support]' \
|
||||
'(--loader --experimental-loader)'{--loader,--experimental-loader}'=[Specify the module of a custom ECMAScript Module loader]: :_files' \
|
||||
|
@ -150,6 +152,8 @@ _arguments -C \
|
|||
'--no-experimental-global-navigator[expose experimental Navigator API on the global scope]' \
|
||||
'--no-experimental-repl-await[disable experimental await keyword support in REPL]' \
|
||||
'--no-experimental-require-module[allow loading synchronous ES Modules in require()]' \
|
||||
'--no-experimental-sqlite[disable experimental node sqlite module]' \
|
||||
'--no-experimental-strip-types[disable experimental type-stripping for TypeScript files]' \
|
||||
'--no-experimental-websocket[experimental WebSocket API (currently set)]' \
|
||||
'--no-extra-info-on-fatal-exception[hide extra information on fatal exception that causes exit]' \
|
||||
'--no-force-async-hooks-checks[disable checks for async_hooks]' \
|
||||
|
@ -228,6 +232,7 @@ _arguments -C \
|
|||
'(- 1 *)--v8-options[print v8 command line options]' \
|
||||
"--v8-pool-size=[set v8's thread pool size]:number" \
|
||||
"--watch[run in watch mode]" \
|
||||
'--watch-kill-signal=[kill signal to send to the process on watch mode restarts]:signal:_signals -s' \
|
||||
"--watch-path=[path to watch]: :_node_files" \
|
||||
'--watch-preserve-output[preserve outputs on watch mode restart]' \
|
||||
'--zero-fill-buffers[automatically zero-fill all newly allocated Buffer and SlowBuffer instances]' \
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# Completion script for pre-commit (https://github.com/pre-commit/pre-commit/).
|
||||
# Completion script for pre-commit 4.2.0 (https://github.com/pre-commit/pre-commit/).
|
||||
# Modified from rejected https://github.com/pre-commit/pre-commit/pull/2506
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
@ -15,7 +15,7 @@
|
|||
# ------------------------------------------------------------------------------
|
||||
|
||||
_pre_commit_commands() {
|
||||
local _commands=(
|
||||
local commands=(
|
||||
"autoupdate:Auto-update pre-commit config to the latest repos' versions"
|
||||
"clean:Clean out pre-commit files"
|
||||
"gc:Clean unused cached repos"
|
||||
|
@ -30,8 +30,9 @@ _pre_commit_commands() {
|
|||
"uninstall:Uninstall the pre-commit script"
|
||||
"validate-config:Validate .pre-commit-config.yaml files"
|
||||
"validate-manifest:Validate .pre-commit-hooks.yaml files"
|
||||
"help:Show help for a specific command"
|
||||
)
|
||||
_describe 'pre-commit commands' _commands
|
||||
_describe 'pre-commit commands' commands
|
||||
}
|
||||
|
||||
_pre_commit_options=(
|
||||
|
@ -46,6 +47,7 @@ _pre_commit_autoupdate_options=(
|
|||
"--bleeding-edge[Update to the bleeding edge of 'HEAD' instead of the latest tagged version]"
|
||||
"--freeze[Store 'frozen' hashes in 'rev' instead of tag names]"
|
||||
"*--repo[Only update this repository -- may be specified multiple times]:repos:"
|
||||
{-j,--jobs}"[Number of threads to use]:jobs"
|
||||
)
|
||||
|
||||
_pre_commit_clean_options=(
|
||||
|
@ -68,7 +70,7 @@ _pre_commit_init_templatedir_options=(
|
|||
"--color[Whether to use color in output. Defaults to 'auto']:color:(auto always never)"
|
||||
{-c,--config}"[Path to alternate config file]:config:_files -g '*.yaml'"
|
||||
"--no-allow-missing-config[Assume cloned repos should have a 'pre-commit' config]"
|
||||
"*"{-t,--hook-type}"[which hook type to install]:hook_types:(pre-commit pre-merge-commit pre-push prepare-commit-msg commit-msg post-commit post-checkout post-merge post-rewrite)"
|
||||
"*"{-t,--hook-type}"[which hook type to install]:hook_types:(commit-msg post-checkout post-commit post-merge post-rewrite pre-commit pre-merge-commit pre-push pre-rebase prepare-commit-msg)"
|
||||
":The directory in which to write the hook script.:_files -/"
|
||||
)
|
||||
|
||||
|
@ -78,7 +80,7 @@ _pre_commit_install_options=(
|
|||
{-c,--config}"[Path to alternate config file]:config:_files -g '*.yaml'"
|
||||
{-f,--overwrite}"[Overwrite existing hooks / remove migration mode]"
|
||||
"--install-hooks[Whether to install hook environments for all environments in the config file]"
|
||||
"*"{-t,--hook-type}"[which hook type to install]:hook_types:(pre-commit pre-merge-commit pre-push prepare-commit-msg commit-msg post-commit post-checkout post-merge post-rewrite)"
|
||||
{-t,--hook-type}"[which hook type to install]:hook_type:(commit-msg post-checkout post-commit post-merge post-rewrite pre-commit pre-merge-commit pre-push pre-rebase prepare-commit-msg)"
|
||||
"--allow-missing-config[Hook scripts will permit a missing configuration file]"
|
||||
)
|
||||
|
||||
|
@ -102,11 +104,13 @@ _pre_commit_run_options=(
|
|||
{--all-files,-a}"[Run on all the files in the repo]"
|
||||
"--files[Specific filenames to run hooks on]:files:_files"
|
||||
"--show-diff-on-failure[When hooks fail, run 'git diff' directly afterward]"
|
||||
"--hook-stage[The stage during which the hook is fired]:hook_stage:(commit merge-commit prepare-commit-msg commit-msg post-commit manual post-checkout push post-merge post-rewrite)"
|
||||
"--hook-stage[The stage during which the hook is fired]:hook_stage:(commit-msg post-checkout post-commit post-merge post-rewrite pre-commit pre-merge-commit pre-push pre-rebase prepare-commit-msg manual)"
|
||||
"--remote-branch[Remote branch ref used by 'git push']:remote_branch:"
|
||||
"--local-branch[Local branch ref used by 'git push']:local_branch:"
|
||||
{--from-ref,--source,-s}"[the original ref in a 'from_ref...to_ref' diff expression]:from_ref:"
|
||||
{--to-ref,--origin,-o}"[the destination ref in a 'from_ref...to_ref' diff expression]:to_ref:"
|
||||
"--pre-rebase-upstream[the upstream from which the series was forked]:pre_rebase_upstream"
|
||||
"--pre-rebase-branch[the branch being rebased and is not set when rebasing the current branch]:pre_rebase_branch"
|
||||
"--commit-msg-filename[Filename to check when running during 'commit-msg']:commit_msg_filename:"
|
||||
"--prepare-commit-message-source[Source of the commit message]:prepare_commit_message_source:"
|
||||
"--commit-object-name[Commit object name]:commit_object_name:"
|
||||
|
@ -132,11 +136,13 @@ _pre_commit_try_repo_options=(
|
|||
{--all-files,-a}"[Run on all the files in the repo]"
|
||||
"--files[Specific filenames to run hooks on]:files:_files"
|
||||
"--show-diff-on-failure[When hooks fail, run 'git diff' directly afterward]"
|
||||
"--hook-stage[The stage during which the hook is fired]:hook_stage:(commit merge-commit prepare-commit-msg commit-msg post-commit manual post-checkout push post-merge post-rewrite)"
|
||||
"--hook-stage[The stage during which the hook is fired]:hook_stage:(commit-msg post-checkout post-commit post-merge post-rewrite pre-commit pre-merge-commit pre-push pre-rebase prepare-commit-msg manual)"
|
||||
"--remote-branch[Remote branch ref used by 'git push']:remote_branch:"
|
||||
"--local-branch[Local branch ref used by 'git push']:local_branch:"
|
||||
{--from-ref,--source,-s}"[the original ref in a 'from_ref...to_ref' diff expression]:from_ref:"
|
||||
{--to-ref,--origin,-o}"[the destination ref in a 'from_ref...to_ref' diff expression]:to_ref:"
|
||||
"--pre-rebase-upstream[the upstream from which the series was forked]:pre_rebase_upstream"
|
||||
"--pre-rebase-branch[the branch being rebased and is not set when rebasing the current branch]:pre_rebase_branch"
|
||||
"--commit-msg-filename[Filename to check when running during 'commit-msg']:commit_msg_filename:"
|
||||
"--prepare-commit-message-source[Source of the commit message]:prepare_commit_message_source:"
|
||||
"--commit-object-name[Commit object name]:commit_object_name:"
|
||||
|
@ -153,7 +159,7 @@ _pre_commit_uninstall_options=(
|
|||
"(- : *)"{-h,--help}"[show this help message and exit]"
|
||||
"--color[Whether to use color in output. Defaults to 'auto']:color:(auto always never)"
|
||||
{-c,--config}"[Path to alternate config file]:config:_files -g '*.yaml'"
|
||||
"*"{-t,--hook-type}"[which hook type to uninstall]:hook_types:(pre-commit pre-merge-commit pre-push prepare-commit-msg commit-msg post-commit post-checkout post-merge post-rewrite)"
|
||||
"*"{-t,--hook-type}"[which hook type to uninstall]:hook_types:(commit-msg post-checkout post-commit post-merge post-rewrite pre-commit pre-merge-commit pre-push pre-rebase prepare-commit-msg)"
|
||||
)
|
||||
|
||||
_pre_commit_validate_config_options=(
|
||||
|
|
|
@ -42,6 +42,10 @@ _setcap() {
|
|||
local curcontext=$curcontext state line expl ret=1
|
||||
|
||||
_arguments -C -s \
|
||||
'-r[remove capability from file]' \
|
||||
'--license[display the license info]' \
|
||||
'-f[force setting even when the capability is invalid]' \
|
||||
'-h[show help message and exit]' \
|
||||
'-v[verify that the specified capabilities are currently associated with the file]' \
|
||||
'-n[set the file capability for use only in a user namespace with this root user ID owner]:rootuid' \
|
||||
'-q[make the program less verbose in its output]' \
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# Completion script for shallow-backup: https://github.com/alichtman/shallow-backup
|
||||
# Completion script for shallow-backup v6.4: https://github.com/alichtman/shallow-backup
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
# Authors
|
||||
|
@ -38,30 +38,30 @@
|
|||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
_shallow-backup() {
|
||||
_arguments \
|
||||
'(- 1 *)'{-h,--help}'[Show help and exit]' \
|
||||
'(- 1 *)'{-v,--version}'[Print version]' \
|
||||
'--add-dot[Add a dotfile or dotfolder to config by path]:PATH:_files' \
|
||||
'--backup-all[Full back up]' \
|
||||
'--backup-configs[Back up app config files]' \
|
||||
'--backup-dots[Back up dotfiles]' \
|
||||
'--backup-fonts[Back up installed fonts]' \
|
||||
'--backup-packages[Back up package libraries]' \
|
||||
'--delete-config[Delete config file]' \
|
||||
'--destroy-backup[Delete backup directory]' \
|
||||
'--dry-run[Do not backup or reinstall any files, just give verbose output]' \
|
||||
'--new-path[Input a new back up directory path]:PATH:_files -/' \
|
||||
'--no-new-backup-path-prompt[Skip setting new back up directory path prompt]' \
|
||||
'--no-splash[Do not display splash screen]' \
|
||||
'--reinstall-all[Full reinstallation]' \
|
||||
'--reinstall-configs[Reinstall configs]' \
|
||||
'--reinstall-dots[Reinstall dotfiles and dotfolders]' \
|
||||
'--reinstall-fonts[Reinstall fonts]' \
|
||||
'--reinstall-packages[Reinstall packages]' \
|
||||
'--remote[Set remote URL for the git repo]':url \
|
||||
'--show[Display config file]'
|
||||
_arguments \
|
||||
'(- 1 *)'{-h,--help}'[Show help and exit]' \
|
||||
'(- 1 *)'{-v,--version}'[Print version]' \
|
||||
'--add-dot[Add a dotfile or dotfolder to config by path]:PATH:_files' \
|
||||
'--backup-all[Full back up]' \
|
||||
'--backup-configs[Back up app config files]' \
|
||||
'--backup-dots[Back up dotfiles]' \
|
||||
'--backup-fonts[Back up installed fonts]' \
|
||||
'--backup-packages[Back up package libraries]' \
|
||||
'--delete-config[Delete config file]' \
|
||||
'--destroy-backup[Delete backup directory]' \
|
||||
'--dry-run[Do not backup or reinstall any files, just give verbose output]' \
|
||||
'--new-path[Input a new back up directory path]:PATH:_files -/' \
|
||||
'--no-new-backup-path-prompt[Skip setting new back up directory path prompt]' \
|
||||
'--no-splash[Do not display splash screen]' \
|
||||
'--reinstall-all[Full reinstallation]' \
|
||||
'--reinstall-configs[Reinstall configs]' \
|
||||
'--reinstall-dots[Reinstall dotfiles and dotfolders]' \
|
||||
'--reinstall-fonts[Reinstall fonts]' \
|
||||
'--reinstall-packages[Reinstall packages]' \
|
||||
'--remote[Set remote URL for the git repo]':url \
|
||||
'--edit[Open config file in $EDITOR]' \
|
||||
'--show[Display config file]'
|
||||
}
|
||||
|
||||
_shallow-backup
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# Completion script for shellcheck (https://github.com/koalaman/shellcheck)
|
||||
# Completion script for shellcheck v0.10.0 (https://github.com/koalaman/shellcheck)
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
# Authors
|
||||
|
@ -43,12 +43,14 @@ _arguments \
|
|||
{-C,--color=}'[specify color]:color:(auto always never)' \
|
||||
{-i,--include=}'[consider only given types of warnings]:error code' \
|
||||
{-e,--exclude=}'[exclude given types of warnings]:error code' \
|
||||
'--extended-analysis=[perform dataflow analysis]:bool:(true false)' \
|
||||
{-f,--format=}'[specify output format]:format:(checkstyle diff gcc json json1 quiet tty)' \
|
||||
'--list-optional[list checks disabled by default]' \
|
||||
"--norc[don't look for .shellcheckrc files]" \
|
||||
'--rcfile=[specify configuration file over searching for one]:rcfile:_files' \
|
||||
{-o,--enable=}"[give list of optional checks to enable (or 'all')]:error code" \
|
||||
{-P,--source-path=}'[specify path when looking for sourced files]:_files -/' \
|
||||
{-s,--shell=}'[specify dialect]:dialect:(sh bash dash ksh)' \
|
||||
{-s,--shell=}'[specify dialect]:dialect:(sh bash dash ksh busybox)' \
|
||||
{-S,--severity=}'[specify minimum severity of errors to consider]:severity:(error warning info style)' \
|
||||
{-V,--version}'[print version information]' \
|
||||
{-W,--wiki-link-count=}'[specify number of wiki links to show, when applicable]:number' \
|
||||
|
|
146
src/_showoff
146
src/_showoff
|
@ -35,7 +35,7 @@
|
|||
# -------
|
||||
#
|
||||
# * Bruno Michel (https://github.com/nono)
|
||||
# * Shoehi Yoshida (https://github.com/nono)
|
||||
# * Shohei Yoshida (https://github.com/nono)
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
@ -76,78 +76,78 @@ _showoff() {
|
|||
'*:: :->args' \
|
||||
&& ret=0
|
||||
|
||||
case $state in
|
||||
(args)
|
||||
case $line[1] in
|
||||
(add|new)
|
||||
_arguments \
|
||||
'(-d --dir)'{-d,--dir}='[Slide dir (where to put a new slide file)]:directory:_files -/' \
|
||||
'(-n --name)'{-n,--name}='[Slide name (name of the new slide file)]:basename' \
|
||||
{-s,--source}='[Include code from the given file as the slide body]:file:_files' \
|
||||
'(-t --style --type)'{-t,--style,--type}='[Slide Type/Style (default: title)]:style' \
|
||||
'(-u --nonumber)'{-u,--nonumber}"[Don't number the slide, use the given name verbatim]" \
|
||||
'1:title' && ret=0
|
||||
;;
|
||||
(create|init)
|
||||
_arguments \
|
||||
'(-d --slidedir)'{-d,--slidedir}='[Sample slide directory name (default: one)]:arg' \
|
||||
'(-n --nosamples)'{-n,--nosamples}="[Don't create sample slides]" \
|
||||
'1:dir_name' && ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments \
|
||||
'-c[List commands one per line, to assist with shell completion]' \
|
||||
'1: :_showoff_help' && ret=0
|
||||
;;
|
||||
(heroku)
|
||||
_arguments \
|
||||
'(-f --force)'{-f,--force}'[force overwrite of existing Gemfile, .gems and config.ru files if they exist]' \
|
||||
'(-p --password)'{-p,--password}='[add password protection to your heroku site(default: none)]' \
|
||||
'1:heroku_name' && ret=0
|
||||
;;
|
||||
(info)
|
||||
_arguments \
|
||||
'(-f --file)'{-f,--file}='[alternate json filename]: :_files -g "*.json"' \
|
||||
'(-j --json)'{-j,--json}'[render output as json]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(pdf|static)
|
||||
_arguments \
|
||||
'(-f --file --pres_file)'{-f,--file,--pres_file}='[JSON file used to describe presentation(default: showoff.json)]: :_files -g "*.json"' \
|
||||
'(-l --lang --language --locale)'{-l,--lang,--language,--locale}'[Language code to generate(default: none)]' \
|
||||
'1:name' \
|
||||
&& ret=0
|
||||
;;
|
||||
(serve)
|
||||
_arguments \
|
||||
'(-S --standalone)'{-S,--standalone}'[Run in standalone mode with no audience interaction]' \
|
||||
'(-f --file --pres_file)'{-f,--file,--pres_file}='[JSON file used to describe presentation(default: showoff.json)]: :_files -g "*.json"' \
|
||||
'--git_branch=[Branch of git repository to use(default: none)]:branch' \
|
||||
'--git_path=[Path of the presentation within the git repository(default: none)]:path' \
|
||||
'(-h --host)'{-h,--host}='[Host or ip to run on(default: 0.0.0.0)]' \
|
||||
'--nocache[Disable content caching]'\
|
||||
'--nosleep[Prevent the computer from sleeping during your presentation]' \
|
||||
'(-p --port)'{-p,--port}='[Port on which to run(default: 9090)]' \
|
||||
'(-r --review)'{-r,--review}'[Enable code review]'\
|
||||
'(-s --ssl)'{-s,--ssl}'[Run via HTTPS]' \
|
||||
'--ssl_certificate=[Path to SSL certificate]: :_files' \
|
||||
'--ssl_private_key=[Path to SSL private key]: :_files' \
|
||||
'(-u --url --git_url)'{-u,--url,--git_url}='[GIT URL to a repository containing the presentation]:url' \
|
||||
'(-v --verbose)'{-v,--verbose}'[Show verbose messaging]' \
|
||||
'(-x --execute --executecode)'{-x,--execute,--executecode}'[Enable remote code execution]' \
|
||||
'1: :_files -/' && ret=0
|
||||
;;
|
||||
(skeleton|validate)
|
||||
_arguments \
|
||||
'(-f --file)'{-f,--file}'=[alternate json filename(default: none)]: :_files -g "*.json"' \
|
||||
&& ret=0
|
||||
;;
|
||||
*)
|
||||
(( ret )) && _message 'no more arguments'
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
case $state in
|
||||
(args)
|
||||
case $line[1] in
|
||||
(add|new)
|
||||
_arguments \
|
||||
'(-d --dir)'{-d,--dir}='[Slide dir (where to put a new slide file)]:directory:_files -/' \
|
||||
'(-n --name)'{-n,--name}='[Slide name (name of the new slide file)]:basename' \
|
||||
{-s,--source}='[Include code from the given file as the slide body]:file:_files' \
|
||||
'(-t --style --type)'{-t,--style,--type}='[Slide Type/Style (default: title)]:style' \
|
||||
'(-u --nonumber)'{-u,--nonumber}"[Don't number the slide, use the given name verbatim]" \
|
||||
'1:title' && ret=0
|
||||
;;
|
||||
(create|init)
|
||||
_arguments \
|
||||
'(-d --slidedir)'{-d,--slidedir}='[Sample slide directory name (default: one)]:arg' \
|
||||
'(-n --nosamples)'{-n,--nosamples}="[Don't create sample slides]" \
|
||||
'1:dir_name' && ret=0
|
||||
;;
|
||||
(help)
|
||||
_arguments \
|
||||
'-c[List commands one per line, to assist with shell completion]' \
|
||||
'1: :_showoff_help' && ret=0
|
||||
;;
|
||||
(heroku)
|
||||
_arguments \
|
||||
'(-f --force)'{-f,--force}'[force overwrite of existing Gemfile, .gems and config.ru files if they exist]' \
|
||||
'(-p --password)'{-p,--password}='[add password protection to your heroku site(default: none)]' \
|
||||
'1:heroku_name' && ret=0
|
||||
;;
|
||||
(info)
|
||||
_arguments \
|
||||
'(-f --file)'{-f,--file}='[alternate json filename]: :_files -g "*.json"' \
|
||||
'(-j --json)'{-j,--json}'[render output as json]' \
|
||||
&& ret=0
|
||||
;;
|
||||
(pdf|static)
|
||||
_arguments \
|
||||
'(-f --file --pres_file)'{-f,--file,--pres_file}='[JSON file used to describe presentation(default: showoff.json)]: :_files -g "*.json"' \
|
||||
'(-l --lang --language --locale)'{-l,--lang,--language,--locale}'[Language code to generate(default: none)]' \
|
||||
'1:name' \
|
||||
&& ret=0
|
||||
;;
|
||||
(serve)
|
||||
_arguments \
|
||||
'(-S --standalone)'{-S,--standalone}'[Run in standalone mode with no audience interaction]' \
|
||||
'(-f --file --pres_file)'{-f,--file,--pres_file}='[JSON file used to describe presentation(default: showoff.json)]: :_files -g "*.json"' \
|
||||
'--git_branch=[Branch of git repository to use(default: none)]:branch' \
|
||||
'--git_path=[Path of the presentation within the git repository(default: none)]:path' \
|
||||
'(-h --host)'{-h,--host}='[Host or IP to run on(default: 0.0.0.0)]' \
|
||||
'--nocache[Disable content caching]'\
|
||||
'--nosleep[Prevent the computer from sleeping during your presentation]' \
|
||||
'(-p --port)'{-p,--port}='[Port on which to run(default: 9090)]' \
|
||||
'(-r --review)'{-r,--review}'[Enable code review]'\
|
||||
'(-s --ssl)'{-s,--ssl}'[Run via HTTPS]' \
|
||||
'--ssl_certificate=[Path to SSL certificate]: :_files' \
|
||||
'--ssl_private_key=[Path to SSL private key]: :_files' \
|
||||
'(-u --url --git_url)'{-u,--url,--git_url}='[GIT URL to a repository containing the presentation]:url' \
|
||||
'(-v --verbose)'{-v,--verbose}'[Show verbose messaging]' \
|
||||
'(-x --execute --executecode)'{-x,--execute,--executecode}'[Enable remote code execution]' \
|
||||
'1: :_files -/' && ret=0
|
||||
;;
|
||||
(skeleton|validate)
|
||||
_arguments \
|
||||
'(-f --file)'{-f,--file}'=[alternate json filename(default: none)]: :_files -g "*.json"' \
|
||||
&& ret=0
|
||||
;;
|
||||
*)
|
||||
(( ret )) && _message 'no more arguments'
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
|
||||
return ret
|
||||
}
|
||||
|
|
186
src/_ufw
186
src/_ufw
|
@ -28,7 +28,7 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# Completion script for The Uncomplicated Firewall (ufw). (https://launchpad.net/ufw).
|
||||
# Completion script for The Uncomplicated Firewall (ufw) v0.36.2. (https://launchpad.net/ufw).
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
# Authors
|
||||
|
@ -38,108 +38,132 @@
|
|||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
|
||||
_ufw_logging() {
|
||||
local params additional second
|
||||
second=$words[2]
|
||||
|
||||
local params additional second
|
||||
second=$words[2]
|
||||
if [ ! -z $second ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [ ! -z $second ]; then
|
||||
return
|
||||
fi
|
||||
params=("on" "off")
|
||||
additional=("low" "medium" "high" "full")
|
||||
|
||||
params=(
|
||||
"on"
|
||||
"off"
|
||||
)
|
||||
|
||||
additional=(
|
||||
"low"
|
||||
"medium"
|
||||
"high"
|
||||
"full"
|
||||
)
|
||||
|
||||
_describe -t params 'on/off' params
|
||||
_describe -t additional 'level' additional
|
||||
_describe -t params 'on/off' params
|
||||
_describe -t additional 'level' additional
|
||||
}
|
||||
|
||||
|
||||
_ufw_delete() {
|
||||
local rules complrules second
|
||||
local rules complrules second
|
||||
|
||||
second=$words[2]
|
||||
second=$words[2]
|
||||
|
||||
if [ ! -z $second ]; then
|
||||
return
|
||||
fi
|
||||
if [ ! -z $second ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
complrules=()
|
||||
rules=("${(f)$(ufw status | tr -s ' ' | tail -n +5 | tr -s '\n')}")
|
||||
complrules=()
|
||||
rules=("${(f)$(ufw status | tr -s ' ' | tail -n +5 | tr -s '\n')}")
|
||||
|
||||
for ((i=1; i<=${#rules[@]}; i++)); do
|
||||
complrules+=("$i:$rules[i]");
|
||||
done
|
||||
for ((i=1; i<=${#rules[@]}; i++)); do
|
||||
complrules+=("$i:$rules[i]");
|
||||
done
|
||||
|
||||
_describe -t complrules 'Rules' complrules
|
||||
_describe -t complrules 'Rules' complrules
|
||||
}
|
||||
|
||||
_ufw_app() {
|
||||
local ret=1
|
||||
|
||||
local -a subcmds=(
|
||||
"list:list application profiles"
|
||||
"info:show information on profile"
|
||||
"update:update profile"
|
||||
"default:set default application profile"
|
||||
)
|
||||
|
||||
_arguments \
|
||||
"1: :{_describe 'command' subcmds}" \
|
||||
&& ret=0
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
(( $+functions[_flutter_pub_token_subcommand] )) ||
|
||||
_flutter_pub_token_subcommand() {
|
||||
local -a subcommands=(
|
||||
|
||||
)
|
||||
_describe -t subcommands 'subcommand' subcommands "$@"
|
||||
}
|
||||
|
||||
_ufw() {
|
||||
local curcontext="$curcontext" ret=1
|
||||
local -a state line commands
|
||||
local curcontext="$curcontext" ret=1
|
||||
local -a state line commands
|
||||
|
||||
commands=(
|
||||
"enable:enable the firewall"
|
||||
"disable:disable the firewall"
|
||||
"default:set default policy"
|
||||
"logging:set logging level"
|
||||
"allow:add allow rule"
|
||||
"deny:add deny rule"
|
||||
"reject:add reject rule"
|
||||
"limit:add limit rule"
|
||||
"delete:delete rule"
|
||||
"insert:insert rule at position"
|
||||
"route:add route rule"
|
||||
"reload:reload firewall"
|
||||
"reset:reset firewall"
|
||||
"status:show firewall status"
|
||||
"show:show firewall report"
|
||||
"version:display version information"
|
||||
"prepend:add rule before all of the same type"
|
||||
)
|
||||
commands=(
|
||||
"enable:enable the firewall"
|
||||
"disable:disable the firewall"
|
||||
"default:set default policy"
|
||||
"logging:set logging level"
|
||||
"allow:add allow rule"
|
||||
"deny:add deny rule"
|
||||
"reject:add reject rule"
|
||||
"limit:add limit rule"
|
||||
"delete:delete rule"
|
||||
"insert:insert rule at position"
|
||||
"route:add route rule"
|
||||
"reload:reload firewall"
|
||||
"reset:reset firewall"
|
||||
"status:show firewall status"
|
||||
"show:show firewall report"
|
||||
"version:display version information"
|
||||
"prepend:add rule before all of the same type"
|
||||
"app:application profile command"
|
||||
)
|
||||
|
||||
_arguments -C -s -S -n \
|
||||
'(- 1 *)'--version"[display version information]: :->full" \
|
||||
'(- 1 *)'{-h,--help}'[display usage information]: :->full' \
|
||||
'(- 1 *)'--dry-run"[don't modify anything, just show the changes]: :->cmds" \
|
||||
'1:cmd:->cmds' \
|
||||
'*:: :->args' && ret=0
|
||||
_arguments -C -s -S -n \
|
||||
'(- 1 *)'--version"[display version information]: :->full" \
|
||||
'(- 1 *)'{-h,--help}'[display usage information]: :->full' \
|
||||
'(- 1 *)'--dry-run"[don't modify anything, just show the changes]: :->cmds" \
|
||||
'1:cmd:->cmds' \
|
||||
'*:: :->args' && ret=0
|
||||
|
||||
case "$state" in
|
||||
(cmds)
|
||||
_describe -t commands 'commands' commands
|
||||
case "$state" in
|
||||
(cmds)
|
||||
_describe -t commands 'commands' commands
|
||||
;;
|
||||
(args)
|
||||
local cmd
|
||||
cmd=$words[1]
|
||||
case "$cmd" in
|
||||
(logging)
|
||||
_ufw_logging && ret=0
|
||||
;;
|
||||
(delete)
|
||||
_ufw_delete && ret=0
|
||||
;;
|
||||
(*)
|
||||
_default && ret=0
|
||||
;;
|
||||
esac
|
||||
(args)
|
||||
local cmd
|
||||
cmd=$words[1]
|
||||
case "$cmd" in
|
||||
(logging)
|
||||
_ufw_logging && ret=0
|
||||
;;
|
||||
(delete)
|
||||
_ufw_delete && ret=0
|
||||
;;
|
||||
(app)
|
||||
_ufw_app && ret=0
|
||||
;;
|
||||
(*)
|
||||
_default && ret=0
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
(*)
|
||||
(*)
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
|
||||
return ret
|
||||
return ret
|
||||
}
|
||||
|
||||
_ufw
|
||||
_ufw "$@"
|
||||
|
||||
# Local Variables:
|
||||
# mode: Shell-Script
|
||||
# sh-indentation: 2
|
||||
# indent-tabs-mode: nil
|
||||
# sh-basic-offset: 2
|
||||
# End:
|
||||
# vim: ft=zsh sw=2 ts=2 et
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
# Description
|
||||
# -----------
|
||||
#
|
||||
# Completion script for xsel (https://www.vergenet.net/~conrad/software/xsel/).
|
||||
# Completion script for xsel v1.2.1 (https://www.vergenet.net/~conrad/software/xsel/).
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
# Authors
|
||||
|
@ -45,6 +45,7 @@ local selection='(-p --primary -s --secondary -b --clipboard)'
|
|||
_arguments -s \
|
||||
$input{-a,--append}'[append standard input to the selection]' \
|
||||
$input{-f,--follow}'[append to selection as standard input grows]' \
|
||||
$input{-z,--zeroflush}'[overwrites selection when zero(\\0) is received]' \
|
||||
$input{-i,--input}'[read standard input into the selection]' \
|
||||
{-o,--output}'[write the selection to standard output]' \
|
||||
$operation{-c,--clear}'[clear the selection]' \
|
||||
|
@ -55,6 +56,7 @@ _arguments -s \
|
|||
$operation{-k,--keep}'[do not modify the selections, but make the PRIMARY and SECONDARY selections persist even after the programs they were selected in exit]' \
|
||||
$operation{-x,--exchange}'[exchange the PRIMARY and SECONDARY selections]' \
|
||||
'--display[specify the server to use; see X(1)]:X display:_x_display' \
|
||||
'--windowName[specify the X WM_ NAME window property]:window_name' \
|
||||
{-t,--selectionTimeout}'[specify the timeout in milliseconds within which the selection must be retrieved]:number' \
|
||||
{-l,--logfile}'[specify the file to log errors to when detached (default $HOME/.xsel.log)]:log file:_files' \
|
||||
{-n,--nodetach}'[do not detach from the controlling terminal]' \
|
||||
|
|
|
@ -0,0 +1,454 @@
|
|||
* 目录
|
||||
- [[#介绍][介绍]]
|
||||
- [[#开始][开始]]
|
||||
- [[#让zsh知道用哪个函数补全命令][让zsh知道用哪个函数补全命令]]
|
||||
- [[#补全gnu格式命令][补全gnu格式命令]]
|
||||
- [[#从其它命令复制补全][从其它命令复制补全]]
|
||||
- [[#编写你自己的补全代码][编写你自己的补全代码]]
|
||||
- [[#工具函数][工具函数]]
|
||||
- [[#用_describe编写简单的补全函数][用_describe编写简单的补全函数]]
|
||||
- [[#用_alternative编写补全函数][用_alternative编写补全函数]]
|
||||
- [[#用_arguments编写补全函数][用_arguments编写补全函数]]
|
||||
- [[#用_regex_arguments和_regex_words编写补全函数][用_regex_arguments和_regex_words编写补全函数]]
|
||||
- [[#用_values_sep_parts和_multi_parts实现复杂补全][用_values、_sep_parts和_multi_parts实现复杂补全]]
|
||||
- [[#用compadd直接添加补全词][用compadd直接添加补全词]]
|
||||
- [[#测试与debug][测试与debug]]
|
||||
- [[#踩坑了吧-需要小心的东西][踩坑了吧 (需要小心的东西)]]
|
||||
- [[#小贴士][小贴士]]
|
||||
- [[#其它资源][其它资源]]
|
||||
|
||||
> 译注:本文可能有不通顺的地方,或者采用的词汇不是很正确。
|
||||
> 如果你有更好的主意,欢迎提交PR。
|
||||
|
||||
* 介绍
|
||||
Zsh官方的补全函数文档令人费解,而且也没提供多少示例。
|
||||
写这份文档的当下我已经在网上找到了其它几份教程,但是那些教程只涉及了补全系统的一小部分。
|
||||
这份文档目的在于补全网上其它地方没涵盖的部分,同时附带示例,这样读者就可以学会如何写更高级的补全函数。
|
||||
我不会展开每一细节,但给你提供的内容和示例足以从零开始。
|
||||
如果你需要了解更多细节,你可以自行查询[[https://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System][官方文档]]。
|
||||
|
||||
还请公开你所创作的任何脚本(比如fork这个仓库然后[[id:64bcd501-b0f0-48c7-b8e2-07af708b95ec][pr]])。
|
||||
此外如果你有任何更多补充内容或对此教程的改进,欢迎做贡献。
|
||||
* 开始
|
||||
** 让zsh知道用哪个函数补全命令
|
||||
补全命令用的补全函数储存于名字以下划线“_”起始的文件,这些文件应存于$fpath变量所列出的某目录中。
|
||||
你可以将下面的代码写入你的~/.zshrc以在$fpath中新增目录:
|
||||
#+BEGIN_SRC sh
|
||||
fpath=(~/newdir $fpath)
|
||||
#+END_SRC
|
||||
一个补全函数文件的第一行长这个样:
|
||||
#+BEGIN_SRC sh
|
||||
#compdef foobar
|
||||
#+END_SRC
|
||||
这行代码表示这个文件含有补全foobar命令的代码。
|
||||
多数情况下第一行都采用这个格式,但你也可以用同一个文件补全多个不同的函数。
|
||||
查阅[[https://zsh.sourceforge.net/Doc/Release/Completion-System.html#Autoloaded-files][官方文档]]以了解更多细节。
|
||||
|
||||
你也可以直接使用compdef命令(比如在你的~/.zshrc文件里)来告诉zsh用哪个函数补全命令:
|
||||
#+BEGIN_SRC sh
|
||||
> compdef _function foobar
|
||||
#+END_SRC
|
||||
或者对多个命令使用同一种补全:
|
||||
#+BEGIN_SRC sh
|
||||
> compdef _function foobar goocar hoodar
|
||||
#+END_SRC
|
||||
如果你想提供参数的话:
|
||||
#+BEGIN_SRC sh
|
||||
> compdef '_function arg1 arg2' foobar
|
||||
#+END_SRC
|
||||
查阅[[https://zsh.sourceforge.net/Doc/Release/Completion-System.html#Functions-4][官方文档]]以了解更多细节。
|
||||
** 补全gnu格式命令
|
||||
很多[[https://www.gnu.org/][gnu]]命令以标准化的方式列出选项描述(使用--help选项时)。
|
||||
对于这些命令你可以使用_gnu_generic函数自动创建补全,比如这样:
|
||||
#+BEGIN_SRC sh
|
||||
> compdef _gnu_generic foobar
|
||||
#+END_SRC
|
||||
或者对多个不同命令使用_gnu_generic:
|
||||
#+BEGIN_SRC sh
|
||||
> compdef _gnu_generic foobar goocar hoodar
|
||||
#+END_SRC
|
||||
你可以把这行代码放进~/.zshrc文件里。
|
||||
** 从其它命令复制补全
|
||||
如果你想要让一个命令(比如cmd1)和另一个已有补全的命令(比如cmd2)拥有相同的补全,你可以:
|
||||
#+BEGIN_SRC sh
|
||||
> compdef cmd1=cmd2
|
||||
#+END_SRC
|
||||
比如当你给一个命令创建了一个助记alias的时候会很有帮助。
|
||||
* 编写你自己的补全代码
|
||||
你可以通过阅读已有的补全函数来开始入门。
|
||||
在我的Linux系统上这些补全函数在/usr/share/zsh/functions/Completion/Unix、
|
||||
/usr/share/zsh/functions/Completion/Linux和一些其它子目录下。
|
||||
|
||||
你会注意到这些文件频繁使用_arguments函数。
|
||||
该函数是一个工具函数,可用于编写简单的补全函数。
|
||||
_arguments函数是一个compadd内置函数的包装函数。
|
||||
compadd内置函数是一个核心函数,用于向命令行加入补全词,并控制其行为。
|
||||
不过,多数情况下你不需要使用compadd,因为有很多更易于使用的工具函数,如_arguments和_describe。
|
||||
|
||||
对于非常基础的补全,_describe函数已经够用了。
|
||||
|
||||
** 工具函数
|
||||
下面是一个工具函数列表,你或许会用到它们。
|
||||
工具函数的完整列表及使用方法在[[https://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-Functions][此]]可供查阅。
|
||||
这些函数的使用示例在下一节给出。
|
||||
|
||||
> 译注:从这里开始会出现一些术语,如定义(specification)、描述(description)、动作(action)、词汇(word)等。
|
||||
> 初次阅读可能会觉得比较困难,尤其是下面的工具函数表格,稍后教程开始一一讲解并给出示例的时候就好懂多了。
|
||||
> 定义指的是对补全规则的定义,如`_describe 定义`。
|
||||
> 描述当然指的是对命令行选项和参数的用户友好描述,补全时会显示在屏幕上,如:'-o 输出文件'
|
||||
> 词汇指的是如同'word'、'-o'、'--help'、'start'等连续的一小段字符串
|
||||
> 动作指的是匹配成功后执行的操作,比如执行某函数生成补全,或直接补全等等。
|
||||
> 选项(option)和参数指给命令提供的选项和参数,如`cp -r src dst`中,`-r`为选项,`src`和`dst`为参数。有些选项带参,如`tar -f file ...`中`-f`选项带`file`参数。
|
||||
> 候选(candidate)指可能的补全结果,如补全`tar -f`时目录下所有文件会被作为候选,补全`systemctl`时`start`、`stop`、`list-units`等指令会被作为候选。
|
||||
> 还请不要感到灰心,读下去就是了。
|
||||
|
||||
*** 用于大部分补全的主要工具函数
|
||||
| _alternative | 从其它工具函数或shell代码生成补全候选。 |
|
||||
| _arguments | 指定如何补全一命令的各选项和参数(命令选项风格为unix风格)。 |
|
||||
| _describe | 创建由带描述的词汇(但不包含动作)组成的简单补全。比_arguments更简单。 |
|
||||
| _gnu_generic | 为带有“--help”选项的命令补全选项。 |
|
||||
| _regex_arguments | 创建一先用regex表达式匹配命令行参数再执行动作/补全的函数。 |
|
||||
*** 对单个词汇进行复杂补全的工具函数
|
||||
| _values | 补全任意词汇(值)及其参数,或逗号分隔的词汇与参数列表。 |
|
||||
| _combination | 补全值的组合,比如域名和用户名的二元组。 |
|
||||
| _multi_parts | 对词汇的由符号分隔的多个部分分别补全,比如补全路径:/u/i/sy -> /usr/include/sys |
|
||||
| _sep_parts | 类似_multi_parts但在补全的不同部分中允许不同的分隔符。 |
|
||||
| _sequence | 包装另一补全函数,并补全由该函数生成的匹配列表。 |
|
||||
*** 用于补全特定对象种类的函数
|
||||
| _path_files | 补全文件目录。用多个选项控制行为。 |
|
||||
| _files | 使用所有选项调用_path_files,除了-g和-/。这些选项取决于file-patterns风格设置。 |
|
||||
| _net_interfaces | 补全网络接口名称。 |
|
||||
| _users | 补全用户名 |
|
||||
| _groups | 补全组名 |
|
||||
| _options | 补全shell选项名。 |
|
||||
| _parameters | 补全shell参数/变量名(可用模式匹配限制要补全的参数/变量名)。 |
|
||||
*** 处理已缓存的补全的函数
|
||||
如果你有大量的补全,你可以将补全保存于一个缓存文件以快速加载。
|
||||
| _cache_invalid | 指明补全缓存是否需要重新构建(rebuild),缓存由标识符指定 |
|
||||
| _retrieve_cache | 从缓存文件获取补全信息 |
|
||||
| _store_cache | 储存缓存于缓存文件,缓存由标识符指定 |
|
||||
*** 其它函数
|
||||
| _message | 当无补全可生成时显示帮助信息。 |
|
||||
| _regex_words | 为_regex_arguments命令生成参数。比手写参数更简单。 |
|
||||
| _guard | 检查被补全的词汇,用于_arguments和类似函数的定义的ACTION中。 |
|
||||
*** 动作(Actions)
|
||||
许多工具函数,如_arguments、_regex_arguments、_alternative和_values,在选项/参数末尾有一个action。
|
||||
这个action指定如何补全对应的参数。
|
||||
这些action可以是如下形式之一:
|
||||
| ( ) | 需要提供参数但未生成任何匹配 |
|
||||
| (ITEM1 ITEM2) | 匹配列表 |
|
||||
| ((ITEM1\:'DESC1' ITEM2\:'DESC2')) | 匹配列表,带有描述。引号必须和整个定义所使用的引号不同。 |
|
||||
| ->STRING | 将$state设为STRING然后继续(可在调用工具函数后用case语句检查$state的值) |
|
||||
| FUNCTION | 生成匹配或完成其它操作的函数的函数名,比如_files或_message |
|
||||
| {EVAL-STRING} | 把字符串当作shell代码执行(evaluate)。可用于带参调用工具函数,如_values或_describe |
|
||||
| =ACTION | 在补全命令行中插入占位词汇不改变补全点。 |
|
||||
|
||||
并非所有的action种类都可用于使用action的工具函数。比如->STRING类不可用于_regex_arguments或_alternative函数。
|
||||
** 用_describe编写简单的补全函数
|
||||
_describe函数可以用于简单的补全,此类补全的选项/参数的位置与顺序无关紧要。
|
||||
你只需用一个数组参数储存这些选项和其描述,然后将数组参数的名作为参数传入_describe。
|
||||
下面的示例创建补全候选c和d(注意代码文件名应为_cmd,并且文件存于$fpath所列出的目录之下)。
|
||||
#+BEGIN_SRC sh
|
||||
#compdef cmd
|
||||
local -a subcmds
|
||||
subcmds=('c:c命令描述' 'd:d命令描述')
|
||||
_describe 'command' subcmds
|
||||
#+END_SRC
|
||||
|
||||
你可以像下面一样使用由双横杠分隔的列表,但注意实操时会混合匹配结果,所以不应该用于不同种类的补全候选:
|
||||
#+BEGIN_SRC sh
|
||||
local -a subcmds topics
|
||||
subcmds=('c:c命令描述' 'd:d命令的描述')
|
||||
topics=('e:e帮助主题的描述' 'f:f帮助主题的描述')
|
||||
_describe 'command' subcmds -- topics
|
||||
#+END_SRC
|
||||
|
||||
如果两个候选有相同的描述,_describe把它们集于一行,并确保描述严格按列对齐。
|
||||
_describe函数可用在_alternative、_arguments或_regex_arguments的ACTION中。
|
||||
在这种情况下你需要用括号将_describe和参数包起来,比如'TAG:DESCRIPTION:{_describe 'values' options}'
|
||||
** 用_alternative编写补全函数
|
||||
如同_describe,该函数进行简单补全,其选项/参数的顺序和位置并不重要。
|
||||
然而,与_describe的固定匹配不同,_alternative可进一步调用函数生成补全候选。
|
||||
此外,_alternative允许混合不同种类的补全候选。
|
||||
|
||||
关于参数,该函数接受一列定义(specification),每项定义的形式为“TAG:DESCRIPTION:ACTION”(即“标签:描述:动作”),其中TAG是一个标识补全匹配种类的特殊标签。
|
||||
DESCRIPTION以标题(heading)的形式描述补全候选组,而ACTION是先前列出的动作种类之一(除了->STRING和=ACTION之外)。
|
||||
例如:
|
||||
#+BEGIN_SRC sh
|
||||
_alternative 'arguments:自定义参数:(a b c)' 'files:文件名:_files'
|
||||
#+END_SRC
|
||||
第一个定义增加了补全候选a、b和c,而第二个定义调用_files函数以补全文件目录。
|
||||
|
||||
我们可以用反斜杠 \ 将不同定义分成几行并给每个自定义参数加入描述文字:
|
||||
#+BEGIN_SRC sh
|
||||
_alternative \
|
||||
'args:自定义参数:((a\:"描述a" b\:"描述b" c\:"描述c"))' \
|
||||
'files:文件名:_files'
|
||||
#+END_SRC
|
||||
|
||||
如果我们想向_files传递参数,我们可以直接写在_files后面:
|
||||
#+BEGIN_SRC sh
|
||||
_alternative \
|
||||
'args:自定义参数:((a\:"描述a" b\:"描述b" c\:"描述c"))' \
|
||||
'files:文件名:_files -/'
|
||||
#+END_SRC
|
||||
|
||||
如要用变量展开创建补全列表,必须用双引号将定义括起来,
|
||||
如:
|
||||
#+BEGIN_SRC sh
|
||||
_alternative \
|
||||
"dirs:用户目录:($userdirs)" \
|
||||
"pids:进程ID:($(ps -A o pid=))"
|
||||
#+END_SRC
|
||||
在此例子中第一个定义加入$userdirs变量中的词汇,第二个定义执行'ps -A o pid='并获取pid表,pid表用作补全候选。
|
||||
实操中,我们使用已有的_pids函数,而不是像上面那样手写。
|
||||
|
||||
我们可以在ACTION中使用_values等其它工具函数以完成更复杂的补全,如:
|
||||
#+BEGIN_SRC sh
|
||||
_alternative \
|
||||
"directories:用户目录:($userdirs)" \
|
||||
'options:逗号分隔选项: _values -s , letter a b c'
|
||||
#+END_SRC
|
||||
该示例补全$userdirs里的项目,以及用逗号分隔的、含有a、b和/或c的列表。
|
||||
注意_values前面的空格。空格不可省略,因为_values不能接受标准compadd描述选项。
|
||||
|
||||
和_describe一样,_alternative可用作ACTION并作为_arguments或_regex_arguments的一部分。
|
||||
** 用_arguments编写补全函数
|
||||
只需要调用_arguments函数一次就可以创造出非常智能的补全函数。该函数本身就是用于处理这种带有带参选项的命令的。
|
||||
如同_alternative函数,_arguments接受一列定义字符串参数。
|
||||
这些定义字符串指定选项和任何对应的选项参数(如:-f 文件名),或命令参数。
|
||||
|
||||
简单的选项定义用'-OPT[DESCRIPTION]'(即'-选项[描述]'),比如:
|
||||
#+BEGIN_SRC sh
|
||||
_arguments '-s[排序后输出]' '--l[更多输出]' '-l[更多输出]'
|
||||
#+END_SRC
|
||||
选项参数可在选项描述后指定,形式用'-OPT[DESCRIPTION]:MESSAGE:ACTION'(即'-选项[描述]:消息:动作'),
|
||||
其中MESSAGE是待显示的信息,而ACTION可以是前面的动作(Actions)章节提到的任何形式。
|
||||
比如:
|
||||
#+BEGIN_SRC sh
|
||||
_arguments '-f[输入文件]:文件名:_files'
|
||||
#+END_SRC
|
||||
|
||||
命令参数定义用'N:MESSAGE:ACTION'(即'N:消息:动作'),其中N指定这是第N个命令参数,而MESSAGE和ACTION都和前面的一样。
|
||||
如果N被省略,则其仅表示这是(在所有已定义的参数之后的)下一个参数。如果开头(在N后面)用的是双冒号,则参数非必需。
|
||||
比如:
|
||||
#+BEGIN_SRC sh
|
||||
_arguments '-s[排序后输出]' '1:第一个参数:_net_interfaces' '::可选参数:_files' ':下一个参数:(a b c)'
|
||||
#+END_SRC
|
||||
这里第一个参数是网络接口,下一个可选参数是一个文件名,最后一个参数可以是a、b或c,而-s选项可以在任何位置被补全。
|
||||
|
||||
_arguments函数允许所有ACTION形式(在前面的动作(Actions)章节列出)。
|
||||
这表示你可以用动作来选择case语句分支,如:
|
||||
#+BEGIN_SRC sh
|
||||
_arguments '-m[音乐文件]:文件名:->files' '-f[flags]:flag:->flags'
|
||||
case "$state" in
|
||||
files)
|
||||
local -a music_files
|
||||
music_files=( Music/**/*.{mp3,wav,flac,ogg} )
|
||||
_multi_parts / music_files
|
||||
;;
|
||||
flags)
|
||||
_values -s , 'flags' a b c d e
|
||||
;;
|
||||
esac
|
||||
#+END_SRC
|
||||
在此例子中指向音乐文件的路径被_multi_parts一步步地沿目录下降补全,
|
||||
而flags被_values函数按照逗号分隔列表补全。
|
||||
|
||||
我已经介绍了_arguments定义的基础部分,你还可以定义互斥选项、重复选项和参数、以+开头的选项等。有关更多细节,查阅[[https://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System][官方文档]]。
|
||||
同时你也可以看看本文末尾列出的教程,以及[[https://github.com/vapniks/zsh-completions/tree/master/src][src目录]]下的补全函数。
|
||||
** 用_regex_arguments和_regex_words编写补全函数
|
||||
如果你的命令行定义比较复杂,有多个可能的参数序列,那你可能需要_regex_arguments函数。
|
||||
该函数也适用于有一系列跟着多个参数的关键词的情况。
|
||||
|
||||
_regex_arguments创建名字由第一个参数给出的补全函数。
|
||||
因此你需要先调用_regex_arguments来创建补全函数,然后再调用该函数,比如:
|
||||
#+BEGIN_SRC sh
|
||||
_regex_arguments _cmd OTHER_ARGS..
|
||||
_cmd "$@"
|
||||
#+END_SRC
|
||||
|
||||
OTHER_ARGS(即“其它参数”)是一序列用于在命令行上匹配和补全词汇的定义。
|
||||
这些序列可被'|'分隔来表示备选词汇序列。
|
||||
你可以用任意嵌套深度的括号来指定备选序列,但括号必须带反斜杠前缀,如\( \),或用引号括起来,如'(' ')'。
|
||||
|
||||
比如:
|
||||
#+BEGIN_SRC sh
|
||||
_regex_arguments _cmd 序列1 '|' 序列2 \( 序列2a '|' 序列2b \)
|
||||
_cmd "$@"
|
||||
#+END_SRC
|
||||
该示例定义一个匹配序列1或序列2后跟着序列2a或序列2b的命令行。这种方式和正则表达式语法类似。
|
||||
|
||||
一个序列中的每个定义必须在开头包含一个/ PATTERN/ (即/ 模式/)部分,后跟着可选的':TAG:DESCRIPTION:ACTION'(即':标签:描述:动作')部分。
|
||||
|
||||
每个PATTERN是一个匹配一命令行词汇的正则表达式。这些模式按顺序匹配,直到某个模式不匹配,不匹配的模式将执行对应的ACTION(动作)以进行补全。
|
||||
注意,一定要有一个匹配命令自身的模式。
|
||||
下面有对PATTERN(模式)更详细的解释。
|
||||
|
||||
':TAG:DESCRIPTION:ACTION'的使用方法和_alternative相同,只是开头多了个冒号“:”,并且前面列出的所有ACTION格式都可用。
|
||||
|
||||
例如:
|
||||
#+BEGIN_SRC sh
|
||||
_regex_arguments _cmd /$'[^\0]##\0'/ \( /$'word1(a|b|c)\0'/ ':word:first word:(word1a word1b word1c)' '|'\
|
||||
/$'word11(a|b|c)\0'/ ':word:first word:(word11a word11b word11c)' \( /$'word2(a|b|c)\0'/ ':word:second word:(word2a word2b word2c)'\
|
||||
'|' /$'word22(a|b|c)\0'/ ':word:second word:(word22a word22b word22c)' \) \)
|
||||
_cmd "$@"
|
||||
#+END_SRC
|
||||
TODO 英文原文和例子有出入
|
||||
|
||||
在这个例子中第一个词可以是word1(即“词1”,下同)或者word11后紧跟a、b或c,并且如果第一个词含有11,则第二个词可以是word2后紧跟a、b或c,或一个文件名。
|
||||
|
||||
如果感觉太复杂,你也可以用更简单的_regex_words函数达到相同效果。
|
||||
*** 模式
|
||||
你可能注意到了上个例子中的/ PATTERN/和普通的正则表达式不太一样。
|
||||
通常使用的是形如$'foo\0'的字符串参数。这是为了让\0表示成null字符,而zsh内部用来分隔词汇的也是null字符。
|
||||
如果不在末尾包含\0的话,可能会无法匹配下一个词。如果你要把一个变量的值作为模式的一部分,你可以用双括号包起来,
|
||||
这样变量就会展开,然后再在后面加个包含null字符的字符串参数,比如:"$somevar"$'\0'(somevar即“某变量”)。
|
||||
|
||||
表示模式用的正则表达式语法和正常的正则表达式不太一样,但我也找不到有关的文档。
|
||||
不过我还是试图搞清楚了这些特殊字符的意义:
|
||||
| * | 通配符 - 任何数量的字符 |
|
||||
| ? | 通配符 - 单个字符 |
|
||||
| # | 零个或更多的上一个字符(和一般正则表达式里的*一样) |
|
||||
| ## | 一个或更多的上一个字符(和一般正则表达式里的+一样) |
|
||||
*** _regex_words
|
||||
_regex_words函数比_regex_arguments更简单易用。
|
||||
调用_regex_words后的结果可以存在变量里。
|
||||
|
||||
要用_regex_words创建一个定义(specification),你需要提供一个标签,后跟一段描述,后跟一个定义不同词汇的列表。
|
||||
这些定义采用'WORD:DESCRIPTION:SPEC'(即'词汇:描述:定义')的格式,WORD即待补全的词,DESCRIPTION是对应的描述,
|
||||
SPEC可以是由_regex_words创建的另一个变量以指定当前词后的下一个词汇,也可以留空以表示没有更多的词。
|
||||
比如:
|
||||
#+BEGIN_SRC sh
|
||||
_regex_words firstword '第一个词' 'word1a:词a:' 'word1b:词b:' 'word1c:词c'
|
||||
#+END_SRC
|
||||
该函数的返回结果将被存入$reply(reply即“回复”、“回应”)数组里,所以我们需要在$reply变化前将结果存进另一个数组里,如:
|
||||
#+BEGIN_SRC sh
|
||||
local -a firstword
|
||||
_regex_words word 'The first word' 'word1a:a word:' 'word1b:b word:' 'word1c:c word'
|
||||
firstword="$reply[@]"
|
||||
#+END_SRC
|
||||
firstword即“第一个词”。
|
||||
然后我们可以把结果用在_regex_arguments里,如:
|
||||
#+BEGIN_SRC sh
|
||||
_regex_arguments _cmd /$'[^\0]##\0'/ "$firstword[@]"
|
||||
_cmd "$@"
|
||||
#+END_SRC
|
||||
注意到我给命令自身也加了模式。
|
||||
|
||||
这里还有个更复杂的词汇,我们调用_regex_words以匹配不同词汇
|
||||
#+BEGIN_SRC sh
|
||||
local -a firstword firstword2 secondword secondword2
|
||||
_regex_words word1 '第二个词' 'woo:鄧族' 'hoo:不关我事'
|
||||
secondword=("$reply[@]")
|
||||
_regex_words word2 '另一个第二个词' 'yee:汝' 'haa:很搞笑!'
|
||||
secondword2=("$reply[@]")
|
||||
_regex_words commands '第一个词' 'foo:做foo' 'man:yeah man' 'chu:at chu' # 译注:作者在自嗨,at chu除了比较像at you外没什么特殊意义
|
||||
firstword=("$reply[@]")
|
||||
_regex_words word4 '另一个第一个词' 'boo:吓死某人:$secondword' 'ga:嘤嘤嘤:$secondword'\
|
||||
'loo:上厕所:$secondword2'
|
||||
firstword2=("$reply[@]")
|
||||
|
||||
_regex_arguments _hello /$'[^\0]##\0'/ "${firstword[@]}" "${firstword2[@]}"
|
||||
_hello "$@"
|
||||
#+END_SRC
|
||||
在这个例子中第一个词可以是"foo"、"man"、"chu"、"boo"、"ga"或"loo"。
|
||||
如果第一个词是"boo"或"ga",那下一个词可以是"woo"或"hoo",
|
||||
而如果第一个词是"loo"则第二个词可以是"yee"或"haa",其它情况下没有第二个词。
|
||||
|
||||
_ip函数是_regex_words的一个好用例。
|
||||
** 用_values、_sep_parts和_multi_parts实现复杂补全
|
||||
_values、_sep_parts和_multi_parts可以单独使用,也可以作为_alternative、_arguments或_regex_arguments定义里的ACTION。可以看看下面的例子。
|
||||
查阅[[https://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System][官方文档]]以了解更多信息。
|
||||
|
||||
空格分隔的mp3文件列表:
|
||||
#+BEGIN_SRC sh
|
||||
_values 'mp3文件' ~/*.mp3
|
||||
#+END_SRC
|
||||
|
||||
逗号分隔的会话id列表:
|
||||
#+BEGIN_SRC sh
|
||||
_values -s , '会话id' "${(uonzf)$(ps -A o sid=)}"
|
||||
#+END_SRC
|
||||
|
||||
补全foo@news:woo、foo@news:laa或bar@news:woo等:
|
||||
#+BEGIN_SRC sh
|
||||
_sep_parts '(foo bar)' @ '(news ftp)' : '(woo laa)'
|
||||
#+END_SRC
|
||||
|
||||
补全MAC地址,一次补全一个字节:
|
||||
#+BEGIN_SRC sh
|
||||
_multi_parts : '(00:11:22:33:44:55 00:23:34:45:56:67 00:23:45:56:67:78)'
|
||||
#+END_SRC
|
||||
|
||||
** 用compadd直接添加补全词
|
||||
你可以使用内置的compadd函数增加补全词,以获得更细致的控制。
|
||||
这个函数有各种选项控制如何显示补全以及补全时如何替换命令行上的文字。
|
||||
阅读[[https://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System][官方文档]]以获得更多细节。
|
||||
这里我只给出几个简单的示例。
|
||||
|
||||
向补全列表里加入若干词汇:
|
||||
#+BEGIN_SRC sh
|
||||
compadd foo bar blah
|
||||
#+END_SRC
|
||||
|
||||
同上但显示注释:
|
||||
#+BEGIN_SRC sh
|
||||
compadd -X '一些注释' foo bar blah
|
||||
#+END_SRC
|
||||
|
||||
同上但在补全前自动插入"what_"前缀
|
||||
#+BEGIN_SRC sh
|
||||
compadd -P what_ foo bar blah
|
||||
#+END_SRC
|
||||
|
||||
同上但补全后自动插入"_todo"后缀:
|
||||
#+BEGIN_SRC sh
|
||||
compadd -S _todo foo bar blah
|
||||
#+END_SRC
|
||||
|
||||
同上但在后缀后打空格时自动移除"_todo"后缀:
|
||||
#+BEGIN_SRC sh
|
||||
compadd -P _todo -q foo bar blah
|
||||
#+END_SRC
|
||||
|
||||
向补全数组$wordsarray(wordsarray即“词数组”)加入词汇
|
||||
#+BEGIN_SRC sh
|
||||
compadd -a wordsarray
|
||||
#+END_SRC
|
||||
|
||||
* 测试与debug
|
||||
重新加载补全函数:
|
||||
#+BEGIN_SRC sh
|
||||
> unfunction _func
|
||||
> autoload -U _func
|
||||
#+END_SRC
|
||||
|
||||
这些函数会提供有用的信息。
|
||||
如果默认按键没有用,你可以尝试Alt+x然后再输入命令名。
|
||||
| 函数 | 默认按键 | 作用 |
|
||||
|-----------------+--------------------+----------------------------------------------------------------|
|
||||
| _complete_help | Ctrl+x h | 在当前光标位置补全时显示有关上下文名称、标签和补全函数的信息 |
|
||||
| _complete_help | Alt+2 Ctrl+x h | 同上但显示更多信息 |
|
||||
| _complete_debug | Ctrl+x ? | 执行正常补全,但跟踪补全系统执行的shell命令并存入一个临时文件 |
|
||||
* 踩坑了吧 (需要小心的东西)
|
||||
记得在补全函数的文件开头加那行#compdef
|
||||
|
||||
_arguments或_regex_arguments的定义中要使用正确的引号:
|
||||
如果定义中有变量要展开,用双引号,其它情况用单引号,
|
||||
并且记得在ITEM(项目)描述处用不同的引号。(译注:见[[#动作Actions][动作(Actions)]]章节)
|
||||
|
||||
_arguments、_alternative、_regex_arguments等的定义处要在正确的地方使用正确数量的冒号“:”。
|
||||
|
||||
使用_regex_arguments时要记得在开头写匹配命令的模式(不需要加入匹配动作(action))。
|
||||
|
||||
记得在_regex_arguments的任何PATTERN(模式)参数后加上null字符$'\0'
|
||||
* 小贴士
|
||||
有时一个子命令后只会跟一个选项,这时zsh会在tab在子命令后按下时自动补全。如果你想要在补全前先列出选项和描述,
|
||||
你可以向ACTION(动作)加入另一个空选项(比如\:),如':TAG:DESCRIPTION:((opt1\:"opt1描述" \:))'
|
||||
注意这只对在定义参数中使用ACTION的工具函数(_arguments、_regex_arguments等)有效。
|
||||
|
||||
* 其它资源
|
||||
[[https://wikimatze.de/writing-zsh-completion-for-padrino/][这]]是个展示_arguments函数的基本使用方法的教程,短小精悍,
|
||||
而[[https://web.archive.org/web/20190411104837/http://www.linux-mag.com/id/1106/][这]]是_arguments函数的稍稍更进阶的教程。
|
||||
[[https://zsh.sourceforge.net/Doc/Release/Completion-System.html#Completion-System][这]]是zshcompsys手册页(man page)。
|
Loading…
Reference in New Issue