Skip to content

Instantly share code, notes, and snippets.

@rctay
Last active September 22, 2019 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rctay/5886131 to your computer and use it in GitHub Desktop.
Save rctay/5886131 to your computer and use it in GitHub Desktop.
tmux: update current shell's environment's ssh agent forwarding info (ie. value of $SSH_AUTH_SOCK) when reconnecting, eg via PuTTY
# next try: `test` before `export`
val=`tmux show-environment | grep '^SSH_AUTH_SOCK='`;\
test -n "$val" && export "$val"
# with the $_ bash-ism:
test -n `tmux show-environment | grep '^SSH_AUTH_SOCK='`\
&& export "$_";
# use grep instead of `tmux showenv VAR` since output could possibly begin with
# '-' (for variables removed from environment)
eval `tmux show-environment | grep '^SSH_AUTH_SOCK='`; \
export SSH_AUTH_SOCK
# as a function
function copy_one_tmux_env() {
eval `tmux show-environment | grep "^$1="`
export $1
}
@vorburger
Copy link

eval $(tmux showenv -s SSH_AUTH_SOCK) is simpler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment