feat: Improve SSH agent management and enhance VS Code repository setup with error handling; fixes bug recently introduced. the error messge "mkdtemp: private socket dir: Permission denied" was being displayed when a new terminal window was opened.

This commit is contained in:
Peter Wood
2025-06-27 21:10:51 -04:00
parent 42e0c63eb2
commit 3e01ea6358
2 changed files with 45 additions and 8 deletions

View File

@@ -180,8 +180,39 @@ if command -v fabric &> /dev/null; then
}
fi
if [ -z "$SSH_AUTH_SOCK" ]; then
# Start the SSH agent if not already running
# Add the SSH key to the agent
eval "$(ssh-agent -s)" >/dev/null 2>&1 && ssh-add ~/.ssh/id_ed25519 >/dev/null 2>&1
# SSH Agent Management - Start only if needed and working properly
ssh_agent_start() {
local ssh_agent_env="$HOME/.ssh-agent-env"
# Function to check if ssh-agent is running and responsive
ssh_agent_running() {
[ -n "$SSH_AUTH_SOCK" ] && [ -S "$SSH_AUTH_SOCK" ] && ssh-add -l >/dev/null 2>&1
}
# Load existing agent environment if it exists
if [ -f "$ssh_agent_env" ]; then
source "$ssh_agent_env" >/dev/null 2>&1
fi
# Check if agent is running and responsive
if ! ssh_agent_running; then
# Start new agent only if ssh key exists
if [ -f "$HOME/.ssh/id_ed25519" ]; then
# Clean up any stale agent environment
[ -f "$ssh_agent_env" ] && rm -f "$ssh_agent_env"
# Start new agent and save environment
ssh-agent -s > "$ssh_agent_env" 2>/dev/null
if [ $? -eq 0 ]; then
source "$ssh_agent_env" >/dev/null 2>&1
# Add key to agent
ssh-add "$HOME/.ssh/id_ed25519" >/dev/null 2>&1
fi
fi
fi
}
# Only run SSH agent setup if we have SSH keys
if [ -f "$HOME/.ssh/id_ed25519" ]; then
ssh_agent_start
fi