diff --git a/config-sync/.config/tmux/tmux.conf b/config-sync/.config/tmux/tmux.conf index a627200..15d7c44 100644 --- a/config-sync/.config/tmux/tmux.conf +++ b/config-sync/.config/tmux/tmux.conf @@ -4,6 +4,7 @@ set-option -g history-limit 10000 # set -g default-shell zsh set -g base-index 1 set -g renumber-windows on +set -g update-environment "DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY" # Status bar background style set -g status-style 'bg=#ffffff,fg=#333333' diff --git a/config-sync/ssh-rc b/config-sync/ssh-rc new file mode 100755 index 0000000..c6b7ba7 --- /dev/null +++ b/config-sync/ssh-rc @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +# Keep a stable SSH agent socket path for tmux panes across reconnects. +if [ -S "$SSH_AUTH_SOCK" ]; then + ln -sf "$SSH_AUTH_SOCK" "$HOME/.ssh/current_agent.sock" +fi diff --git a/scripts/includes/config-sync.sh b/scripts/includes/config-sync.sh index 93a855b..57277ad 100644 --- a/scripts/includes/config-sync.sh +++ b/scripts/includes/config-sync.sh @@ -43,6 +43,8 @@ CFGSYNC="$SCR/../config-sync" # Sync SSH Config check-config $HOME/.ssh/config $CFGSYNC/ssh-config +check-config $HOME/.ssh/rc $CFGSYNC/ssh-rc +chmod +x $CFGSYNC/ssh-rc # Check nanorc includes # check-inject "$HOME/.nanorc" "include $SCR/../config-sync/nanorc" diff --git a/scripts/zshrc.sh b/scripts/zshrc.sh index 1db50aa..bff7a90 100755 --- a/scripts/zshrc.sh +++ b/scripts/zshrc.sh @@ -183,6 +183,18 @@ elif has nano; then export EDITOR="nano" fi +# Use the stable SSH agent socket maintained by ~/.ssh/rc inside SSH/tmux sessions. +if [[ -n "$SSH_TTY" || -n "$SSH_CONNECTION" ]]; then + if [[ -n "$SSH_AUTH_SOCK" && "$SSH_AUTH_SOCK" != "$HOME/.ssh/current_agent.sock" && -S "$SSH_AUTH_SOCK" ]]; then + mkdir -p "$HOME/.ssh" + ln -sf "$SSH_AUTH_SOCK" "$HOME/.ssh/current_agent.sock" + fi + + if [[ -S "$HOME/.ssh/current_agent.sock" ]]; then + export SSH_AUTH_SOCK="$HOME/.ssh/current_agent.sock" + fi +fi + # Gradle with auto environment detection if [[ -z $GRADLE ]] && command -v 'gradle' &> /dev/null; then GRADLE="$(which gradle)"