From 266ce7c940b5894352594c7d40a77a6b16e1c763 Mon Sep 17 00:00:00 2001 From: Jason Nader Date: Sat, 14 Mar 2020 23:11:33 +0900 Subject: [PATCH] Improve Arch Linux package completions Add completions for `downgrade` tool Add new `--installed` option for printing Arch packages Change Arch Linux package related completions to use `--installed` add newline --- share/completions/downgrade.fish | 3 +++ share/completions/pacaur.fish | 2 +- share/completions/pacman.fish | 2 +- share/completions/yaourt.fish | 2 +- share/functions/__fish_print_packages.fish | 26 +++++++++++++--------- 5 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 share/completions/downgrade.fish diff --git a/share/completions/downgrade.fish b/share/completions/downgrade.fish new file mode 100644 index 000000000..35575c166 --- /dev/null +++ b/share/completions/downgrade.fish @@ -0,0 +1,3 @@ +# Arch Linux package downgrader tool +complete -c downgrade -f +complete -c downgrade -xa "(__fish_print_packages --installed)" diff --git a/share/completions/pacaur.fish b/share/completions/pacaur.fish index 4467cadc6..707158ab7 100644 --- a/share/completions/pacaur.fish +++ b/share/completions/pacaur.fish @@ -1,7 +1,7 @@ set -l progname pacaur complete -c $progname -f -set -l listinstalled "(pacman -Q | string replace ' ' \t)" +set -l listinstalled "(__fish_print_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 listrepos "(__fish_print_pacman_repos)" diff --git a/share/completions/pacman.fish b/share/completions/pacman.fish index 6f565d86f..500010502 100644 --- a/share/completions/pacman.fish +++ b/share/completions/pacman.fish @@ -4,7 +4,7 @@ set -l progname pacman -set -l listinstalled "(pacman -Q | string replace ' ' \t)" +set -l listinstalled "(__fish_print_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 listrepos "(__fish_print_pacman_repos)" diff --git a/share/completions/yaourt.fish b/share/completions/yaourt.fish index 59b1e6b2f..dad66c98d 100644 --- a/share/completions/yaourt.fish +++ b/share/completions/yaourt.fish @@ -1,7 +1,7 @@ set -l progname yaourt complete -c $progname -f -set -l listinstalled "(pacman -Q | string replace ' ' \t)" +set -l listinstalled "(__fish_print_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 listrepos "(__fish_print_pacman_repos)" diff --git a/share/functions/__fish_print_packages.fish b/share/functions/__fish_print_packages.fish index f15399ebf..5caf1d8cc 100644 --- a/share/functions/__fish_print_packages.fish +++ b/share/functions/__fish_print_packages.fish @@ -60,19 +60,23 @@ function __fish_print_packages # Caches for 5 minutes if type -q -f pacman - set cache_file $XDG_CACHE_HOME/.pac-cache.$USER - if test -f $cache_file - cat $cache_file - set age (math (date +%s) - (stat -c '%Y' $cache_file)) - set max_age 250 - if test $age -lt $max_age - return + if not set -q only_installed + set cache_file $XDG_CACHE_HOME/.pac-cache.$USER + if test -f $cache_file + cat $cache_file + set age (math (date +%s) - (stat -c '%Y' $cache_file)) + set max_age 250 + if test $age -lt $max_age + return + end end + # prints: Package + pacman -Ssq | sed -e 's/$/\t'Package'/' >$cache_file & + return + else + pacman -Q | string replace ' ' \t + return end - - # prints: Package - pacman -Ssq | sed -e 's/$/\t'Package'/' >$cache_file & - return end # Zypper needs caching as it is slow