diff --git a/Makefile b/Makefile index ea417ad..a8b24b7 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@ install: lib $(MAKE) -C doc/ $@ $(MAKE) -C lib/ $@ $(MAKE) -C src/ $@ + $(MAKE) -C completion/ $@ clean: $(MAKE) -C doc/ $@ diff --git a/completion/Makefile b/completion/Makefile new file mode 100644 index 0000000..aac44c9 --- /dev/null +++ b/completion/Makefile @@ -0,0 +1,25 @@ +PREFIX ?= /usr/local +DATAROOTDIR ?= $(PREFIX)/share +ZSH_COMPLETION_DIR ?= $(DATAROOTDIR)/zsh/site-functions + +ZSH_COMPLETION_FILES = \ + zsh/_paccapability \ + zsh/_paccheck \ + zsh/_pacconf \ + zsh/_pacfile \ + zsh/_pacinfo \ + zsh/_pacini \ + zsh/_paclock \ + zsh/_paclog \ + zsh/_pacrepairdb \ + zsh/_pacrepairfile \ + zsh/_pacreport \ + zsh/_pacsift \ + zsh/_pacsync \ + zsh/_pactrans + +install: + install -d "${DESTDIR}${ZSH_COMPLETION_DIR}" + install -m 644 $(ZSH_COMPLETION_FILES) "${DESTDIR}${ZSH_COMPLETION_DIR}" + +.PHONY: install diff --git a/completion/README b/completion/README new file mode 100644 index 0000000..4709acb --- /dev/null +++ b/completion/README @@ -0,0 +1,15 @@ +How to mostly autogenerate the zsh auto complete definitions + +Write code like the following (using pacreport as an example): + +dummy() { pacreport } +compdef _gnu_generic dummy +[tab complete "dummy -" once to cache results] +printf '%s\n' ${(onq-)_args_cache_dummy} + +This will print entries to put in $args. After that, the following needs to be done manually: +* Completing arguments to flags (last optional field) +* Exlusivity (in leading parenthesis) & grouping of the flags. +* Repeatability (leading * after exlusivity) +* Handling any positional arguments. +* Any special handling (such as different modes, e.g. in pactrans or paclock). diff --git a/completion/zsh/_paccapability b/completion/zsh/_paccapability new file mode 100644 index 0000000..0cfcf59 --- /dev/null +++ b/completion/zsh/_paccapability @@ -0,0 +1,9 @@ +#compdef paccapability + +declare -a args +args=( + '(-)--help[display help information]' + '(-)--version[display version information]' + '*:capability: ' +) +_arguments $args diff --git a/completion/zsh/_paccheck b/completion/zsh/_paccheck new file mode 100644 index 0000000..b8ca141 --- /dev/null +++ b/completion/zsh/_paccheck @@ -0,0 +1,28 @@ +#compdef paccheck + +declare -a args +args=( + '--backup[include backup files in modification checks]' + '--config=[set an alternate configuration file]::_files' + '--db-files[include database files in checks]' + '--dbpath=[set an alternate database location]::_files' + '--depends[check for missing dependencies]' + '--file-properties[check installed files against MTREE data]' + '--files[check installed files against package database]' + '(-)--help[display help information]' + '--list-broken[only print packages that fail checks]' + '--md5sum[check file md5sums against MTREE data]' + '--noextract[include NoExtract files in modification checks]' + '--noupgrade[include NoUpgrade files in modification checks]' + '--null=[parse stdin as separated values (default NUL)]::: ' + '--opt-depends[check for missing optional dependencies]' + '--quiet[only display error messages]' + '--recursive[perform checks on package (opt-)depends]' + '--require-mtree[treat packages missing MTREE data as an error]' + '--root=[set an alternate installation root]::_path_files -/' + '--sha256sum[check file sha256sums against MTREE data]' + '--sysroot=[set an alternate system root]::_path_files -/' + '(-)--version[display version information]' + '*:packages:{_values packages $(pacman -Qq)}' +) +_arguments $args diff --git a/completion/zsh/_pacconf b/completion/zsh/_pacconf new file mode 100644 index 0000000..f129b5d --- /dev/null +++ b/completion/zsh/_pacconf @@ -0,0 +1,19 @@ +#compdef pacconf + +declare -a args +args=( + '--arch=[set an alternate architecture]:: ' + '--config=[set an alternate configuration file]::_files' + '(-)--help[display help information]' + '--null=[use to separate values (default NUL)]::sep: ' + '--options[display all global options]' + '--raw[display unmodified values]' + '(-)--repo-list[list configured repositories]' + '--repo=[query options for a specific repo]::{_values repo $(pacconf --repo-list)}' + '--root=[set an alternate installation root]::_path_files -/' + '--single[only display the first value for list items]' + '--verbose[always show directive names]' + '(-)--version[display version information]' + '*:directive: ' +) +_arguments $args diff --git a/completion/zsh/_pacfile b/completion/zsh/_pacfile new file mode 100644 index 0000000..e8872e4 --- /dev/null +++ b/completion/zsh/_pacfile @@ -0,0 +1,15 @@ +#compdef pacfile + +declare -a args +args=( + '--check[compare database values to filesystem]' + '--config=[set an alternate configuration file]::_files' + '--dbpath=[set an alternate database location]::_files' + '(-)--help[display help information]' + '--package=[limit information to specified package(s)]:: ' + '--root=[set an alternate installation root]::_path_files -/' + '--sysroot=[set an alternate system root]::_path_files -/' + '(-)--version[display version information]' + '*:files:_files' +) +_arguments $args diff --git a/completion/zsh/_pacinfo b/completion/zsh/_pacinfo new file mode 100644 index 0000000..975be16 --- /dev/null +++ b/completion/zsh/_pacinfo @@ -0,0 +1,21 @@ +#compdef pacinfo + +declare -a args +args=( + '--cachedir=[set an alternate cache location]::_path_files -/' + '--config=[set an alternate configuration file]::_files' + '--dbext=[set an alternate sync database extension]:: ' + '--dbpath=[set an alternate database location]::_files' + '--debug[enable extra debugging messages]' + '(-)--help[display help information]' + '--no-timeout[disable low speed timeouts for downloads]' + '--null=[parse stdin as separated values (default NUL)]::sep: ' + '--raw[display raw numeric values]' + '--removable-size[include removable dependencies in size]' + '--root=[set an alternate installation root]::_path_files -/' + '--short[display brief package information]' + '--verbose[display additional package information]' + '(-)--version[display version information]' + '*:pkgspec:{_values pkgspec $(pacman -Sql)}' +) +_arguments $args diff --git a/completion/zsh/_pacini b/completion/zsh/_pacini new file mode 100644 index 0000000..9a8c6a9 --- /dev/null +++ b/completion/zsh/_pacini @@ -0,0 +1,13 @@ +#compdef pacini + +declare -a args +args=( + '(-)--help[display help information]' + '(-)--section-list[list configured sections]' + '--section=[query options for a specific section]:: ' + '--verbose[always show directive names]' + '(-)--version[display version information]' + ':file[File name]:_files' + '*:directives: ' +) +_arguments $args diff --git a/completion/zsh/_paclock b/completion/zsh/_paclock new file mode 100644 index 0000000..95a4b12 --- /dev/null +++ b/completion/zsh/_paclock @@ -0,0 +1,37 @@ +#compdef paclock + +local context state state_descr line ret=1 +typeset -A opt_args +typeset -a args +args=( + '--config=[set an alternate configuration file]::_files' + '--dbpath=[set an alternate database location]::_files' + '--enoent-ok[ignore unlock errors due to a missing lock file]' + '--fail-ok[always unlock the database following --run]' + '--key=[set the lock identity key]:: ' + '--lock[establish a new lock (default)]' + '--lockfile=[set the lock file path]::_files' + '--no-check-keys[skip check for matching lock file key before unlocking]' + '--print[print the lock file path exit]' + '--root=[set an alternate installation root]::_path_files -/' + '--run[run a command with the database locked]' + '--sysroot=[set an alternate installation system root]::_path_files -/' + '--unlock[remove an existing lock]' + '(-)--help[display help]' + '(-)--version[display version]' +) + +if [[ $words[(ie)--run] -le ${#words} ]]; then + _arguments -S $args \ + '*::arguments:->cmd' \ + && ret=0 +else + _arguments -S $args \ + && ret=0 +fi + +if [[ $state == 'cmd' ]]; then + _normal && ret=0 +fi + +return ret diff --git a/completion/zsh/_paclog b/completion/zsh/_paclog new file mode 100644 index 0000000..96ecf1b --- /dev/null +++ b/completion/zsh/_paclog @@ -0,0 +1,26 @@ +#compdef paclog + +declare -a args +args=( + + options + '(--no-color)--color[color output]' + '--config=[set an alternate configuration file]::_files' + '--debug[enable extra debugging messages]' + '--logfile=[set an alternate log file]::_files' + '(--color)--no-color[do not color output]' + '(filters)--pkglist[list installed packages (EXPERIMENTAL)]' + '--root=[set an alternate installation root]::_path_files -/' + '--sysroot=[set an alternate installation system root]::_path_files -/' + '(-)--help[show help and exit]' + '(-)--version[show version and exit]' + + filters + '*--action=[show entries]::(install reinstall upgrade downgrade remove all)' + '--after=[show entries after ]:: ' + '--before=[show entries before ]:: ' + '*--caller=[show entries from program ]:: ' + '--commandline[show command line entries]' + '*--grep=[show entries matching ]:: ' + '*--package=[show entries affecting ]::{_values package $(pacman -Sql)}' + '--warnings[show notes/warnings/errors]' +) +_arguments $args diff --git a/completion/zsh/_pacrepairdb b/completion/zsh/_pacrepairdb new file mode 100644 index 0000000..73d9cb6 --- /dev/null +++ b/completion/zsh/_pacrepairdb @@ -0,0 +1,24 @@ +#compdef pacrepairdb + +declare -a args +args=( + '--cachedir=[set an alternate cache location]::_path_files -/' + '--config=[set an alternate configuration file]::_files' + '--dbonly[update database without reinstalling packages]' + '--dbpath=[set an alternate database location]::_files' + '--debug[enable extra debugging messages]' + '(-)--help[display help information]' + '--hookdir=[add additional user hook directory]::_path_files -/' + '--logfile=[set an alternate log file]::_files' + '--no-confirm[assume default responses to all prompts]' + '--no-hooks[do not run transaction hooks]' + '--no-scriptlet[do not run package install scripts]' + '--no-timeout[disable low speed timeouts for downloads]' + '--print-only[show steps without performing them]' + '--root=[set an alternate installation root]::_path_files -/' + '--sysroot=[set an alternate system root]::_path_files -/' + '--verbose[display additional progress information]' + '(-)--version[display version information]' + '*:packages:{_values packages $(pacman -Qq)}' +) +_arguments $args diff --git a/completion/zsh/_pacrepairfile b/completion/zsh/_pacrepairfile new file mode 100644 index 0000000..5e7e8d8 --- /dev/null +++ b/completion/zsh/_pacrepairfile @@ -0,0 +1,19 @@ +#compdef pacrepairfile + +declare -a args +args=( + '--config=[set an alternate configuration file]::_files' + '--dbpath=[set an alternate database location]::_files' + '--gid[set file group id]' + '(-)--help[display help information]' + '--mode[set file permissions]' + '--mtime[set file modification time]' + '--package=[search package for file properties]::{_values package $(pacman -Qq)}' + '--quiet[do not display progress information]' + '--root=[set an alternate installation root]::_path_files -/' + '--sysroot=[set an alternate system root]::_path_files -/' + '--uid[set file owner id]' + '(-)--version[display version information]' + '*:files:_files' +) +_arguments $args diff --git a/completion/zsh/_pacreport b/completion/zsh/_pacreport new file mode 100644 index 0000000..1247213 --- /dev/null +++ b/completion/zsh/_pacreport @@ -0,0 +1,19 @@ +#compdef pacreport + +declare -a args +args=( + '--backups[list .pac{save,orig,new} files]' + '--cachedir=[set an alternate cache location]::_path_files -/' + '--config=[set an alternate pacman configuration file]::_files' + '--dbext=[set an alternate sync database extension]:: ' + '--dbpath=[set an alternate database location]::_files' + '*--group=[list missing group packages]::{_values group $(pacman -Sg)}' + '(-)--help[display help information]' + '--missing-files[list missing package files]' + '--root=[set an alternate installation root]::_path_files -/' + '--sysroot=[set an alternate system root]::_path_files -/' + '--unowned-files[list unowned files]' + '--optional-deps[take optional dependencies into account when listing unneeded packages and dependency loops]' + '(-)--version[display version information]' +) +_arguments $args diff --git a/completion/zsh/_pacsift b/completion/zsh/_pacsift new file mode 100644 index 0000000..670a335 --- /dev/null +++ b/completion/zsh/_pacsift @@ -0,0 +1,47 @@ +#compdef pacsift + +declare -a args +args=( + + options + '--any[display packages matching any search criteria]' + '--build-date=[search package build date]:: ' + '--config=[set an alternate configuration file]::_files' + '--dbext=[set an alternate sync database extension]:: ' + '--dbpath=[set an alternate database location]::_files' + '--exact[match search terms exactly]' + '(--not-exists)--exists[exit with a non-zero value if no matches were found]' + '(-)--help[display help information]' + '--invert[display packages which DO NOT match search criteria]' + '(--exists)--not-exists[exit with a non-zero value if matches were found]' + '--null=[use to separate values (default NUL)]::sep: ' + '--regex[use regular expressions for matching]' + '--root=[set an alternate installation root]::_path_files -/' + '--sysroot=[set an alternate system root]::_path_files -/' + '(-)--version[display version information]' + + filters + '--cache[search packages in cache (EXPERIMENTAL)]' + '--local[search installed packages]' + '--sync[search packages in all sync repositories]' + + package-fields + '*--architecture=[search package architecture]:: ' + '*--base=[search package bases]:: ' + '*--repo=[search packages in repo ]::{_values repo $(pacconf --repo-list)}' + '*--name=[search package names]::{_values name $(pacman -Sql)}' + '*--description=[search package descriptions]:: ' + '*--packager=[search package packager field]:: ' + '*--group=[search package group field]::{_values group $(pacman -Sg)}' + '*--owns-file=[search package file lists]::_files' + '*--license=[search package licenses]:: ' + '*--provides=[search package provides]::{_values package $(pacman -Sql)}' + '*--depends=[search package dependencies]::{_values package $(pacman -Sql)}' + '*--optdepends=[search package dependencies]::{_values package $(pacman -Sql)}' + '*--conflicts=[search package conflicts]:: ' + '*--replaces=[search package replaces]::{_values package $(pacman -Sql)}' + '*--install-date=[search package install date]:: ' + '*--installed-size=[search package installed size]:: ' + '*--download-size=[search package download size]:: ' + '*--size=[search package size]:: ' + '*--url=[search package url]:: ' + '*--satisfies=[find packages satisfying dependency ]:: ' +) +_arguments $args diff --git a/completion/zsh/_pacsync b/completion/zsh/_pacsync new file mode 100644 index 0000000..7d7a93f --- /dev/null +++ b/completion/zsh/_pacsync @@ -0,0 +1,18 @@ +#compdef pacsync + +declare -a args +args=( + '--config=[set an alternate configuration file]::_files' + '--dbext=[set an alternate sync database extension]:: ' + '--dbpath=[set an alternate database location]::_files' + '--debug[enable extra debugging messages]' + '--force[sync repos even if already up-to-date]' + '(-)--help[display help information]' + '--logfile=[set an alternate log file]::_files' + '--no-timeout[disable low speed timeouts for downloads]' + '--sysroot=[set an alternate system root]::_path_files -/' + '--updated[return false unless a database was updated]' + '(-)--version[display version information]' + '*:repo:{_values repo $(pacconf --repo-list)}' +) +_arguments $args diff --git a/completion/zsh/_pactrans b/completion/zsh/_pactrans new file mode 100644 index 0000000..3de643c --- /dev/null +++ b/completion/zsh/_pactrans @@ -0,0 +1,95 @@ +#compdef pactrans pacinstall pacremove + +typeset -a args + +args=( + + actions + '--spec[install sync/file specs, remove local specs (default)]' + '--install[install packages from sync database]' + '--remove[remove packages]' + '--file[install packages from files]' + '--sysupgrade[upgrade installed packages]' + + + options + '--cachedir=[set an alternate cache location]::_path_files -/' + '--config=[set an alternate configuration file]::_files' + '--dbonly[make the requested changes only to the database]' + '--dbpath=[set an alternate database location]::_files' + '--dbsync[update sync databases prior to the transaction]' + '--dbext=[set an alternate sync database extension]:: ' + '--debug[enable extra debugging messages]' + '--no-timeout[disable low speed timeouts for downloads]' + '--hookdir=[add additional user hook directory]::_path_files -/' + '--logfile=[set an alternate log file]::_files' + '--print-only[display transaction information and exit]' + '--no-confirm[assume default responses to all prompts]' + '--no-deps[ignore dependency version restrictions]' + '--no-hooks[do not run transaction hooks]' + '--assume-installed=[behave as if package is installed]:package:{_values package $(pacman -Sql)' + '--no-scriptlet[do not run package install scripts]' + '--null=[parse stdin as separated values (default NUL)]::sep: ' + '--root=[set an alternate installation root]::_path_files -/' + '--sysroot=[set an alternate system root]::_path_files -/' + '(-)--help[display help information]' + '(-)--version[display version information]' + + + sysupgrade_options + '--ignore-group=[ignore upgrades for packages in group ]::{_values group $(pacman -Sg)}' + '--ignore-pkg=[ignore upgrades for ]::{_values package $(pacman -Qq)}' + + + install_file_options + '--as-deps[install packages as dependencies]' + '--as-explicit[install packages as explicit]' + '--download-only[download packages without installing]' + + + remove_options + '--cascade[remove packages that depend on removed packages]' + '--no-backup[do not save configuration file backups]' + '--recursive[remove unneeded dependencies of removed packages]' + '--unneeded[only remove packages that are unneeded]' + + + prompt_options + '--delete-corrupt-files=[enable/disable deletion of corrupt package archives]:value:(prompt yes no)' + '--import-pgp-keys=[enable/disable automatic importing of missing PGP keys]:value:(prompt yes no)' + '--install-ignored-packages=[enable/disable installation of ignored packages]:value:(prompt yes no)' + '--resolve-conflicts=[method to use for resolving conflicts-]::(prompt none all provided depends provided-depends)' + '--resolve-replacements=[method to use for resolving package replacements-]::(prompt none all provided depends provided-depends)' + '--skip-unresolvable=[enable/disable skipping packages with missing dependencies]:value:(prompt yes no)' + '--use-first-provider=[enable/disable automatic provider selection]:value:(prompt yes no)' + '(--no-confirm prompt_options)--yolo[set all prompt disposition options to all/yes and set --no-confirm]' + + + positional +) + +declare -a spec_alts +spec_alts=( + 'sync:package:{_values package $(pacman -Sql)}' + 'files:files:_files' +) +local spec_comp='*:spec:{_alternative $spec_alts}' +local install_comp='*:package:{_values package $(pacman -Sql)}' +local remove_comp='*:package:{_values package $(pacman -Qq)}' + +# Detect what type of positional arguments we are currently completing (if any) +local mode word + +case $service in + pactrans) mode=$spec_comp ;; + pacinstall) mode=$install_comp ;; + pacremove) mode=$remove_comp ;; +esac + +for word in $words[1,$CURRENT]; do + case $word in + --spec) mode=$spec_comp ;; + --install) mode=$install_comp ;; + --remove) mode=$remove_comp ;; + --file) mode='*:files:_files' ;; + esac +done + +if [[ -n $mode ]]; then + _arguments $args $mode +else + _arguments $args +fi