Skip to content

Instantly share code, notes, and snippets.

@stark
Last active November 14, 2020 02:45
Show Gist options
  • Save stark/7a823e91548d58d72544 to your computer and use it in GitHub Desktop.
Save stark/7a823e91548d58d72544 to your computer and use it in GitHub Desktop.
LinuxBBQ Academy

Lesson 4 - X Startup Customization

Whenever you start your computer and boot into Linux, a series of files are read and executed in a certain order.

We will cover the boot process a tad later in this document, but let us take a look at the part where you enter your username and password and everything thereafter.

This is where the shell starts, as the first interactive environment of your system. After entering username and password, the files ~/.bash_profile and ~/.bashrc are read or sourced.

Let's take a look at ~/.bash_profile first:

cat ~/.bash_profile

As we can see, it first tries to find a file named ~/.bashrc and then, after testing for a set of environment parameters, it executes a command named startx.

It probably has a manual page:

man startx

Let's browse down to the bottom of the manual, where it says FILES. It seems that startx executes a script named ~/.xinitrc amongst some others.

Let's leave the manpage (press q) and check this infamous ~/.xinitrc file:

cat ~/.xinitrc

The really important line is the last one that starts with exec.

In LinuxBBQ Academy it should read:

exec x-window-manager

This is a very general term: x-window-manager could be actually any window manager that has been installed so far.

And in fact, if we install the window manager openbox, it would (probably) be set as x-window-manager, while wmii (the one that was used before) slips down to spot 2.

How can we check which window manager is now set to the active one ?

sudo update-alternatives --display x-window-manager

Is the command, and it should show /usr/bin/wmii as our one and only window manager here.

It also means that if you:

  • Have more than one window manager installed.
  • Always want to have exactly wmii starting up, and not the other one.

You have to edit the ~/.xinitrc file, and change:

exec x-window-manager

To

exec wmii

So, do this if you like. Just remember that later, when you install another window manager, you have to alter this line in ~/.xinitrc again.

But don't just close ~/.xinitrc yet!

Let's say, you want to have a terminal opening every time you start your X session.

Nothing is easier than this: Just add one line before the exec x-window-manager line, so that it looks exactly like this:

x-terminal-emulator &
exec x-window-manager

Remember the '&' there! Now you can save and exit GNU nano.

Wait a moment. x-terminal-emulator looks pretty much like x-window-manager, doesn't it?

Well yes. There are dozens of terminal emulators in Debian, and x-terminal-emulator is the link to the program that is used as terminal emulator in X.

Yeah okay but what terminal emulator do we actually use? Find it out yourself:

sudo update-alternatives --display x-terminal-emulator

Now that you know about the startup of X, you maybe want to add some other cool programs to pop up after logging in. Maybe the alsamixer? In this case, the line in ~/.xinitrc would read:

x-terminal-emulator -e alsamixer &

Or you want to have music playing after logging in?

playstream &

Will do this for you.

The difference is: alsamixer is a terminal program, so the x-terminal-emulator has to execute (-e) the program alsamixer.

playstream, on the other hand, does not need a terminal to play, so no x-terminal-emulator -e needed there.

Further readings in our wiki:

Xinitrc

http://ow.ly/NkOID

Window Managers

http://ow.ly/NkOJG

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