From 97838657b9d20c9ae56db7c867b302a799a442ca Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Tue, 22 Sep 2020 19:17:15 +0200 Subject: [PATCH] Extract creating $XDG_CACHE_HOME into its own function --- share/functions/__fish_make_cache_dir.fish | 9 +++++++++ share/functions/__fish_print_packages.fish | 7 ++----- share/functions/__fish_print_pacman_packages.fish | 9 +++------ share/functions/__fish_print_zypper_packages.fish | 7 ++----- 4 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 share/functions/__fish_make_cache_dir.fish diff --git a/share/functions/__fish_make_cache_dir.fish b/share/functions/__fish_make_cache_dir.fish new file mode 100644 index 000000000..24c774491 --- /dev/null +++ b/share/functions/__fish_make_cache_dir.fish @@ -0,0 +1,9 @@ +function __fish_make_cache_dir --description "Create and return XDG_CACHE_HOME" + set -l xdg_cache_home $XDG_CACHE_HOME + if test -z "$xdg_cache_home"; or string match -qv '/*' -- $xdg_cache_home; or set -q xdg_cache_home[2] + set xdg_cache_home $HOME/.cache + end + mkdir -m 700 -p $xdg_cache_home + and echo $xdg_cache_home +end + diff --git a/share/functions/__fish_print_packages.fish b/share/functions/__fish_print_packages.fish index ebfe5f068..2d2092b1e 100644 --- a/share/functions/__fish_print_packages.fish +++ b/share/functions/__fish_print_packages.fish @@ -32,11 +32,8 @@ function __fish_print_packages and return # Set up cache directory - set -l xdg_cache_home $XDG_CACHE_HOME - if test -z "$xdg_cache_home" - set xdg_cache_home $HOME/.cache - end - mkdir -m 700 -p $xdg_cache_home + set -l xdg_cache_home (__fish_make_cache_dir) + or return # yum is slow, just like rpm, so go to the background if type -q -f /usr/share/yum-cli/completion-helper.py diff --git a/share/functions/__fish_print_pacman_packages.fish b/share/functions/__fish_print_pacman_packages.fish index fae1656f5..db4cd5145 100644 --- a/share/functions/__fish_print_pacman_packages.fish +++ b/share/functions/__fish_print_pacman_packages.fish @@ -5,12 +5,9 @@ function __fish_print_pacman_packages argparse i/installed -- $argv or return 1 - # Set up cache directory - set -l xdg_cache_home $XDG_CACHE_HOME - if test -z "$xdg_cache_home" - set xdg_cache_home $HOME/.cache - end - mkdir -m 700 -p $xdg_cache_home + set -l xdg_cache_home (__fish_make_cache_dir) + or return + if not set -q only_installed set -l cache_file $xdg_cache_home/.pac-cache.$USER if test -f $cache_file diff --git a/share/functions/__fish_print_zypper_packages.fish b/share/functions/__fish_print_zypper_packages.fish index 42eb7deaf..2cce045e3 100644 --- a/share/functions/__fish_print_zypper_packages.fish +++ b/share/functions/__fish_print_zypper_packages.fish @@ -1,11 +1,8 @@ function __fish_print_zypper_packages type -q -f zypper || return 1 - set -l xdg_cache_home $XDG_CACHE_HOME - if test -z "$xdg_cache_home" - set xdg_cache_home $HOME/.cache - end - mkdir -m 700 -p $xdg_cache_home + 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