Harden installers and wrappers
This commit is contained in:
78
Zsh/.zshrc
78
Zsh/.zshrc
@@ -16,13 +16,45 @@ export DOTZSH_SYNTAX_HIGHLIGHTING_PLUGIN="$ZSH/custom/plugins/zsh-syntax-highlig
|
||||
# Programming Languages Root
|
||||
export PROG_DIR="$HOME/.programming"
|
||||
|
||||
typeset -gA DOTZSH_MISSING_TOOL_WARNED
|
||||
|
||||
dotzsh_warn_missing_tool_once() {
|
||||
local tool_key="$1"
|
||||
local tool_label="$2"
|
||||
local setup_hint="$3"
|
||||
|
||||
if [[ -n "${DOTZSH_MISSING_TOOL_WARNED[$tool_key]:-}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
DOTZSH_MISSING_TOOL_WARNED[$tool_key]=1
|
||||
|
||||
print -u2 -- "$tool_label is not installed on this system."
|
||||
print -u2 -- "Run: $setup_hint"
|
||||
print -u2 -- "Or: just setup all"
|
||||
}
|
||||
|
||||
# Go and GVM (Black Box)
|
||||
export GOPATH="$PROG_DIR/go"
|
||||
export GVM_ROOT="$GOPATH"
|
||||
|
||||
gvm_load() {
|
||||
local requested_command="$1"
|
||||
|
||||
unset -f gvm go gofmt
|
||||
[[ -s "$GVM_ROOT/scripts/gvm" ]] && source "$GVM_ROOT/scripts/gvm"
|
||||
|
||||
if [[ ! -s "$GVM_ROOT/scripts/gvm" ]]; then
|
||||
dotzsh_warn_missing_tool_once "go" "Go / GVM" "just lang go"
|
||||
return 127
|
||||
fi
|
||||
|
||||
source "$GVM_ROOT/scripts/gvm"
|
||||
|
||||
if ! command -v "$requested_command" >/dev/null 2>&1; then
|
||||
dotzsh_warn_missing_tool_once "go" "Go / GVM" "just lang go"
|
||||
return 127
|
||||
fi
|
||||
|
||||
"$@"
|
||||
}
|
||||
|
||||
@@ -34,8 +66,22 @@ gofmt() { gvm_load gofmt "$@"; }
|
||||
export NVM_DIR="$PROG_DIR/node"
|
||||
|
||||
nvm_load() {
|
||||
local requested_command="$1"
|
||||
|
||||
unset -f nvm node npm npx
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
|
||||
|
||||
if [[ ! -s "$NVM_DIR/nvm.sh" ]]; then
|
||||
dotzsh_warn_missing_tool_once "node" "Node / NVM" "just lang node"
|
||||
return 127
|
||||
fi
|
||||
|
||||
. "$NVM_DIR/nvm.sh"
|
||||
|
||||
if ! command -v "$requested_command" >/dev/null 2>&1; then
|
||||
dotzsh_warn_missing_tool_once "node" "Node / NVM" "just lang node"
|
||||
return 127
|
||||
fi
|
||||
|
||||
"$@"
|
||||
}
|
||||
|
||||
@@ -55,15 +101,41 @@ export CONDA_ROOT="$PYENV_ROOT/versions/miniforge3-latest"
|
||||
|
||||
pyenv_load() {
|
||||
unset -f pyenv
|
||||
|
||||
if ! command -v pyenv >/dev/null 2>&1; then
|
||||
dotzsh_warn_missing_tool_once "python" "Pyenv / Python" "just lang python"
|
||||
return 127
|
||||
fi
|
||||
|
||||
eval "$(command pyenv init -)"
|
||||
|
||||
if ! command -v pyenv >/dev/null 2>&1; then
|
||||
dotzsh_warn_missing_tool_once "python" "Pyenv / Python" "just lang python"
|
||||
return 127
|
||||
fi
|
||||
|
||||
pyenv "$@"
|
||||
}
|
||||
|
||||
pyenv() { pyenv_load "$@"; }
|
||||
|
||||
conda_load() {
|
||||
local requested_command="$1"
|
||||
|
||||
unset -f conda mamba
|
||||
[ -f "$CONDA_ROOT/etc/profile.d/conda.sh" ] && source "$CONDA_ROOT/etc/profile.d/conda.sh"
|
||||
|
||||
if [[ ! -f "$CONDA_ROOT/etc/profile.d/conda.sh" ]]; then
|
||||
dotzsh_warn_missing_tool_once "python" "Conda / Mamba" "just lang python"
|
||||
return 127
|
||||
fi
|
||||
|
||||
source "$CONDA_ROOT/etc/profile.d/conda.sh"
|
||||
|
||||
if ! command -v "$requested_command" >/dev/null 2>&1; then
|
||||
dotzsh_warn_missing_tool_once "python" "Conda / Mamba" "just lang python"
|
||||
return 127
|
||||
fi
|
||||
|
||||
"$@"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user