Skip to content

Instantly share code, notes, and snippets.

@tomty89
Last active January 4, 2022 04:53
Show Gist options
  • Save tomty89/4bac7bd1a4c85d59274da8281160361c to your computer and use it in GitHub Desktop.
Save tomty89/4bac7bd1a4c85d59274da8281160361c to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ -z "$XDG_VTNR" ] || [ -z "$XDG_SESSION_ID" ]; then
exit 1
fi
exec systemd-run --user -u sway-"$XDG_VTNR" -E XDG_SESSION_ID="$XDG_SESSION_ID" -G -t bash -lc sway
@tomty89
Copy link
Author

tomty89 commented Jan 3, 2022

libseat gets the "graphical" (as in, the existing earliest session, apparently; it's marked with an * in loginctl user-status) session via libsystemd. If the tty of that session is being used (e.g. by X, or another sway instance / wayland compositor, probably), the approach will lead to failure, in which case XDG_SESSION_ID can be used to specify a different session (which "owns" a tty) to use.

Since sway is intended to be run by the user manager (e.g. so that it will be attached to the user manager's netns), --scope is avoided.

bash -lc provides the "profile" env vars.

-t is for showing the (error) messages directly on the console. It's especially convenient when -G is needed/used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment