From dbbe7794ef50b93ce78fa07efa146dcf26e231fc Mon Sep 17 00:00:00 2001 From: dana Date: Thu, 7 Jun 2018 14:52:56 -0500 Subject: 42948: new opkg completion --- Completion/Linux/Command/_opkg | 462 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 462 insertions(+) create mode 100644 Completion/Linux/Command/_opkg (limited to 'Completion/Linux') diff --git a/Completion/Linux/Command/_opkg b/Completion/Linux/Command/_opkg new file mode 100644 index 000000000..5feadc11a --- /dev/null +++ b/Completion/Linux/Command/_opkg @@ -0,0 +1,462 @@ +#compdef opkg ipkg + +# Notes: +# +# - This function has been designed with opkg in mind, but much of it should +# also work with ipkg. +# +# - Caching doesn't appear to save a HUGE amount of time given the scale of most +# opkg repos (compared to e.g. APT) and the resources available to the devices +# that use them. +# +# - _opkg_pkg_* functions can be called with --update to update their respective +# cache files without actually completing. +# +# - Lots of code redundancy here (@todo). +# +# Notable styles supported: +# +# % zstyle ':completion:*:opkg:*' use-cache +# Set to yes to enable caching of package names. Usually disabled by default. +# +# % zstyle ':completion:*:opkg:*' cache-path +# Set to a directory path to override the default cache-file directory. +# +# % zstyle ':completion:*:opkg:*' cache-persists +# Set to yes to keep cache data in memory for the remainder of the shell +# session. Most completion functions do this always, but opkg tends to be used +# on fairly resource-constrained devices, so it's disabled by default here. +# +# % zstyle ':completion:*:opkg:*' status-paths ... +# Set to one or more paths or glob patterns to override the defaults used when +# checking cache validity. If any of the specified files has been modified +# more recently than the cache, the cache is considered invalid. +# +# % zstyle ':completion:*:opkg:*' conf-paths ... +# Set to one or more paths or glob patterns to override the defaults used when +# searching opkg configuration data. + +## +# Check cache validity. +__opkg_cache_policy() { + local -a tmp + + # Always invalidate if it's been over a week + tmp=( $1(#qmw+1N) ) + (( $#tmp )) && return 0 + + zstyle -a ":completion:$curcontext:" status-paths tmp + + if (( $#tmp )); then + tmp=( $~tmp(#qN) ) + else + tmp=( + {/opt,/usr,/var}/lib/{i,o}pkg/status(#q-.N) + {/opt,/usr,/var}/lib/{i,o}pkg/lists/packages(#q-.N) + /opt/var/opkg-lists/packages(#q-.N) + ) + fi + + # Always invalidate if we found no status files + (( $#tmp )) || return 0 + + # Invalidate if any status file is newer than the cache file + for 2 in $tmp; do + [[ $2 -nt $1 ]] && return 0 + done + + return 1 +} + +## +# Search opkg config files. +__opkg_grep_conf() { + local -aU tmp + + zstyle -a ":completion:$curcontext:" conf-paths tmp + + if (( $#tmp )); then + tmp=( $~tmp(#qN) ) + else + tmp=( + {,/opt}/etc/{i,o}pkg*.conf(#q-.N) + {,/opt}/etc/{i,o}pkg/*.conf(#q-.N) + ) + fi + + (( $#tmp )) || return 1 + + GREP_OPTIONS= command grep -sE "$@" $tmp +} + +## +# Complete architecture/priority pair. +# +# Architecture names are essentially arbitrary (up to the packager), so we can't +# really complete every possibility here — but we'll account for most of the +# popular ones. +_opkg_arch_prio() { + local -a copts=( "$@" ) + local -aU tmp + + [[ -prefix *: ]] && { + _message priority + return + } + + # Already configured arches + tmp=( ${(f)"$( _call_program architectures $svc print-architecture )"} ) + tmp=( ${${tmp##arch[ ]##}%% *} ) + + tmp+=( + # 'Meta' arches + all any noarch + # Arches supported by entware-ng + armv5soft armv7soft mipselsf x86-32 x86-64 + # Arches mentioned in the optware-ng source + arm armeb fsg3be hpmv2 i686 ixp4xxbe ixp4xxle mssii nslu2 powerpc qemux86 + slugosbe slugosle + # Arches mentioned in the Ångström distribution's narcissus source + a7