2 Commits

Author SHA1 Message Date
David Tomaschik
2814312d60 Optimize startup 2026-07-07 14:53:56 -07:00
David Tomaschik
a390d0a4d4 Improve SSH_AUTH_SOCK handling. 2026-07-07 14:28:37 -07:00
3 changed files with 154 additions and 131 deletions

View File

@@ -29,10 +29,7 @@ fi
# Setup for libvirt
if [ -z "${LIBVIRT_DEFAULT_URI:-}" ] ; then
if [ "$(id -u)" = "0" ] || (id -Gn 2>/dev/null | grep -q "\blibvirt\b") ; then
LIBVIRT_DEFAULT_URI="qemu:///system"
export LIBVIRT_DEFAULT_URI
fi
export LIBVIRT_DEFAULT_URI="qemu:///system"
fi
# Got rust? (gvim, etc.)

View File

@@ -29,6 +29,9 @@ export WORKON_HOME="$HOME/.virtualenvs"
# GPG full key id
export GPG_ID=7FD58D9A196DCEEEAD671F94F4D7A7915DEA789B
# Capture uname early
_UNAME="$(uname)"
# things we need in all interactive shells
case "$-" in
*i*)
@@ -86,7 +89,6 @@ case "$-" in
;;
esac
# Opt out of .net telemetry
export DOTNET_CLI_TELEMETRY_OPTOUT=1
@@ -97,6 +99,8 @@ export LVM_SUPPRESS_FD_WARNINGS=1
export EARTHLY_SSH_AUTH_SOCK=""
# Handle SSH_AUTH_SOCK for tmux consistency
case "$-" in
*i*)
_SSH_AUTH_LINK="${HOME}/.ssh/ssh_auth_sock"
# Helper to check if a path is our link or points to it
@@ -115,10 +119,19 @@ _is_link_path() {
return 1
}
# Helper to check if an SSH socket is valid and useful via ssh-add return codes
# Helper to check if an SSH socket is valid and useful
_is_valid_ssh_sock() {
[ -z "$1" ] && return 1
[ -S "$1" ] || return 1
if command -v nc >/dev/null 2>&1; then
# Use nc to quickly check if the socket is listening.
# We use -N to shutdown the socket after EOF on stdin (for OpenBSD netcat compatibility).
if echo '' | nc -w 1 -N -U "$1" >/dev/null 2>&1; then
return 0
fi
fi
if command -v ssh-add >/dev/null 2>&1; then
SSH_AUTH_SOCK="$1" ssh-add -l >/dev/null 2>&1
case "$?" in
@@ -126,6 +139,10 @@ _is_valid_ssh_sock() {
*) return 1 ;;
esac
fi
if command -v nc >/dev/null 2>&1; then
return 1
fi
return 0
}
@@ -234,10 +251,12 @@ elif _is_valid_ssh_sock "${_SSH_AUTH_LINK}"; then
fi
unset _SSH_AUTH_LINK _CANDIDATE
;;
esac
# Setup XDG-like dirs on MacOS
# Based on https://leebyron.com/til/mac-xdg/
if [ "$(uname)" = "Darwin" ] ; then
if [ "${_UNAME}" = "Darwin" ] ; then
export XDG_BIN_HOME="${XDG_BIN_HOME:-$HOME/.local/bin}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/Library/Caches}"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
@@ -246,10 +265,12 @@ if [ "$(uname)" = "Darwin" ] ; then
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$TMPDIR/runtime-$(id -u)}"
export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
export PATH="${HOME}/bin/macos:${PATH}"
elif [ "$(uname)" = "Linux" ] ; then
elif [ "${_UNAME}" = "Linux" ] ; then
export PATH="${HOME}/bin/linux:${PATH}"
fi
unset _UNAME
if test -e "$HOME/.localenv"; then
# shellcheck source=/dev/null
. "$HOME/.localenv"

View File

@@ -1,8 +1,11 @@
# For interactive shells
[[ -n "$ZSH_PROFILE" ]] && {
zmodload zsh/datetime
zshrc_start_time=$EPOCHREALTIME
zmodload zsh/zprof
export PS4='+[%D{%f} / %D{%s.%N}] %N:%i> '
exec 3>&2 2>/tmp/zsh_startup.log
set -x
zshrc_start_time=$EPOCHREALTIME
}
HISTFILE=~/.zhistory
HISTSIZE=10000
@@ -298,6 +301,8 @@ typeset -U PATH
if [[ -n "$ZSH_PROFILE" ]]; then
zshrc_end_time=$EPOCHREALTIME
set +x
exec 2>&3 3>&-
# Calculation in ms using zsh floating point math
elapsed_ms=$(( (zshrc_end_time - zshrc_start_time) * 1000 ))
printf "zshrc done: %.0fms\n" "$elapsed_ms"