Created
June 4, 2013 19:30
-
-
Save ekimekim/5708796 to your computer and use it in GitHub Desktop.
A mechanism for running commands in a seperate X session. Requires two files - the script to run the command through, and the xinitrc file to run the command after X starts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file should be renamed ~/.xinitrc | |
# However, CAUTION: Your window manager / desktop environment may already use this file. | |
# In which case you should PREPEND the file with this file's contents. | |
# (The same applies if you have a custom xinitrc - just add this file's contents where appropriate. | |
# For example, in my home .xinitrc, this clause comes after common setup (such as setting the cursor) | |
# but before specifics for setting up my window manager.) | |
if [ -n "$XRUN" ]; then | |
eval $XRUN | |
exit | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USAGE="$0 COMMAND {ARGS} | |
Run given command in a new X session. | |
The session should appear on the next available tty and will terminate when the command does. | |
" | |
if [ "$#" -lt 1 ]; then | |
echo "$USAGE" | |
exit 255 | |
fi | |
# keeps looping until an available display number is found | |
for ((n=0;;n++)); do | |
if ! [ -e "/tmp/.X11-unix/X$n" ]; then | |
break | |
fi | |
done | |
# Construct a bash command string to execute program, even if it contains spaces. | |
command="" | |
for arg in "$@"; do | |
command="$command `printf %q "$arg"`" | |
done | |
XRUN="$command" startx -- ":$n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment