__fish_print_packages: Extract the rest

Of note: The rpm/yum thing seems to be coupled, so I put it into one
function that tries the yum helper and uses the rpm path otherwise.
Zypper is already its own thing, so this should only be used for yum
and probably dnf (does that still have the helper?)

Zypper can be dropped, as that already used a separate function in the file.

Apk can just be inlined - it's literally one line for installed and another for all packages.
This commit is contained in:
Fabian Homborg 2020-09-22 19:24:04 +02:00
parent cf59c3b680
commit 04d7d89020
42 changed files with 235 additions and 264 deletions

View file

@ -1,8 +1,8 @@
# Completions for apk (Alpine Package Keeper)
# Package name
complete -f -c apk -n "__fish_seen_subcommand_from add info fetch dot" -a "(__fish_print_packages)" -d Package
complete -f -c apk -n "__fish_seen_subcommand_from del fix version manifest" -a "(__fish_print_packages --installed)" -d Package
complete -f -c apk -n "__fish_seen_subcommand_from add info fetch dot" -a "(apk search -q)" -d Package
complete -f -c apk -n "__fish_seen_subcommand_from del fix version manifest" -a "(apk info -q)" -d Package
# Global options
complete -f -c apk -s h -l help -d "Show help"

View file

@ -38,4 +38,4 @@ function __fish_apt-cache_use_package -d 'Test if apt command should have packag
return 1
end
complete -c apt-cache -n __fish_apt-cache_use_package -a '(__fish_print_packages)' -d Package
complete -c apt-cache -n __fish_apt-cache_use_package -a '(__fish_print_apt_packages)' -d Package

View file

@ -18,7 +18,7 @@ function __fish_apt_use_package -d 'Test if apt command should have packages as
return 1
end
complete -c apt-get -n __fish_apt_use_package -a '(__fish_print_packages)' -d Package
complete -c apt-get -n __fish_apt_use_package -a '(__fish_print_apt_packages)' -d Package
complete -c apt-get -s h -l help -d 'Display help and exit'
complete -f -n __fish_apt_no_subcommand -c apt-get -a update -d 'Update sources'

View file

@ -18,7 +18,7 @@ function __fish_apt_use_package -d 'Test if apt command should have packages as
return 1
end
complete -c apt-mark -n __fish_apt_use_package -a '(__fish_print_packages)' -d Package
complete -c apt-mark -n __fish_apt_use_package -a '(__fish_print_apt_packages)' -d Package
complete -c apt-mark -s h -l help -d 'Display help and exit'
complete -f -n __fish_apt_no_subcommand -c apt-mark -a auto -d 'Mark a package as automatically installed'

View file

@ -27,8 +27,8 @@ end
complete -c apt -f
complete -k -c apt -n "__fish_seen_subcommand_from $pkg_subcmds" -a '(__fish_print_packages | head -n 250 | sort)'
complete -c apt -n "__fish_seen_subcommand_from $installed_pkg_subcmds" -a '(__fish_print_packages --installed | string match -re -- "(?:\\b|_)"(commandline -ct | string escape --style=regex) | head -n 250)' -d Package
complete -k -c apt -n "__fish_seen_subcommand_from $pkg_subcmds" -a '(__fish_print_apt_packages | head -n 250 | sort)'
complete -c apt -n "__fish_seen_subcommand_from $installed_pkg_subcmds" -a '(__fish_print_apt_packages --installed | string match -re -- "(?:\\b|_)"(commandline -ct | string escape --style=regex) | head -n 250)' -d Package
complete -k -c apt -n "__fish_seen_subcommand_from $handle_file_pkg_subcmds" -a '(__fish_complete_suffix .deb)'
complete -c apt -n "__fish_seen_subcommand_from install" -l no-install-recommends

View file

@ -18,7 +18,7 @@ function __fish_apt_use_package -d 'Test if aptitude command should have package
return 1
end
complete -c aptitude -n __fish_apt_use_package -a '(__fish_print_packages)' -d Package
complete -c aptitude -n __fish_apt_use_package -a '(__fish_print_apt_packages)' -d Package
complete -c aptitude -s h -l help -d 'Display a brief help message. Identical to the help action'
complete -f -n __fish_apt_no_subcommand -c aptitude -a autoclean -d 'Remove any cached packages which can no longer be downloaded'

