1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-09 15:59:04 -08:00

use cache directory when loading shell functions

This commit is contained in:
Connor Olding 2024-07-21 13:24:19 -07:00
parent 5299f0725f
commit f52cc0c819

View file

@ -4,13 +4,17 @@
unset FANCY; _=: && [ -z $_ ] && FANCY=1 || FANCY=0 # detect zsh and bash
if [ "$FANCY" = 0 ]; then . ~/.prep; fi # handle stuff like /etc/profile and $PATH
# combine everything matching "YES_MYSHELL" in ~/sh/ into ~/.sh-myshell.
# combine and load everything containing "YES_MYSHELL" in ~/sh/:
[ -z "${0##/*}" ] && sh=zsh || sh="$0" # zsh replaces $0, so hardcode it
if [ -s ~/sh/recombine ] && (. ~/sh/recombine) > ~/.sh-"$sh"; then
preload=:; . ~/.sh-"$sh"; unset preload
elif [ -f ~/.sh-"$sh" ]; then
rm ~/.sh-"$sh"
{ [ -d "${XDG_CACHE_HOME:="$HOME/.cache"}" ] || mkdir "$XDG_CACHE_HOME"; } &&
{ [ -d "$XDG_CACHE_HOME/shrc" ] || mkdir "$XDG_CACHE_HOME/shrc"; } &&
cache="$XDG_CACHE_HOME/shrc/$sh-$$" &&
if [ -s ~/sh/recombine ] && (. ~/sh/recombine) > "$cache"; then
#wc -l "$cache" >&2
preload=:; . "$cache"; unset preload
fi
! [ -f "$cache" ] || rm "$cache"
unset cache
# {{{1 utilities