Extract creating $XDG_CACHE_HOME into its own function

This commit is contained in:
Fabian Homborg 2020-09-22 19:17:15 +02:00
parent 24012b1941
commit 97838657b9
4 changed files with 16 additions and 16 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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