Skip to content

Instantly share code, notes, and snippets.

@towo
Last active October 24, 2016 23:05
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 towo/b5643ba96f987df54acc54470e6be460 to your computer and use it in GitHub Desktop.
Save towo/b5643ba96f987df54acc54470e6be460 to your computer and use it in GitHub Desktop.
Updating shells in tmux for new X sessions, specifically GNOME shell
set -g update-environment 'DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY DBUS_SESSION_BUS_ADDRESS'
precmd() {
if [ -n "${TMUX}" ]; then
local _tmux_env;
_tmux_env=$(tmux show-environment);
if [ "${_tmux_env}" != "${_expected_tmux_env}" ]; then
eval $(echo "${_tmux_env}" | sed -e '/^-/!{ s/=/="/; s/$/"/; s/^/export /; }' -e 's/^-/unset /' -e 's/$/;/');
_expected_tmux_env="${_tmux_env}";
fi;
fi;
}
# vim: filetype=zsh :
@towo
Copy link
Author

towo commented Oct 24, 2016

Just drop this function into your zsh infrastructure and get it loaded in your shells and ensure your tmux also updates DBUS_SESSION_ADDRESS.

This will automatically source all things you set in update-environment - especially DBUS_SESSION_BUS_ADDRESS - to update to your current runtime environment. So if you have to shoot your X session in the head and get a new one, just push enter in your shell to still be able to talk to your new ssh agent started with the D-Bus session.

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