View file

@ -1,7 +1,7 @@
# This can't currently be wrapped as the pacman completions rely on variables whose value this needs to change
# complete -c aura -w pacman
set -l listinstalled "(pacman -Q | tr ' ' \t)"
set -l listall "(__fish_print_packages)"
set -l listall "(__fish_print_pacman_packages)"
set -l listrepos "(__fish_print_pacman_repos)"
set -l listgroups "(pacman -Sg | sed 's/\(.*\)/\1\tPackage group/g')"

View file

@ -1,5 +1,5 @@
complete -c dlocate -s S -x -d 'List records that match filenames'
complete -c dlocate -s L -d 'List all files in the package' -xa '(__fish_print_packages)'
complete -c dlocate -o ls -d 'ls -ldF all files in the package' -xa '(__fish_print_packages)'
complete -c dlocate -o du -d 'du -sck all files in the package' -xa '(__fish_print_packages)'
complete -c dlocate -s L -d 'List all files in the package' -xa '(__fish_print_apt_packages)'
complete -c dlocate -o ls -d 'ls -ldF all files in the package' -xa '(__fish_print_apt_packages)'
complete -c dlocate -o du -d 'du -sck all files in the package' -xa '(__fish_print_apt_packages)'

View file

@ -1,3 +1,3 @@
# Arch Linux package downgrader tool
complete -c downgrade -f
complete -c downgrade -xa "(__fish_print_packages --installed)"
complete -c downgrade -xa "(__fish_print_pacman_packages --installed)"

View file

@ -1,6 +1,6 @@
# Completions for the `dpkg-reconfigure` command
complete -f -c dpkg-reconfigure -a '(__fish_print_packages)' -d Package
complete -f -c dpkg-reconfigure -a '(__fish_print_apt_packages)' -d Package
# Support flags
complete -x -f -c dpkg-reconfigure -s h -l help -d 'Display help'

View file

@ -33,8 +33,8 @@ function __fish_eopkg_print_repos -d "Print list of repositories"
end
complete -f -c eopkg -n '__fish_seen_subcommand_from remove-repo rr enable-repo er disable-repo dr list-available la' -a "(__fish_eopkg_print_repos)" -d Repository
complete -f -c eopkg -n '__fish_seen_subcommand_from upgrade up install it info' -a "(__fish_print_packages)" -d "Available Package"
complete -f -c eopkg -n '__fish_seen_subcommand_from remove rm autoremove rmf check' -a "(__fish_print_packages --installed)" -d "Installed package"
complete -f -c eopkg -n '__fish_seen_subcommand_from upgrade up install it info' -a "(__fish_print_eopkg_packages)" -d "Available Package"
complete -f -c eopkg -n '__fish_seen_subcommand_from remove rm autoremove rmf check' -a "(__fish_print_eopkg_packages --installed)" -d "Installed package"
complete -f -c eopkg -n '__fish_seen_subcommand_from upgrade up remove rm install it info check list-available la list-installed li list-upgrades lu' -s c -l component -a "(__fish_eopkg_print_components)" -d Component
## Upgrade

View file

@ -27,9 +27,9 @@ function __fish_opkg_use_package_installed -d 'Test if opkg command should have
return 1
end
complete -c opkg -n __fish_opkg_use_package -a '(__fish_print_packages)' -d Package
complete -c opkg -n __fish_opkg_use_package -a '(__fish_print_opkg_packages)' -d Package
complete -c opkg -n __fish_opkg_use_package_installed -a '(__fish_print_packages --installed)' -d Package
complete -c opkg -n __fish_opkg_use_package_installed -a '(__fish_print_opkg_packages --installed)' -d Package
complete -f -n __fish_opkg_no_subcommand -c opkg -a update -d 'Update list of available packages'
complete -f -n __fish_opkg_no_subcommand -c opkg -a upgrade -d 'Upgrade packages'

View file

@ -1,9 +1,9 @@
set -l progname pacaur
complete -c $progname -f
set -l listinstalled "(__fish_print_packages --installed)"
set -l listinstalled "(__fish_print_pacman_packages --installed)"
# This might be an issue if another package manager is also installed (e.g. for containers)
set -l listall "(__fish_print_packages)"
set -l listall "(__fish_print_pacman_packages)"
set -l listrepos "(__fish_print_pacman_repos)"
set -l listgroups "(pacman -Sg)\t'Package Group'"

View file

@ -4,9 +4,9 @@
set -l progname pacman
set -l listinstalled "(__fish_print_packages --installed)"
set -l listinstalled "(__fish_print_pacman_packages --installed)"
# This might be an issue if another package manager is also installed (e.g. for containers)
set -l listall "(__fish_print_packages)"
set -l listall "(__fish_print_pacman_packages)"
set -l listrepos "(__fish_print_pacman_repos)"
set -l listgroups "(pacman -Sg)\t'Package Group'"

View file

@ -1,3 +1,3 @@
complete -c pkg_delete -a '(__fish_print_packages)' -d Package
complete -c pkg_delete -a '(__fish_print_pkg_add_packages)' -d Package
complete -c pkg_delete -o a -d 'Delete unused deps'
complete -c pkg_delete -o V -d 'Turn on stats'

View file

@ -1 +1 @@
complete -c pkg_info -a '(__fish_print_packages)' -d Package
complete -c pkg_info -a '(__fish_print_pkg_add_packages)' -d Package

View file

@ -8,7 +8,7 @@ set -l subcommands activate archive build cat cd checksum clean configure \
selfupdate setrequested setunrequested sync test unarchive uninstall \
unload unsetrequested upgrade url usage variants version work
complete -c port -n "__fish_seen_subcommand_from $subcommands" -a '(__fish_print_packages)' -d Package
complete -c port -n "__fish_seen_subcommand_from $subcommands" -a '(__fish_print_port_packages)' -d Package
complete -f -n "__fish_use_subcommand $subcommands" -c port -a activate -d 'Set version of a port to active'
complete -f -n "__fish_use_subcommand $subcommands" -c port -a archive -d "Create image for port without installing"

View file

@ -51,4 +51,4 @@ complete -c portmaster -f -d 'Ports Directory' -a "
string match -r '(?<=/usr/ports/)[^/]*(?:/[^/]*)?' (__fish_complete_directories /usr/ports/(commandline -ct))
)"
complete -c portmaster -f -d 'Installed package' -a "(__fish_print_packages)"
complete -c portmaster -f -d 'Installed package' -a "(__fish_print_port_packages)"

View file

@ -71,7 +71,7 @@ complete $rpm_query -l triggers -d 'Display the trigger scripts contained in the
complete $rpm_query -l triggerscripts -d 'Display the trigger scripts contained in the package'
set -l rpm_select -c rpm -n "__fish_contains_opt -s q -s V query verify"
complete $rpm_select -a "(__fish_print_packages)"
complete $rpm_select -a "(__fish_print_rpm_packages)"
complete $rpm_select -s a -l all -d 'Query all installed packages'
complete $rpm_select -s f -l file -d 'Query package owning specified file' -rF
complete $rpm_select -l fileid -d 'Query package that contains a given file identifier, i.e. the MD5 digest of the file contents' -x
@ -81,7 +81,7 @@ complete $rpm_select -s p -l package -d 'Query an (uninstalled) package in speci
complete $rpm_select -l pkgid -d 'Query package that contains a given package identifier, i.e. the MD5 digest of the combined header and payload contents' -x
complete $rpm_select -l specfile -d 'Parse and query specified spec-file as if it were a package' -xa "(__fish_complete_suffix .spec)"
complete $rpm_select -l tid -d 'Query package(s) that have the specified TID (transaction identifier)' -x
complete $rpm_select -l triggeredby -d 'Query packages that are triggered by the specified packages' -x -a "(__fish_print_packages)"
complete $rpm_select -l triggeredby -d 'Query packages that are triggered by the specified packages' -x -a "(__fish_print_rpm_packages)"
complete $rpm_select -l whatprovides -d 'Query all packages that provide the specified capability' -x
complete $rpm_select -l whatrequires -d 'Query all packages that requires the specified capability for functioning' -x
@ -101,7 +101,7 @@ complete $rpm_verify -l nomode -d "Don't verify mode attribute"
complete $rpm_verify -l nordev -d "Don't verify dev attribute"
set -l rpm_erase -c rpm -n "__fish_contains_opt -s e erase"
complete $rpm_erase -a "(__fish_print_packages)"
complete $rpm_erase -a "(__fish_print_rpm_packages)"
complete $rpm_erase -l allmatches -d 'Remove all versions of the package which match specified string'
complete $rpm_erase -l nodeps -d "Don't check dependencies before uninstalling the packages"
complete $rpm_erase -l noscripts -d "Don't execute scriplets"

View file

@ -110,9 +110,6 @@ function __fish_snap_filters -d 'List assertion filters'
snap known $argv[1] | string match -v 'type:*' | string match '*: *' | string replace -r '(.*): (.*)' '$1=$2'
end
# Enable when __fish_print_packages supports snaps
#complete -c snap -n '__fish_snap_use_package' -a '(__fish_print_packages)' -d 'Package'
# Enable file completions where appropriate
complete -c snap -n __fish_snap_use_file -a '(__fish_complete_path)'

View file

@ -35,7 +35,7 @@ function __fish_wajig_use_package -d 'Test if wajig command should have packages
return 1
end
complete -c wajig -n __fish_wajig_use_package -a '(__fish_print_packages)' -d Packageh
complete -c wajig -n __fish_wajig_use_package -a '(__fish_print_apt_packages)' -d Packages
complete -c wajig -s q -l quiet -d 'Do system commands everything quietly.'
complete -c wajig -s n -l noauth -d 'Allow packages from unathenticated archives.'
complete -c wajig -s s -l simulate -d 'Trace but don\'t execute the sequence of underlying commands.'

View file

@ -3,7 +3,7 @@
set -l progname xbps-alternatives
set -l listinstalled "(__fish_print_packages -i)"
set -l listinstalled "(__fish_print_xbps_packages -i)"
complete -c $progname -f
complete -c $progname -a "$listinstalled"

View file

@ -4,8 +4,8 @@
set -l progname xbps-dgraph
complete -c $progname -f
complete -c $progname -a "(__fish_print_packages -i)"
complete -c $progname -n "__fish_contains_opt -s R" -a "(__fish_print_packages)"
complete -c $progname -a "(__fish_print_xbps_packages -i)"
complete -c $progname -n "__fish_contains_opt -s R" -a "(__fish_print_xbps_packages)"
complete -c $progname -s C -d 'Specifies a path to the XBPS configuration directory.' -xa "(__fish_complete_directories)"
complete -c $progname -s c -d 'Specifies a path to the graph configuration file.' -F

View file

@ -3,7 +3,7 @@
set -l progname xbps-fbulk
complete -c $progname -f -a "(__fish_complete_directories) (__fish_print_packages)"
complete -c $progname -f -a "(__fish_complete_directories) (__fish_print_xbps_packages)"
complete -c $progname -s a -d 'Set a different target architecture, useful for cross compiling.' -x
complete -c $progname -s j -d 'Set number of parallel builds running at the same time. By default set to 1.' -x

View file

@ -3,7 +3,7 @@
set -l progname xbps-install
set -l listall "(__fish_print_packages)"
set -l listall "(__fish_print_xbps_packages)"
complete -c $progname -f
complete -c $progname -a "$listall"

View file

@ -11,7 +11,7 @@ complete -c $progname -s C -d 'Specifies a path to the XBPS configuration direct
complete -c $progname -s d -d 'Enables extra debugging shown to stderr.'
complete -c $progname -s h -d 'Show the help message.'
complete -c $progname -s m -d 'Set mode of PKGNAME' -xa "$modes"
complete -c $progname -n "__fish_seen_subcommand_from $modes" -xa "(__fish_print_packages -i)"
complete -c $progname -n "__fish_seen_subcommand_from $modes" -xa "(__fish_print_xbps_packages -i)"
complete -c $progname -s r -d 'Specifies a full path for the target root directory.' -xa "(__fish_complete_directories)"
complete -c $progname -s u -d 'Updates the pkgdb format to the latest version making the necessary conversions.'
complete -c $progname -s v -d 'Enables verbose messages.'

View file

@ -3,8 +3,8 @@
set -l progname xbps-query
set -l listall "(__fish_print_packages)"
set -l listinstalled "(__fish_print_packages -i)"
set -l listall "(__fish_print_xbps_packages)"
set -l listinstalled "(__fish_print_xbps_packages -i)"
complete -c $progname -f

View file

@ -3,7 +3,7 @@
set -l progname xbps-reconfigure
set -l listinstalled "(__fish_print_packages -i)"
set -l listinstalled "(__fish_print_xbps_packages -i)"
complete -c $progname -f
complete -c $progname -a "$listinstalled"

View file

@ -3,7 +3,7 @@
set -l progname xbps-remove
set -l listinstalled "(__fish_print_packages -i)"
set -l listinstalled "(__fish_print_xbps_packages -i)"
complete -c $progname -f
complete -c $progname -a "$listinstalled"

View file

@ -4,7 +4,7 @@
set -l progname xbps-uhelper
set -l actions binpkgarch binpkgver cmpver getpkgdepname getpkgdepversion getpkgname getpkgrevision getpkgversion pkgmatch version real-version
complete -c $progname -f -a "$actions (__fish_print_packages -i)"
complete -c $progname -f -a "$actions (__fish_print_xbps_packages -i)"
complete -c $progname -s C -d 'Path to xbps.conf file.' -rF
complete -c $progname -s d -d 'Debugging messages to stderr.'

View file

@ -1,9 +1,9 @@
set -l progname yaourt
complete -c $progname -f
set -l listinstalled "(__fish_print_packages --installed)"
set -l listinstalled "(__fish_print_pacman_packages --installed)"
# This might be an issue if another package manager is also installed (e.g. for containers)
set -l listall "(__fish_print_packages)"
set -l listall "(__fish_print_pacman_packages)"
set -l listrepos "(__fish_print_pacman_repos)"
set -l listgroups "(pacman -Sg)\t'Package Group'"

View file

@ -25,7 +25,7 @@ complete -c yum -n __fish_use_subcommand -xa search -d "find packages matching d
complete -c yum -n __fish_use_subcommand -xa clean -d "Clean up cache directory"
complete -c yum -n __fish_use_subcommand -xa generate-rss -d "Generate rss changelog"
complete -c yum -n __fish_yum_package_ok -a "(__fish_print_packages)"
complete -c yum -n __fish_yum_package_ok -a "(__fish_print_rpm_packages)"
complete -c yum -s h -l help -d "Display help and exit"
complete -c yum -s y -d "Assume yes to all questions"
@ -41,7 +41,7 @@ complete -c yum -l enablerepo -d "Enable repository" -r
complete -c yum -l disablerepo -d "Disable repository" -r
complete -c yum -l obsoletes -d "Enables obsolets processing logic"
complete -c yum -l rss-filename -d "Output rss-data to file" -r
complete -c yum -l exclude -d "Exclude specified package from updates" -a "(__fish_print_packages)"
complete -c yum -l exclude -d "Exclude specified package from updates" -a "(__fish_print_rpm_packages)"
complete -c yum -n 'contains list (commandline -poc)' -a all -d 'List all packages'
complete -c yum -n 'contains list (commandline -poc)' -a available -d 'List packages available for installation'

View file

@ -2,18 +2,13 @@ function __fish_print_apt_packages
argparse --name=__fish_print_packages i/installed -- $argv
or return
set -l only_installed 1
if not set -q _flag_installed
set -e only_installed
end
switch (commandline -ct)
case '-**'
return
end
type -q -f apt-cache || return 1
if not set -q only_installed
if not set -q _flag_installed
# Do not generate the cache as apparently sometimes this is slow.
# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=547550
# (It is safe to use `sed -r` here as we are guaranteed to be on a GNU platform

