Lazy-load Intel oneAPI setvars.sh (~1.5s) via wrapper functions that source the environment on first use of icc/icx/ifort/etc. Cache all shell completion outputs to ~/.cache/bash.d/ so they are sourced from disk instead of regenerated via subprocess on every shell start. Cache invalidates automatically when the tool binary is updated. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
25 lines
808 B
Text
Executable file
25 lines
808 B
Text
Executable file
# shellcheck shell=bash
|
|
# Cache completion scripts to avoid subprocess overhead on every shell start.
|
|
#
|
|
# Usage: cached_completion <tool> <generation-command...>
|
|
# Example: cached_completion gh gh completion -s bash
|
|
#
|
|
# The cache file is regenerated when the tool binary is newer than the cache.
|
|
# Cache location: ${XDG_CACHE_HOME:-$HOME/.cache}/bash.d/
|
|
|
|
_COMP_CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/bash.d"
|
|
|
|
cached_completion() {
|
|
local tool="$1"; shift
|
|
local cache_file="${_COMP_CACHE}/${tool}.bash"
|
|
local tool_path
|
|
tool_path="$(command -v "$tool" 2>/dev/null)" || return
|
|
|
|
if [[ ! -f "$cache_file" || "$tool_path" -nt "$cache_file" ]]; then
|
|
mkdir -p "$_COMP_CACHE"
|
|
"$@" > "$cache_file" 2>/dev/null || return
|
|
fi
|
|
|
|
# shellcheck disable=SC1090
|
|
. "$cache_file"
|
|
}
|