Commit Diff


commit - a91721d810c9a9ef14e6f86951e5c83c7be78c0f
commit + 2ebee30b0afc8c8ba521f0bc4e0fa58f40031152
blob - 25355928d12eb0c0ced83ec474ff22f26d00dab4
blob + b417521fa2d9facd55bea2260790992b7f68d956
--- .profile
+++ .profile
@@ -13,10 +13,12 @@ for prefix in '' /usr/local /opt/local /usr $HOME/.loc
 	path "${prefix}/bin"
 done
 
+path_push() { test -d "$1" && PATH="${1}${PATH:+:}${PATH}"; }
+
 PLAN9=$HOME/.local/plan9 export PLAN9
-path $PLAN9/bin
+path "$PLAN9/bin"
 
-path /opt/homebrew/bin
+path_push /opt/homebrew/bin
 #path ~/.cargo/bin
 #path /usr/local/go/bin
 #path /usr/X11R6/bin
@@ -34,7 +36,7 @@ export LESS=FRXix4
 # flags removed: redraw
 # note: if we ever load into normal vim, iclower will show an error, so that's a
 # red flag
-#export EXINIT='set ai ruler iclower sm sw=2 ts=2 para=BlBdPpIt sect=ShSs 
+#export EXINIT='set ai ruler iclower sm sw=2 ts=2 para=BlBdPpIt sect=ShSs
 # map gg 1G'
 export EDITOR=vi
 command -v ovi >/dev/null && EDITOR=ovi
@@ -53,5 +55,62 @@ test -f ~/.profile.local && . ~/.profile.local
 # shellcheck source=/dev/null
 test -f ~/.local/bin/git-prompt.sh && . ~/.local/bin/git-prompt.sh
 
+# --- ssh-agent setup (works on OpenBSD and macOS with Homebrew OpenSSH) ---
+
+_agent_sock="$HOME/.ssh/agent.sock"
+_agent_pid="$HOME/.ssh/agent.pid"
+
+# Pick the right ssh-agent binary
+case $(uname -s) in
+OpenBSD)
+	_ssh_agent=/usr/bin/ssh-agent
+	;;
+Darwin)
+	# Homebrew: Apple Silicon first, then Intel
+	if [ -x /opt/homebrew/bin/ssh-agent ]; then
+		_ssh_agent=/opt/homebrew/bin/ssh-agent
+	elif [ -x /usr/local/bin/ssh-agent ]; then
+		_ssh_agent=/usr/local/bin/ssh-agent
+	else
+		_ssh_agent=ssh-agent
+	fi
+	;;
+*)
+	_ssh_agent=ssh-agent
+	;;
+esac
+
+_start_agent() {
+	rm -f "$_agent_sock"
+	eval "$("$_ssh_agent" -a "$_agent_sock")"
+	( umask 0177; echo "$SSH_AGENT_PID" > "$_agent_pid" )
+}
+
+export SSH_AUTH_SOCK="$_agent_sock"
+
+if [ ! -S "$SSH_AUTH_SOCK" ]; then
+	_start_agent
+else
+	ssh-add -l >/dev/null 2>&1
+	case $? in
+	2)	# Socket exists but agent is dead
+		_start_agent
+		;;
+	*)	# Agent is alive (0 = has keys, 1 = no keys yet)
+		SSH_AGENT_PID=$(cat "$_agent_pid" 2>/dev/null)
+		export SSH_AGENT_PID
+		;;
+	esac
+fi
+
+# macOS: tell launchd so GUI apps (KeePassXC) see the right socket
+if [ "$(uname -s)" = Darwin ]; then
+	launchctl setenv SSH_AUTH_SOCK "$SSH_AUTH_SOCK"
+fi
+
+unset _agent_sock _agent_pid _ssh_agent
+unset -f _start_agent
+
+# --- final for interactive shells
+
 export ENV=~/.shrc
-
blob - 1fd60e520bbedcf63dfe15f0062d690e00380276
blob + 613aa0432f5cc18532a5c37d061062a0eb722215
--- .shrc
+++ .shrc
@@ -103,4 +103,3 @@ command -v __git_ps1 >/dev/null &&
 		GIT_PS1_SHOWSTASHSTATE=true &&
 		GIT_PS1_SHOWUNTRACKEDFILES=true &&
 		PS1=': [\[\e[01;$(($??31:39))m\]$?\[\e[0m\]] \t \u@\h$(__git_ps1 " git:(%s)") : \w ;\n: \$ ; '
-