99# -i, --image IMAGE Docker image (overrides $OR_IMAGE and default)
1010# --user Map host UID/GID into the container via entrypoint.sh
1111# -p, --port SPEC Forward a port, e.g. --port 8265:8265 (repeatable)
12- # --dry-run Print the docker command without executing it
12+ # --dry-run Print the commands (xauth setup + docker run) without executing them
1313# -h|--help Show this help and exit
1414
1515#
@@ -39,7 +39,7 @@ IMAGE=""
3939CMD_ARGS=()
4040
4141usage () {
42- grep ' ^# ' " $0 " | sed ' s/^# \{0,1\}//'
42+ sed -n ' 3,/^$/ s/^# \{0,1\}//p ' " $0 "
4343 exit 0
4444}
4545
@@ -72,9 +72,14 @@ if [[ -n "${KLAYOUT_CMD:-}" ]]; then
7272fi
7373
7474XSOCK=/tmp/.X11-unix
75- XAUTH=/tmp/.docker.xauth
76- if ! $DRY_RUN ; then
77- xauth nlist ${DISPLAY:-: 0} | sed -e ' s/^..../ffff/' | xauth -f $XAUTH nmerge -
75+
76+ if $DRY_RUN ; then
77+ # Use a fixed path so the printed commands work when run by hand
78+ XAUTH=/tmp/.docker.xauth.dry-run
79+ else
80+ XAUTH=$( mktemp /tmp/.docker.xauth.XXXXXXXXXX)
81+ trap ' rm -f "$XAUTH"' EXIT
82+ xauth nlist " ${DISPLAY:-: 0} " | sed -e ' s/^..../ffff/' | xauth -f " $XAUTH " nmerge -
7883fi
7984
8085if test -t 0; then
@@ -104,7 +109,7 @@ CMD_STR=
104109
105110ENV_SH_CMD=' if [ -f ../env.sh ]; then . ../env.sh; fi;'
106111
107- # Build the command once; dry-run prints it, otherwise exec it.
112+ # Build the command once; dry-run prints it, otherwise run it.
108113DOCKER_CMD=(
109114 " $container_engine " run --rm -i
110115 $DOCKER_INTERACTIVE
@@ -130,8 +135,11 @@ DOCKER_CMD=(
130135)
131136
132137if $DRY_RUN ; then
133- echo " ${DOCKER_CMD[*]} "
138+ echo " # Run both lines; the first creates $XAUTH for X forwarding"
139+ echo " xauth nlist '${DISPLAY:-: 0} ' | sed -e 's/^..../ffff/' | xauth -f '$XAUTH ' nmerge -"
140+ printf ' %q ' " ${DOCKER_CMD[@]} "
141+ echo
134142 exit 0
135143fi
136144
137- exec " ${DOCKER_CMD[@]} "
145+ " ${DOCKER_CMD[@]} "
0 commit comments