LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

sx

Simple alternative to xinit and startx

TLDR

Start an X session running the commands in $XDGCONFIGHOME/sx/sxrc
$ sx
copy
Start an X session running a specific window manager directly
$ sx [dwm]
copy
Start an X session with an explicit command line
$ sx [exec] [i3]
copy
Run a one-off X program after starting the server
$ sx [xterm]
copy

SYNOPSIS

sx [command [args...]]

DESCRIPTION

sx is a small POSIX shell script that starts an Xorg server, sets up an authority cookie, and then runs a user-supplied command (or sxrc) as the X session. It is intended as a minimal, transparent replacement for xinit and startx, exposing the same basic mechanics without their many optional behaviors.The X server is started on the same TTY where sx is invoked, with the display number derived from the TTY number (so VT1 becomes :1). A fresh MIT-MAGIC-COOKIE-1 is generated from /dev/urandom and registered with xauth before the server is launched with -keeptty -noreset.If no arguments are passed, sx runs the executable file at $XDGCONFIGHOME/sx/sxrc (defaulting to ~/.config/sx/sxrc). Otherwise the supplied command and its arguments become the session leader: when it exits, sx tears down the server.

PARAMETERS

sx does not parse flags of its own. Any arguments are treated as the session command and its arguments. Use -- before the command if it begins with something that could be mistaken for an option.

CONFIGURATION

$XDG_CONFIG_HOME/sx/sxrc

Executable script run as the X session when sx is invoked without arguments. Must have the executable bit set. A typical sxrc launches a window manager as the last (foreground) command, for example:
$ #!/bin/sh
xrdb -merge ~/.Xresources &
xsetroot -cursor_name left_ptr &
exec dwm
copy
$XAUTHORITY
Path to the X authority file. sx generates this file under $XDGDATAHOME/sx/ and exports it for child processes.

CAVEATS

The Xorg command line is hardcoded: server flags cannot be customized through sx itself. Only Unix domain sockets are configured; TCP listening is not enabled. The display number is tied to the TTY number, so starting sx on tty1 always produces display :1, which differs from startx, where :0 is the default. sx requires Xorg, xauth, and a readable /dev/urandom; error checking is intentionally minimal, leaving most reporting to the underlying tools.

HISTORY

sx was written by Earnest Wieczorek (Earnestly) as a proof-of-concept response to the comment in xinit(1) urging "site administrators" to write nicer wrappers. First published on GitHub around 2015, it has remained a tiny shell script (around 70 lines) and is packaged in several distributions, notably Arch Linux, as a lightweight way to launch an X session without startx.

SEE ALSO

xinit(1), startx(1), Xorg(1), xauth(1)

Copied to clipboard
Kai