summary refs log tree commit diff
path: root/bin/gui-enter
blob: ac7a479e7105c483955c5f42d01f7e6d257ba7d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
# this script is based on some assumptions that are made in the context
# of my gentoo/swaywm setup

set -e
[ -n "$DEBUG" ] && set -x

usage() {
	printf "usage: %s USER [ARGS...]" "$(basename "$0")\n"
	printf "\n"
	printf "enter the desktop session of USER and run COMMAND.\n"
	exit 1
}

case "$1" in
	-h) usage && exit 0 ;;
esac

user="${1}"
[ -z "${user}" ] && usage
shift

uid=$(id -u "${user}")

marker_bins="
	oguri
	kanshi
	waybar
	wlsunset
	pipewire
	swayidle
"
pid=
for bin in ${marker_bins}; do
	pid=$(cat "/run/user/${uid}/${bin}.pid")
	kill -0 "${pid}" && break
done

# grep -zE '^(SWAY|I3|WAYLAND|DBUS|XDG|PATH)' /proc/"${pid}"/environ | tr '\0' '\n'

env=$(grep -zE '^(SWAY|I3|WAYLAND|DBUS|XDG|PATH)' /proc/"${pid}"/environ | tr '\0' ' ' || true)
exec doas -nu "${user}" -- env ${env} "${@}"