2026-02-03 18:36:21 +02:00
|
|
|
# ---- logging ---------------------------------------------------------------
|
|
|
|
|
|
2026-02-02 22:07:05 +02:00
|
|
|
log_shell_init() {
|
2026-02-05 07:32:54 +02:00
|
|
|
local uid="${UID:-}"
|
|
|
|
|
[[ -n "$uid" ]] || uid="$(id -u 2>/dev/null || echo unknown)"
|
|
|
|
|
|
|
|
|
|
# Override with:
|
|
|
|
|
# export NANUQSAURUS_SHELL_INIT_LOG_FILE=/path/to/log
|
|
|
|
|
local log_file="${NANUQSAURUS_SHELL_INIT_LOG_FILE:-/tmp/shell-init-${uid}.log}"
|
|
|
|
|
|
|
|
|
|
printf '%s\n' "shell-init: $*" >>"$log_file" 2>/dev/null || true
|
2026-02-02 22:07:05 +02:00
|
|
|
}
|
|
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
# ---- helpers ---------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
have() { command -v "$1" >/dev/null 2>&1; }
|
|
|
|
|
|
|
|
|
|
is_interactive() {
|
|
|
|
|
[[ -t 1 || -n ${PS1:-} ]]
|
2026-02-02 22:07:05 +02:00
|
|
|
}
|
|
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
# ---- environment sanity ----------------------------------------------------
|
2026-02-02 22:07:05 +02:00
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
if [[ -z ${TERM:-} || $TERM == dumb ]]; then
|
2026-02-02 22:07:05 +02:00
|
|
|
export TERM=xterm-256color
|
|
|
|
|
fi
|
|
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
INTERACTIVE=0
|
|
|
|
|
is_interactive && INTERACTIVE=1
|
2026-02-02 22:07:05 +02:00
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
log_shell_init "TERM=$TERM PS1=${PS1:-<empty>} SHELL=$SHELL interactive=$INTERACTIVE"
|
|
|
|
|
|
|
|
|
|
# Ensure PS1 exists so downstream init blocks run
|
|
|
|
|
if (( INTERACTIVE )) && [[ -z ${PS1:-} ]]; then
|
2026-02-02 22:07:05 +02:00
|
|
|
PS1='\\s-\\v\\$ '
|
|
|
|
|
fi
|
|
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
(( INTERACTIVE )) || return 0
|
|
|
|
|
|
|
|
|
|
# ---- bash-preexec ----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
if [[ -n ${BASH_VERSION:-} && -z ${bash_preexec_imported:-} && -r "@BASHPREEXEC@" ]]; then
|
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
|
. "@BASHPREEXEC@"
|
2026-07-11 16:13:30 +03:00
|
|
|
# Do NOT call __bp_install here. bash-preexec must install on the FIRST prompt,
|
|
|
|
|
# after starship/atuin/zoxide/ghostty have modified PROMPT_COMMAND, so that
|
|
|
|
|
# __bp_interactive_mode stays the LAST PROMPT_COMMAND entry. Installing eagerly
|
|
|
|
|
# lets later hooks land after it and silently breaks preexec (atuin recording).
|
2026-02-03 18:36:21 +02:00
|
|
|
log_shell_init "bash-preexec loaded"
|
2026-02-02 22:07:05 +02:00
|
|
|
fi
|
|
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
# ---- starship --------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
if have @STARSHIP@; then
|
2026-02-02 22:07:05 +02:00
|
|
|
log_shell_init "starship init"
|
2026-02-03 18:36:21 +02:00
|
|
|
case $SHELL in
|
2026-02-02 22:07:05 +02:00
|
|
|
*/bash) eval "$(@STARSHIP@ init bash)" ;;
|
|
|
|
|
*/zsh) eval "$(@STARSHIP@ init zsh)" ;;
|
|
|
|
|
esac
|
2026-07-11 16:13:30 +03:00
|
|
|
# starship's bash init registers starship_precmd/starship_preexec_all with
|
|
|
|
|
# bash-preexec directly; no manual PROMPT_COMMAND wiring needed.
|
2026-02-02 22:07:05 +02:00
|
|
|
else
|
2026-02-03 18:36:21 +02:00
|
|
|
log_shell_init "starship skipped"
|
2026-02-02 22:07:05 +02:00
|
|
|
fi
|
|
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
# ---- atuin -----------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
if have @ATUIN@; then
|
|
|
|
|
log_shell_init "atuin init"
|
|
|
|
|
|
|
|
|
|
if [[ -z ${ATUIN_SESSION:-} ]]; then
|
|
|
|
|
export ATUIN_SESSION="$(@ATUIN@ uuid)"
|
2026-02-02 22:07:05 +02:00
|
|
|
ATUIN_HISTORY_ID=""
|
|
|
|
|
fi
|
2026-02-03 18:36:21 +02:00
|
|
|
|
|
|
|
|
case $SHELL in
|
2026-02-02 22:07:05 +02:00
|
|
|
*/bash) eval "$(@ATUIN@ init bash)" ;;
|
|
|
|
|
*/zsh) eval "$(@ATUIN@ init zsh)" ;;
|
|
|
|
|
esac
|
2026-07-11 16:13:30 +03:00
|
|
|
# atuin's init registers __atuin_preexec/__atuin_precmd with bash-preexec
|
|
|
|
|
# itself; manual array wiring only caused duplicate hook entries.
|
2026-02-02 22:07:05 +02:00
|
|
|
else
|
|
|
|
|
log_shell_init "atuin skipped"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
# ---- zoxide ---------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
if have zoxide; then
|
2026-02-02 22:07:05 +02:00
|
|
|
log_shell_init "zoxide init"
|
2026-02-03 18:36:21 +02:00
|
|
|
case $SHELL in
|
2026-02-02 22:07:05 +02:00
|
|
|
*/bash) eval "$(zoxide init bash)" ;;
|
|
|
|
|
*/zsh) eval "$(zoxide init zsh)" ;;
|
|
|
|
|
esac
|
2026-07-11 16:13:30 +03:00
|
|
|
# zoxide's bash init hooks into bash-preexec (precmd_functions) when it is
|
|
|
|
|
# present; manual PROMPT_COMMAND wiring only pushed hooks past
|
|
|
|
|
# __bp_interactive_mode and broke preexec ordering.
|
2026-02-02 22:07:05 +02:00
|
|
|
else
|
|
|
|
|
log_shell_init "zoxide skipped"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
# ---- aliases --------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
if have eza; then
|
2026-02-02 22:07:05 +02:00
|
|
|
alias ls='eza'
|
2026-02-03 18:36:21 +02:00
|
|
|
alias ll='eza -l --icons=auto --group-directories-first'
|
2026-02-02 22:07:05 +02:00
|
|
|
alias l1='eza -1'
|
2026-02-03 18:36:21 +02:00
|
|
|
alias l.='eza -d .*'
|
2026-02-02 22:07:05 +02:00
|
|
|
fi
|
|
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
if have ug; then
|
2026-02-02 22:07:05 +02:00
|
|
|
alias grep='ug'
|
|
|
|
|
alias egrep='ug -E'
|
|
|
|
|
alias fgrep='ug -F'
|
|
|
|
|
alias xzgrep='ug -z'
|
|
|
|
|
alias xzegrep='ug -zE'
|
|
|
|
|
alias xzfgrep='ug -zF'
|
|
|
|
|
fi
|
|
|
|
|
|
2026-02-03 18:36:21 +02:00
|
|
|
if have bat; then
|
2026-02-02 22:07:05 +02:00
|
|
|
alias cat='bat --style=plain --pager=never' 2>/dev/null
|
2026-02-05 07:32:54 +02:00
|
|
|
fi
|