Skip to content

Instantly share code, notes, and snippets.

@jahkeup
Created August 25, 2021 18:33
Show Gist options
  • Save jahkeup/8c89d9815ed7893a68f76f522544128a to your computer and use it in GitHub Desktop.
Save jahkeup/8c89d9815ed7893a68f76f522544128a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
hash loginctl awk
log() { echo "[$(date --iso-8601=s)] $*" >&2; }
if ! loginctl show-session &>/dev/null; then
log "ERROR: no logind session found"
exit 1
fi
{
HEADER=("SESSION" "USERNAME" "XORG-DISPLAY")
(IFS=$'\t'; echo "${HEADER[*]}")
loginctl list-sessions |
awk -v OFS=$'\t' \
'$4 ~ /seat[0-9]+/ {
display_cmd = "loginctl show-session --value -p Display "$1;
display_cmd | getline xorg_display;
print $1, $3, xorg_display;
close(display_cmd);
}'
} |
column -t |
{
# print header to stderr
sed -u '1q' >/dev/stderr
# rest to stdout
cat
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment