From 6e8d6328ee0dcff82883c19c19d1e0f35e0926ba Mon Sep 17 00:00:00 2001 From: phanium <91544758+phanen@users.noreply.github.com> Date: Fri, 7 Mar 2025 13:39:10 +0800 Subject: [PATCH] completions/flatpak: don't ignore packages with uppercase in name (#11230) * completions/flatpak: don't ignore packages with uppercase in name `[^A-Z]+` here seems to trim header section in old version flatpak (avoid one more `tail -n -2`?) but this can ignore packages have uppercase name like `org.gtk.Gtk3theme.Adwaita-dark`. * completions/flatpak: use cached `__fish_print_flatpak_packages` for `flatpak install` --- share/completions/flatpak.fish | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/share/completions/flatpak.fish b/share/completions/flatpak.fish index 00ed51f7f..614f418f7 100644 --- a/share/completions/flatpak.fish +++ b/share/completions/flatpak.fish @@ -55,7 +55,23 @@ function __fish_flatpak # We can't rely on the first line being the headers because modern flatpak will omit it when running in a "subshell". # Based off our invocations, we expect the first column of actual output to never contain a capitalized letter # (unlike the header row). - flatpak $argv | string replace -rf '^([^A-Z]+)(?: +|\t)(.*?)\s*$' '$1\t$2' + flatpak $argv | string replace -rf '^([^A-Z].*?)(?: +|\t)(.*?)\s*$' '$1\t$2' +end + +function __fish_print_flatpak_packages + set -l xdg_cache_home (__fish_make_cache_dir) + or return + set -l cache_file $xdg_cache_home/flatpak + if test -f $cache_file + cat $cache_file + set -l age (path mtime -R -- $cache_file) + set -l max_age 250 + if test $age -lt $max_age + return + end + end + __fish_flatpak remote-ls --columns=application,name >$cache_file & + return 0 end complete -f -c flatpak -n "__fish_seen_subcommand_from run" -a "(__fish_flatpak list --app --columns=application,name)" @@ -63,7 +79,7 @@ complete -f -c flatpak -n "__fish_seen_subcommand_from info uninstall" -a "(__fi complete -f -c flatpak -n "__fish_seen_subcommand_from enter kill" -a "(__fish_flatpak ps --columns=instance,application)" complete -f -c flatpak -n "__fish_seen_subcommand_from remote-info remote-ls remote-modify remote-delete" -a "(__fish_flatpak remotes --columns=name,title)" -complete -c flatpak -n '__fish_seen_subcommand_from install' -xa "(__fish_flatpak remote-ls --columns=application,name)" +complete -c flatpak -n '__fish_seen_subcommand_from install' -xa "(__fish_print_flatpak_packages)" # Plenty of the other stuff is too free-form to complete (e.g. remote-add). complete -f -c flatpak -s h -l help