View file

@ -0,0 +1,43 @@
function __fish_print_eopkg_packages
type -q -f eopkg || return 1
argparse i/installed -- $argv
or return 1
set -l xdg_cache_home (__fish_make_cache_dir)
or return
# If the cache is less than max_age, we do not recalculate it
# Determine whether to print installed/available packages
if set -q _flag_installed
set -l cache_file $xdg_cache_home/.eopkg-installed-cache.$USER
if test -f $cache_file
cat $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 500
if test $age -lt $max_age
return 0
end
end
# Remove package version information from output and pipe into cache file
eopkg list-installed -N | cut -d ' ' -f 1 >$cache_file &
return 0
else
set -l cache_file $xdg_cache_home/.eopkg-available-cache.$USER
if test -f $cache_file
cat $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 500
if test $age -lt $max_age
return 0
end
end
# Remove package version information from output and pipe into cache file
eopkg list-available -N | cut -d ' ' -f 1 >$cache_file &
return 0
end
return 1
end

View file

@ -0,0 +1,14 @@
function __fish_print_opkg_packages
type -q -f opkg || return 1
argparse i/installed -- $argv
or return 1
if set -q _flag_installed
opkg list-installed 2>/dev/null | sed -r 's/^([a-zA-Z0-9\-]+) - ([a-zA-Z0-9\-]+)/\1\t\2/g'
return 0
else
opkg list 2>/dev/null | sed -r 's/^([a-zA-Z0-9\-]+) - ([a-zA-Z0-9\-]+)/\1\t\2/g'
return 0
end
end

View file

