diff --git a/screen/screenrc.symlink b/screen/screenrc.symlink index befd11d5..c3a7d9aa 100644 --- a/screen/screenrc.symlink +++ b/screen/screenrc.symlink @@ -14,3 +14,6 @@ termcapinfo xterm* ti@:te@ # Support updating the title bar from the screened shell. termcapinfo xterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007' + +# Use the SSH agent socket that is created by oh-my-zsh/plugins/ssh-agent. +setenv SSH_AUTH_SOCK /tmp/ssh-agent-$USER-screen diff --git a/ssh/postinit.zsh b/ssh/postinit.zsh index 87c3e8bb..75ed66ab 100644 --- a/ssh/postinit.zsh +++ b/ssh/postinit.zsh @@ -15,9 +15,13 @@ if [[ -n "$SSH_AGENT_PID" ]] && [[ -n "$SSH_AUTH_SOCK" ]]; then setx SSH_AUTH_SOCK "$auth_sock" > /dev/null unset auth_sock else - verbose Removing system-wide export $fg[yellow]\$SSH_AGENT_PID$reset_color - setx SSH_AGENT_PID "" > /dev/null + if [[ -n "$SSH_AGENT_PID" ]]; then + verbose Removing system-wide export $fg[yellow]\$SSH_AGENT_PID$reset_color + setx SSH_AGENT_PID "" > /dev/null + fi - verbose Removing system-wide export $fg[yellow]\$SSH_AUTH_SOCK$reset_color - setx SSH_AUTH_SOCK "" > /dev/null + if [[ -n "$SSH_AGENT_SOCK" ]]; then + verbose Removing system-wide export $fg[yellow]\$SSH_AUTH_SOCK$reset_color + setx SSH_AUTH_SOCK "" > /dev/null + fi fi diff --git a/ssh/zprofile.zsh b/ssh/zprofile.zsh index c1cb27b8..3a8274f8 100644 --- a/ssh/zprofile.zsh +++ b/ssh/zprofile.zsh @@ -1,4 +1,9 @@ if [[ -n "$SSH_CONNECTION" ]] && (($+commands[screen])); then + if [[ -n "$SSH_AUTH_SOCK" ]]; then + verbose Symlinking $fg[yellow]$SSH_AUTH_SOCK$reset_color to $fg[yellow]/tmp/ssh-agent-$USER-screen$reset_color + ln -sf "$SSH_AUTH_SOCK" "/tmp/ssh-agent-$USER-screen" + fi + verbose Starting $fg[green]screen$reset_color because we\'re connected using $fg[green]ssh$reset_color /usr/bin/screen -dRq ssh && exit fi diff --git a/tmux/tmux.conf.symlink b/tmux/tmux.conf.symlink index 0c8ba919..6b37853b 100644 --- a/tmux/tmux.conf.symlink +++ b/tmux/tmux.conf.symlink @@ -32,3 +32,6 @@ set -s escape-time 0 set -g mouse on bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e; send-keys -M'" + +# Always copy SSH environment variables. +set -g update-environment "SSH_CLIENT SSH_CONNECTION SSH_TTY SSH_AUTH_SOCK SSH_ASKPASS"