Skip to content

Instantly share code, notes, and snippets.

@realmtai
Created January 13, 2015 04:02
Show Gist options
  • Save realmtai/cdaf263db37a833756f9 to your computer and use it in GitHub Desktop.
Save realmtai/cdaf263db37a833756f9 to your computer and use it in GitHub Desktop.
# in your ~/.bashrc, add the following
# -- Improved X11 forwarding through GNU Screen (or tmux).
# If not in screen or tmux, update the DISPLAY cache.
# If we are, update the value of DISPLAY to be that in the cache.
function update-x11-forwarding
{
if [ -z "$STY" -a -z "$TMUX" ]; then
echo $DISPLAY > ~/.tmux.display.txt
else
export DISPLAY=`cat ~/.tmux.display.txt`
fi
}
# This is run before every command.
preexec() {
# Don't cause a preexec for PROMPT_COMMAND.
# Beware! This fails if PROMPT_COMMAND is a string containing more than one command.
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return
update-x11-forwarding
# Debugging.
#echo DISPLAY = $DISPLAY, tmux.display.txt = `cat ~/.tmux.display.txt`, STY = $STY, TMUX = $TMUX
}
trap 'preexec' DEBUG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment