Skip to content

Instantly share code, notes, and snippets.

@mwvent
Created May 10, 2018 13:42
Show Gist options
  • Save mwvent/0363828539193848096e0bf179e8dc3e to your computer and use it in GitHub Desktop.
Save mwvent/0363828539193848096e0bf179e8dc3e to your computer and use it in GitHub Desktop.
List display number, glx capable and gpu name - I use for scripts that need to automatically locate a GPU display number when number is unkown
#!/bin/bash
# Get a list of sessions from loginctl - filtered to ones with a DISPLAY set then filter DISPLAY number
DISPLAYS=$(loginctl list-sessions | grep -v "SESSION" | grep -v "listed" | tr -s " " | sed '/^$/d' | cut -d " " -f2 | xargs loginctl show-session | grep "Display=" | cut -d "=" -f 2)
# Iterate found list of DISPLAYS - attempt to determine which are GLX capable, add them to the GLX_DISPLAYS list when found
for CUR_DISPLAY in $DISPLAYS; do
if [ "$( DISPLAY=$CUR_DISPLAY glxinfo 2>&1 | grep "Error:" )" = "" ]; then
HAS_GLX="HASGLX"
else
HAS_GLX="NOGLX"
fi
GPU_NAME=$(DISPLAY=$CUR_DISPLAY xrandr --listproviders | awk -F"name:" '{$0=$2}1' | tr --delete '\n')
echo "$CUR_DISPLAY $HAS_GLX $GPU_NAME"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment