Skip to content

Instantly share code, notes, and snippets.

View rbenito's full-sized avatar

Rafael Benito rbenito

View GitHub Profile
@jrbenito
jrbenito / setdisplay bash function
Last active January 26, 2017 18:55
Set display variable when reconnect to a tmux terminal on a server with many users (display can change on each ssh section)
function setdisplay ()
{
USERID=$(id -u);
# list all connections by numeric (don´t wait slow DNS)
# and filter by current user´s listening ports on localhost
# that that is in the range of 6000 ~ 6999 (generally X ports)
PORTA=$(netstat -ane|grep "LISTEN "|grep "$USERID"|sort -k8n|sed -n -e "s/.*127\.0\.0\.1:6.\(..\) .*/\1/p"|tail -n 1);
export DISPLAY="localhost:$PORTA.0"
}