Speed up shell startup 9x (1.9s → 0.2s)

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>
This commit is contained in:
Ole-Morten Duesund 2026-03-09 09:27:12 +01:00
commit 6a00847d4e
11 changed files with 83 additions and 23 deletions

25
00-completion-cache Executable file
View file

@ -0,0 +1,25 @@
# 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"
}