LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-19-2008, 06:23 PM   #1
ktek
Member
 
Registered: Sep 2008
Posts: 48

Rep: Reputation: 15
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.
 
Old 11-19-2008, 07:41 PM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,073

Rep: Reputation: 385Reputation: 385Reputation: 385Reputation: 385
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.

 
Old 11-20-2008, 03:10 AM   #3
ktek
Member
 
Registered: Sep 2008
Posts: 48

Original Poster
Rep: Reputation: 15
Thanks. I guess I won't worry too much.
 
Old 11-20-2008, 09:09 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,135

Rep: Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876
do a backup and tweak to your hearts content.
 
Old 11-20-2008, 11:05 PM   #5
ktek
Member
 
Registered: Sep 2008
Posts: 48

Original Poster
Rep: Reputation: 15
don't have anything I can find to back-up.
 
Old 12-01-2008, 10:19 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,135

Rep: Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876Reputation: 876
^ 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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
.xinitrc and .xsession ignored Whitman Debian 2 09-18-2005 12:11 PM
.xinitrc vs. .Xdefaults vs .Xsession frankie_DJ Linux - Newbie 4 08-02-2005 05:39 AM
.Xsession .xinitrc a10392 Linux - Newbie 2 12-10-2004 02:34 PM
.xinitrc/.xsession - Where are they? Fluxbox the_rydster Slackware 3 03-07-2004 01:45 PM
No .Xdefaults, .xsession, .xinitrc madchmst82 Linux - Newbie 3 09-23-2003 07:05 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration