Improve _apk and add _sendirc

This commit is contained in:
Alex D. 2020-11-18 15:27:20 +00:00
parent 7e9cfbc00f
commit ccc2069165
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 157 additions and 136 deletions

273
_apk
View File

@ -1,4 +1,4 @@
#compdef _apk apk
#compdef apk
function _apk {
@ -42,164 +42,165 @@ function _apk {
"--initramfs-diskless-boot[Enables selected force options, disables commit hooks and more]"
)
local -a cmds=(
"add:Add packages to world and commit changes"
"del:Remove packages from world and commit changes"
"fix:Fix, reinstall or upgrade packages without modifying world"
"update:Update repository indexes"
"upgrade:Install upgrades available from repositories"
"cache:Manage the local package cache"
"info:Give detailed information about packages or repositories"
"list:List packages matching a pattern or other criteria"
"dot:Render dependencies as graphviz graphs"
"policy:Show repository policy for packages"
"index:Create repository index file from packages"
"fetch:Download packages from global repositories to a local directory"
"manifest:Show checksums of package contents"
"verify:Verify package integrity and signature"
"audit:Audit system for changes"
"stats:Show statistics about repositories and installations"
"version:Compare package versions or perform tests on version strings"
)
local -a cache_subcmds=(
"clean:Remove package files which are no longer necessary"
"download:Fetch package files from the repositories and store them in the cache"
"sync:Clean and Download"
)
local -a latest_opt=("(-l --latest)"{-l,--latest}"[Always choose the latest package by version]")
local -a upgrade_opt=("(-u --upgrade)"{-u,--upgrade}"[Upgrade packages and it's dependencies]")
local -a add_args=(
$global_opts \
$commit_opts \
$latest_opt \
$upgrade_opt \
"--initdb[Initialize a new package database]" \
"(-t --vitual)"{-t,--vitual}"[Create virtual package with given dependencies]" \
"*::package:_apk_packages"
)
local -a del_args=(
$global_opts \
$commit_opts \
"--rdepeds[Recursively delete all top-level reverse dependencies]" \
"*::package:_apk_packages"
)
local -a fix_args=(
$global_opts \
$commit_opts \
"(-d --depends)"{-d,--depends}"[Fix dependencies of specified packages]" \
"(-r --reinstall)"{-r,--reinstall}"[Reinstall packages]" \
"(-u --upgrade)"{-u,--upgrade}"[Upgrade if an upgrade is available and does not break dependencies]" \
"(-x --xattr)"{-x,--xattr}"[Fix packages with broken xattrs]" \
"--directory-permissions[Reset all directory permissions]" \
"*::package:_apk_packages"
)
local -a update_args=($global_opts $commit_opts)
local -a upgrade_args=(
$global_opts \
$commit_opts \
$latest_opt \
"(-a --available)"{-a,--available}"[Reset all packages to versions available from current repositories]" \
"--ignore[Upgrade all other packages than the ones listed]" \
"--no-self-upgrade[Do not do an early upgrade of the 'apk-tools' package]" \
"--prune[Remove packages which are no longer available from any configured repository]" \
"--self-upgrade-only[Only perform a self-upgrade of the 'apk-tools' package]" \
"*::package:_apk_packages"
)
local -a cache_args=(
$global_opts \
$latest_opt \
$upgrade_opt \
':subcommand:_apk_cache'
)
local -a info_args=(
$global_opts \
"(-a --all)"{-a,--all}"[List all information known about the package]" \
"(-d --description)"{-d,--descripton}"[Print the package description]" \
"(-e --installed)"{-e,--installed}"[Check package installed status]" \
"(-L --contents)"{-L,--contents}"[List files included in the package]" \
"(-i --install-if)"{-i,--install-if}"[List the package's install_if rule]" \
"(-I --rinstall-if)"{-I,--rinstall-if}"[List other packages whose install_if rules refer to this package]" \
"(-r --rdepends)"{-r,--rdepends}"[List reverse dependencies of the package]" \
"(-R --depends)"{-R,--depends}"[List the dependencies of the package]" \
"(-s --size)"{-s,--size}"[Print the package's installed size]" \
"(-w --webpage)"{-w,--webpage}"[Print the URL for the package's upstream webpage]" \
"(-W --who-owns)"{-W,--who-owns}"[Print the package which owns the specified file]:file:_files" \
"--license[Print the package SPDX license identifier]" \
"--replaces[List the other packages for which this package is marked as a replacement]" \
"--triggers[Print active triggers for the package]" \
"*::package:_apk_packages"
)
local -a list_args=(
$global_opts \
"(-I --installed)"{-I,--installed}"[Consider only installed packages]" \
"(-O --orphaned)"{-O,--orphaned}"[Consider only orphaned packages]" \
"(-a --available)"{-a,--available}"[Consider only available packages]" \
"(-u --upgradeable)"{-u,--upgradeable}"[Consider only upgradable packages]" \
"(-o --origin)"{-o,--origin}"[List packages by origin]" \
"(-d --depends)"{-d,--depends}"[List packages by dependency]" \
"(-P --providers)"{-P,--providers}"[List packages by provider]" \
"*::pattern"
)
local -a dot_args=(
$global_opts \
"--errors[Consider only packages with errors]" \
"--installed[Consider only installed packages]"
)
local -a policy_args=($global_opts)
local -a index_args=(
$global_opts \
"(-d --description)"{-d,--description}"[Add a description to the index]:description" \
"(-o --output)"{-o,--output}"[Output generated index to file]:output:_files" \
"(-x --index)"{-x,--index}"[Read an existing index to speed up the creation of the new index]" \
"--no-warnings[Disable warnings about missing dependencies]" \
"*::package:_apk_packages"
)
local -a fetch_args=(
$global_opts \
"(-l --link)"{-l,--link}"[Create hard links if possible]" \
"(-o --output)"{-o,--output}"[Where to write the downloaded files]:directory:_dir_list" \
"(-r --recursive)"{-r,--recursive}"[Fetch packages and all of their dependencies]" \
"(-s --stdout)"{-s,--stdout}"[Dump the .apk file(s) to stdout]" \
"--simulate[Simulate the requested operation without making any changes]" \
"*::package:_apk_packages"
)
local -a manifest_args=($global_opts "*::package:_apk_packages")
local -a verify_args=($global_opts "*::package:_apk_packages")
local -a audit_args=($global_opts "*::files:_files")
local -a stats_args=($global_opts)
local -a version_args=(
$global_opts \
"-a[Consider packages from all repository tags]" \
"-l[Limit to packages with output matching given operand]:operand" \
"*::package:_apk_packages"
)
local context state state_descr line
typeset -A opt_args
local curcontext="$curcontext"
local ret=1
function _apk_packages {
function _apk_repopkgs {
local -a packs
if _cache_invalid cached_packs || ! _retrieve_cache cached_packs; then
packs=(${$(/sbin/apk search)%-[[:digit:].]##-r[[:digit:]]##})
packs=(${$(/sbin/apk search)%-[[:digit:][:lower:]._]##-r[[:digit:]]##})
_store_cache cached_packs packs
fi
compadd -a packs
_describe 'index packages' packs
}
function _apk_packages {
_alternative 'repo:index packages:_apk_repopkgs' 'localpkgs:local packages:_files -g "*.apk"'
}
function _apk_cache {
local -a cache_subcmds=(
"clean:Remove package files which are no longer necessary"
"download:Fetch package files from the repositories and store them in the cache"
"sync:Clean and Download"
)
_describe 'subcommand' cache_subcmds
}
function _apk_subcmds {
local -a cmds=(
"add:Add packages to world and commit changes"
"del:Remove packages from world and commit changes"
"fix:Fix, reinstall or upgrade packages without modifying world"
"update:Update repository indexes"
"upgrade:Install upgrades available from repositories"
"cache:Manage the local package cache"
"info:Give detailed information about packages or repositories"
"list:List packages matching a pattern or other criteria"
"dot:Render dependencies as graphviz graphs"
"policy:Show repository policy for packages"
"index:Create repository index file from packages"
"fetch:Download packages from global repositories to a local directory"
"manifest:Show checksums of package contents"
"verify:Verify package integrity and signature"
"audit:Audit system for changes"
"stats:Show statistics about repositories and installations"
"version:Compare package versions or perform tests on version strings"
)
_describe 'subcommand' cmds
}
function _apk_subcmd_args {
local -a add_args=(
$global_opts \
$commit_opts \
$latest_opt \
$upgrade_opt \
"--initdb[Initialize a new package database]" \
"(-t --virtual)"{-t,--virtual}"[Create virtual package with given dependencies]" \
"*::package:_apk_packages"
)
local -a del_args=(
$global_opts \
$commit_opts \
"--rdepeds[Recursively delete all top-level reverse dependencies]" \
"*::package:_apk_packages"
)
local -a fix_args=(
$global_opts \
$commit_opts \
"(-d --depends)"{-d,--depends}"[Fix dependencies of specified packages]" \
"(-r --reinstall)"{-r,--reinstall}"[Reinstall packages]" \
"(-u --upgrade)"{-u,--upgrade}"[Upgrade if an upgrade is available and does not break dependencies]" \
"(-x --xattr)"{-x,--xattr}"[Fix packages with broken xattrs]" \
"--directory-permissions[Reset all directory permissions]" \
"*::package:_apk_packages"
)
local -a update_args=($global_opts $commit_opts)
local -a upgrade_args=(
$global_opts \
$commit_opts \
$latest_opt \
"(-a --available)"{-a,--available}"[Reset all packages to versions available from current repositories]" \
"--ignore[Upgrade all other packages than the ones listed]" \
"--no-self-upgrade[Do not do an early upgrade of the 'apk-tools' package]" \
"--prune[Remove packages which are no longer available from any configured repository]" \
"--self-upgrade-only[Only perform a self-upgrade of the 'apk-tools' package]" \
"*::package:_apk_packages"
)
local -a cache_args=(
$global_opts \
$latest_opt \
$upgrade_opt \
':subcommand:_apk_cache'
)
local -a info_args=(
$global_opts \
"(-a --all)"{-a,--all}"[List all information known about the package]" \
"(-d --description)"{-d,--descripton}"[Print the package description]" \
"(-e --installed)"{-e,--installed}"[Check package installed status]" \
"(-L --contents)"{-L,--contents}"[List files included in the package]" \
"(-i --install-if)"{-i,--install-if}"[List the package's install_if rule]" \
"(-I --rinstall-if)"{-I,--rinstall-if}"[List other packages whose install_if rules refer to this package]" \
"(-r --rdepends)"{-r,--rdepends}"[List reverse dependencies of the package]" \
"(-R --depends)"{-R,--depends}"[List the dependencies of the package]" \
"(-s --size)"{-s,--size}"[Print the package's installed size]" \
"(-w --webpage)"{-w,--webpage}"[Print the URL for the package's upstream webpage]" \
"(-W --who-owns)"{-W,--who-owns}"[Print the package which owns the specified file]:file:_files" \
"--license[Print the package SPDX license identifier]" \
"--replaces[List the other packages for which this package is marked as a replacement]" \
"--triggers[Print active triggers for the package]" \
"*::package:_apk_packages"
)
local -a list_args=(
$global_opts \
"(-I --installed)"{-I,--installed}"[Consider only installed packages]" \
"(-O --orphaned)"{-O,--orphaned}"[Consider only orphaned packages]" \
"(-a --available)"{-a,--available}"[Consider only available packages]" \
"(-u --upgradeable)"{-u,--upgradeable}"[Consider only upgradable packages]" \
"(-o --origin)"{-o,--origin}"[List packages by origin]" \
"(-d --depends)"{-d,--depends}"[List packages by dependency]" \
"(-P --providers)"{-P,--providers}"[List packages by provider]" \
"*::pattern"
)
local -a dot_args=(
$global_opts \
"--errors[Consider only packages with errors]" \
"--installed[Consider only installed packages]"
)
local -a policy_args=($global_opts)
local -a index_args=(
$global_opts \
"(-d --description)"{-d,--description}"[Add a description to the index]:description" \
"(-o --output)"{-o,--output}"[Output generated index to file]:output:_files" \
"(-x --index)"{-x,--index}"[Read an existing index to speed up the creation of the new index]" \
"--no-warnings[Disable warnings about missing dependencies]" \
"*::package:_apk_packages"
)
local -a fetch_args=(
$global_opts \
"(-l --link)"{-l,--link}"[Create hard links if possible]" \
"(-o --output)"{-o,--output}"[Where to write the downloaded files]:directory:_dir_list" \
"(-r --recursive)"{-r,--recursive}"[Fetch packages and all of their dependencies]" \
"(-s --stdout)"{-s,--stdout}"[Dump the .apk file(s) to stdout]" \
"--simulate[Simulate the requested operation without making any changes]" \
"*::package:_apk_packages"
)
local -a manifest_args=($global_opts "*::package:_apk_packages")
local -a verify_args=($global_opts "*::package:_apk_packages")
local -a audit_args=($global_opts "*::files:_files")
local -a stats_args=($global_opts)
local -a version_args=(
$global_opts \
"-a[Consider packages from all repository tags]" \
"-l[Limit to packages with output matching given operand]:operand" \
"*::package:_apk_packages"
)
local cmdvar="${words[1]}_args"
_arguments -s -C ${(P)cmdvar} && ret=0
}

20
_sendirc Normal file
View File

@ -0,0 +1,20 @@
#compdef sendirc
function _sendirc {
function _sendircserv {
local -a servs=(~/IRC/*/global/in(p))
servs=(${${servs%%\/global\/in}##*/})
compadd -a servs
}
function _sendircbuf {
local -a chans=(~/IRC/${words[2]}/{channel,user}/*(/))
chans=(${chans##*/})
compadd -a chans
}
_arguments -C -s \
':server:_sendircserv' \
':buffer:_sendircbuf' \
'*::message'
}