@ -1,196 +1,32 @@
# Use --installed to limit to installed packages only
function __fish_print_packages
set -l args $argv
argparse --name=__fish_print_packages i/installed -- $argv
or return
set -l only_installed 1
if not set -q _flag_installed
set -e only_installed
end
switch (commandline -ct)
case '-**'
return
end
__fish_print_apt_packages $args
# This is `__fish_print_packages`. It prints packages,
# from the first package manager it finds.
# That's a pretty bad idea, which is why this is broken up,
# and only available for legacy reasons.
__fish_print_apt_packages $argv
and return
__fish_print_pkg_packages $args
__fish_print_pkg_packages $argv
and return
__fish_print_pkg_add_packages $args
__fish_print_pkg_add_packages $argv
and return
### BEGIN CACHED RESULTS ###
__fish_print_pacman_packages $args
__fish_print_pacman_packages $argv
and return
__fish_print_zypper_packages
__fish_print_rpm_packages $argv
and return
# Set up cache directory
set -l xdg_cache_home (__fish_make_cache_dir)
or return
__fish_print_eopkg_packages $argv
and return
# yum is slow, just like rpm, so go to the background
if type -q -f /usr/share/yum-cli/completion-helper.py
__fish_print_portage_packages $argv
and return
# If the cache is less than six hours old, we do not recalculate it
set -l cache_file $xdg_cache_home/.yum-cache.$USER
if test -f $cache_file
cat $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 21600
if test $age -lt $max_age
return
end
end
# Remove package version information from output and pipe into cache file
/usr/share/yum-cli/completion-helper.py list all -d 0 -C | sed "s/\..*/\tPackage/" >$cache_file &
return
end
# Rpm is too slow for this job, so we set it up to do completions
# as a background job and cache the results.
if type -q -f rpm
# If the cache is less than five minutes old, we do not recalculate it
set -l cache_file $xdg_cache_home/.rpm-cache.$USER
if test -f $cache_file
cat $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 250
if test $age -lt $max_age
return
end
end
# Remove package version information from output and pipe into cache file
rpm -qa | sed -e 's/-[^-]*-[^-]*$/\t'Package'/' >$cache_file &
return
end
# Eopkg is slow in showing list of available packages
if type -q -f eopkg
# If the cache is less than max_age, we do not recalculate it
# Determine whether to print installed/available packages
if set -q only_installed
set -l cache_file $xdg_cache_home/.eopkg-installed-cache.$USER
if test -f $cache_file
cat $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 500
if test $age -lt $max_age
return
end
end
# Remove package version information from output and pipe into cache file
eopkg list-installed -N | cut -d ' ' -f 1 >$cache_file &
return
else
set -l cache_file $xdg_cache_home/.eopkg-available-cache.$USER
if test -f $cache_file
cat $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 500
if test $age -lt $max_age
return
end
end
# Remove package version information from output and pipe into cache file
eopkg list-available -N | cut -d ' ' -f 1 >$cache_file &
return
end
end
# This completes the package name from the portage tree.
# True for installing new packages. Function for printing
# installed on the system packages is in completions/emerge.fish
# eix is MUCH faster than emerge so use it if it is available
if type -q -f eix
eix --only-names "^"(commandline -ct) | cut -d/ -f2
return
else
# FIXME? Seems to be broken
if type -q -f emerge
emerge -s \^(commandline -ct) | string match -r "^\*.*" | cut -d' ' -f3 | cut -d/ -f2
return
end
end
# port needs caching, as it tends to be slow
# BSD find is used for determining file age because HFS+ and APFS
# don't save unix time, but the actual date. Also BSD stat is vastly
# different from linux stat and converting its time format is tedious
if type -q -f port
set -l cache_file $xdg_cache_home/.port-cache.$USER
if test -e $cache_file
# Delete if cache is older than 15 minutes
find "$cache_file" -ctime +15m | awk '{$1=$1;print}' | xargs rm
if test -f $cache_file
cat $cache_file
return
end
end
# Remove trailing whitespace and pipe into cache file
printf "all\ncurrent\nactive\ninactive\ninstalled\nuninstalled\noutdated" >$cache_file
port echo all | awk '{$1=$1};1' >>$cache_file &
cat $cache_file
return
end
if type -q -f opkg
if set -q only_installed
opkg list-installed 2>/dev/null | sed -r 's/^([a-zA-Z0-9\-]+) - ([a-zA-Z0-9\-]+)/\1\t\2/g'
return
else
opkg list 2>/dev/null | sed -r 's/^([a-zA-Z0-9\-]+) - ([a-zA-Z0-9\-]+)/\1\t\2/g'
return
end
end
if type -q -f apk
if set -q only_installed
apk info -q
return
else
apk search -q
return
end
end
# Caches for 5 minutes
if type -q -f xbps-query
if not set -q only_installed
set -l cache_file $xdg_cache_home/.xbps-cache.$USER
if test -f $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 300
if test $age -lt $max_age
cat $cache_file
return
end
end
# prints: <package name> Package
xbps-query -Rsl | sed 's/^... \([^ ]*\)-.* .*/\1/; s/$/\t'Package'/' | tee $cache_file
return
else
xbps-query -l | sed 's/^.. \([^ ]*\)-.* .*/\1/' # TODO: actually put package versions in tab for locally installed packages
return
end
end
__fish_print_port_packages $argv
and return
__fish_print_xbps_packages $argv
and return
end

View file

@ -8,7 +8,7 @@ function __fish_print_pacman_packages
set -l xdg_cache_home (__fish_make_cache_dir)
or return
if not set -q only_installed
if not set -q _flag_installed
set -l cache_file $xdg_cache_home/.pac-cache.$USER
if test -f $cache_file
cat $cache_file

View file

@ -0,0 +1,25 @@
function __fish_print_port_packages
type -q -f port || return 1
# port needs caching, as it tends to be slow
# BSD find is used for determining file age because HFS+ and APFS
# don't save unix time, but the actual date. Also BSD stat is vastly
# different from linux stat and converting its time format is tedious
set -l xdg_cache_home (__fish_make_cache_dir)
or return
set -l cache_file $xdg_cache_home/.port-cache.$USER
if test -e $cache_file
# Delete if cache is older than 15 minutes
find "$cache_file" -ctime +15m | awk '{$1=$1;print}' | xargs rm
if test -f $cache_file
cat $cache_file
return
end
end
# Remove trailing whitespace and pipe into cache file
printf "all\ncurrent\nactive\ninactive\ninstalled\nuninstalled\noutdated" >$cache_file
port echo all | awk '{$1=$1};1' >>$cache_file &
cat $cache_file
return 0
end

