Skip to content

Instantly share code, notes, and snippets.

@minamaged113
Last active April 13, 2023 08:46
Show Gist options
  • Save minamaged113/67a0d3b5c3dbfa4a7885fedbb40411a6 to your computer and use it in GitHub Desktop.
Save minamaged113/67a0d3b5c3dbfa4a7885fedbb40411a6 to your computer and use it in GitHub Desktop.
A script to set DISPLAY variable when connecting using ssh to ubuntu to allow opening GUI applications from remote console.
#!/usr/bin/env bash
# Add this to your `~/.$(echo $0 | tr -d "-")rc` file to run it for
# every shell instance
#####################################################################
# Add one of the following options to forward the displace from WSL
# outside
#####################################################################
# Option 1 @ port 0
export DISPLAY=$(ip route|awk '/^default/{print $3}'):0.0
#####################################################################
# Option 2 @ port 7
# check if the user is connected using ssh
if [[ -v $SSH_CLIENT ]];
then
export DISPLAY=$(echo $SSH_CLIENT | cut -d " " -f 1 ):7.0
printf "DISPLAY variable has been set to $DISPLAY"
else
printf "Not using SSH. DISPLAY is $DISPLAY"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment