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

View file

@ -22,6 +22,7 @@ Use these in all scripts — do not manipulate `PATH` or check permissions manua
- `path_append <dir>` — add directory to end of `$PATH` (checks existence, prevents duplicates)
- `path_prepend <dir>` — add directory to start of `$PATH`
- `require_private <file>` — warn if file is group/world-accessible; use in credential files
- `cached_completion <tool> <gen-cmd...>` — cache completion output to `~/.cache/bash.d/`; regenerates when the tool binary is updated. Use this for all new completion scripts instead of `eval` or `. <()`
## Writing Scripts
@ -30,6 +31,8 @@ Use these in all scripts — do not manipulate `PATH` or check permissions manua
- Guard directory-dependent exports with `[[ -d <path> ]]` before exporting
- Do not suppress stderr from external scripts — only redirect stdout when needed
- Avoid `eval` when `. <(cmd)` (process substitution) works
- For shell completions, use `cached_completion` instead of `eval` or `. <()` to avoid subprocess overhead on every shell start
- For slow environment scripts, use lazy-loading (see `20-oneapi` for the wrapper-function pattern)
- Prevent `LD_LIBRARY_PATH` duplicates with a `case` guard (see `20-oneapi` for example)
## Permissions