LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What to consider when writing up an xsession or xinitrc ? (https://www.linuxquestions.org/questions/linux-newbie-8/what-to-consider-when-writing-up-an-xsession-or-xinitrc-684739/)

ktek 11-19-2008 06:23 PM

What to consider when writing up an xsession or xinitrc ?
 
Hey. I'd like to tweak my xintrc, mostly to scope out another WM, but it seems to be a somewhat daunting and important script. What all should I take into consideration when heading out to mess with xintrc?

I, unfortunately, do not have an example of my system defaults or anything.

i92guboj 11-19-2008 07:41 PM

There's not much that needs to be taken into account really.

Those scripts are intended mainly to launch a wm and maybe some other little things. They can used to configure some stuff (xbindkeys, set a wallpaper...).

Those files will be run as shell scripts. So, the same universal law that applies for all the shell scripts are still valid here. For example, if you run "program_A" from xinitrc, and program_A never ends, then the script will sit there until that program is closed by you. That means that any program that goes after that is not going to run until program_A has ended. To prevent this behavior you can just launch program_A in background, by adding an ampersand (&) to the end of the command, just like you would do in a bash script or in command line.

Some programs have a short life, so you don't need to do this for them. For example, if you use feh --bg-scale to set your wallpaper, you can put & after it, but that's not gonna give you any benefit, since feh sets the wallpaper and automatically exits anyway.

You might as well want to capture the pid of one process to do something with it later. For example, to make sure it's closed after the session ends. X programs usually die when X is closed. But sometimes there are programs that needs to be killed explicitly. An example is urxvtd, if you use it (it's a daemon for urxvt which greatly reduces the usage of memory when you use lots of terminals). For this, you can use $! like you would do in a regular bash script.

Here you are one script illustrating all of these. It's my actual xinitrc with some comments added so you can make sense of some parts.

Code:

# you can export some vars if you need them inside X, this one tells qtcurve to use
# kde4 color themes for the gtk apps instead of the kde3 ones
export KDE_SESSION_VERSION=4
# setup some X related things
xrdb -merge ~/.Xdefaults
# this calls a script I use to set a random wallpaper from my gallery
random_wallpaper.sh
# pointer
xsetroot -cursor_name left_ptr
# here I launch the wm and redirect all it's output to a file
# I can easily monitor this file using tail in a terminal window that
# I launch a few lines below
xmonad > "${HOME}/logs/xmonad.log" 2>&1 &
# I save the PID for my WM
wm_pid=$!
# launch some programs in the background
gkrellm&
gkrellm -s server&
urxvtd &
# save PID for urxvtd
urxvtd_pid=$!
# wait 2 secs, otherwise if urxvtd is not initialized the following ones will fail
sleep 2
# start some terms with a few things: logs, htop and screen
urxvtc -fade 20 -name server_htop -title server_htop -e ssh root@server
urxvtc -fade 20 -name logs -title logs -e mtail -f ~/logs/xmonad.log /var/log/messages
urxvtc -fade 20 -name htop -title htop -e htop
urxvtc -fade 20 -name main_term -e screen -D -RR
# some more programs
firefox &
sylpheed &
# this line waits until the pid of the wm evaporates. That means that the
# script will sit here until the wm is closed, and the it will proceed to the next line...
wait $wm_pid
# ... the next line, which will kill urxvtd to make sure that urxvtd sessions
# do not sit there wasting ram
kill -TERM $urxvtd_pid

As you see, you can use $! to save the pids and you can use wait to wait for a pid to finish before doing some cleanup at the end of the script. If you don't need such sophistication, you can just make sure that the command to launch the wm is the last one, and that it doesn't end in &. That the simplest xinitrc example you can get:

Code:

feh --bg-scale ~/myfile.png
prog1&
prog2&
prog3&
startkde

Or something like that. Or you might just put "startkde" in a single line, and symlink prog1, prog2 and prog3 into ~/.kde/Autostart... Each wm/desktop has it's own way to autostart applications if you don't want to put them into xinitrc. It's all about choice I guess.

;)

ktek 11-20-2008 03:10 AM

Thanks. I guess I won't worry too much.

schneidz 11-20-2008 09:09 AM

do a backup and tweak to your hearts content.

ktek 11-20-2008 11:05 PM

don't have anything I can find to back-up. :(

schneidz 12-01-2008 10:19 AM

^ if you dont have the cp command then modifying xinitrc is the least of your problems...

what i meant was make a backup of any file you plan to modify. in that case if something goes horribly wrong, one quick cp command will make it all better.


All times are GMT -5. The time now is 08:56 PM.