View file

@ -0,0 +1,15 @@
function __fish_print_portage_packages
# This completes the package name from the portage tree.
# True for installing new packages. Function for printing
# installed on the system packages is in completions/emerge.fish
# eix is MUCH faster than emerge so use it if it is available
if type -q -f eix
eix --only-names "^"(commandline -ct) | cut -d/ -f2
return 0
else if type -q -f emerge
emerge -s \^(commandline -ct) | string match -r "^\*.*" | cut -d' ' -f3 | cut -d/ -f2
return 0
end
return 1
end

View file

@ -0,0 +1,46 @@
function __fish_print_rpm_packages
type -q -f rpm /usr/share/yum-cli/completion-helper.py || return 1
# We do not use "--installed", but we still allow passing it.
argparse i/installed -- $argv
or return 1
set -l xdg_cache_home (__fish_make_cache_dir)
or return
if type -q -f /usr/share/yum-cli/completion-helper.py
# If the cache is less than six hours old, we do not recalculate it
set -l cache_file $xdg_cache_home/.yum-cache.$USER
if test -f $cache_file
cat $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 21600
if test $age -lt $max_age
return
end
end
# Remove package version information from output and pipe into cache file
/usr/share/yum-cli/completion-helper.py list all -d 0 -C | sed "s/\..*/\tPackage/" >$cache_file &
return
end
# Rpm is too slow for this job, so we set it up to do completions
# as a background job and cache the results.
if type -q -f rpm
# If the cache is less than five minutes old, we do not recalculate it
set -l cache_file $xdg_cache_home/.rpm-cache.$USER
if test -f $cache_file
cat $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 250
if test $age -lt $max_age
return
end
end
# Remove package version information from output and pipe into cache file
rpm -qa | sed -e 's/-[^-]*-[^-]*$/\t'Package'/' >$cache_file &
return
end
end

View file

@ -0,0 +1,28 @@
function __fish_print_xbps_packages
# Caches for 5 minutes
type -q -f xbps-query || return 1
argparse i/installed -- $argv
or return 1
set -l xdg_cache_home (__fish_make_cache_dir)
or return
if not set -q _flag_installed
set -l cache_file $xdg_cache_home/.xbps-cache.$USER
if test -f $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 300
if test $age -lt $max_age
cat $cache_file
return
end
end
# prints: <package name> Package
xbps-query -Rsl | sed 's/^... \([^ ]*\)-.* .*/\1/; s/$/\t'Package'/' | tee $cache_file
return 0
else
xbps-query -l | sed 's/^.. \([^ ]*\)-.* .*/\1/' # TODO: actually put package versions in tab for locally installed packages
return 0
end
end

View file

@ -1,28 +0,0 @@
function __fish_print_zypper_packages
type -q -f zypper || return 1
set -l xdg_cache_home (__fish_make_cache_dir)
or return
# Use libzypp cache file if available
if test -f /var/cache/zypp/solv/@System/solv.idx
awk '!/application:|srcpackage:|product:|pattern:|patch:/ {print $1'\tPackage'}' /var/cache/zypp/solv/*/solv.idx
return 0
end
# If the cache is less than five minutes old, we do not recalculate it
set -l cache_file $xdg_cache_home/.zypper-cache.$USER
if test -f $cache_file
cat $cache_file
set -l age (math (date +%s) - (stat -c '%Y' $cache_file))
set -l max_age 300
if test $age -lt $max_age
return 0
end
end
# Remove package version information from output and pipe into cache file
zypper --quiet --non-interactive search --type=package | tail -n +4 | sed -r 's/^. \| ((\w|[-_.])+).*/\1\t'Package'/g' >$cache_file &
return 0
end