Skip to content

Commit

Permalink
Auto-update $DISPLAY within tmux
Browse files Browse the repository at this point in the history
Help avoid stale values for $DISPLAY which breaks X11 forwarding.
  • Loading branch information
Pinjasaur committed Dec 13, 2017
1 parent ff3b5ea commit 39e6d19
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
14 changes: 13 additions & 1 deletion .bash_profile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ source ~/.bash/z/z.sh

# Load the shell dotfiles
for file in ~/.{exports,aliases,functions,bash_prompt,bash.local}; do
[ -r "$file" ] && source "$file"
[ -r "$file" ] && source "$file"
done
unset file

# Ran before every command
preexec() {
# Don't cause a preexec for PROMPT_COMMAND
# Beware! This fails if PROMPT_COMMAND is a string with more than one command
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return

# Update $DISPLAY to help avoid stale values within tmux
update-x11-forwarding
}

trap 'preexec' DEBUG
14 changes: 14 additions & 0 deletions .functions
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,17 @@ haste() {
echo "Upload failed."
return 1
}

# Cache $DISPLAY if we're not in tmux, otherwise update from the cache
# Based on: http://alexteichman.com/octo/blog/2014/01/01/x11-forwarding-and-terminal-multiplexers/
update-x11-forwarding() {
if [ ! -f ~/.display ]; then
touch ~/.display
fi

if [ -z "$TMUX" ]; then
echo $DISPLAY > ~/.display
else
export DISPLAY=`cat ~/.display`
fi
}

0 comments on commit 39e6d19

Please sign in to comment.