I’m in the mood for sharing my tips and tricks. TechBase has some nice bash functions for the user you built KDE as (kde-devel for most people). However, if you installed as another user, there are two common tasks: running a KDE 4 app from your normal user’s account, and switching to your kde-devel user and running a KDE 4 app from there.
A few functions in your main user’s .bashrc and in kde-devel’s .bashrc make all this simple.
Disclaimer: these functions are tailored to my set up (Arch Linux) and will probably need adapting for your system. Especially the kde3 and qt3 functions.
First of all: running KDE 4 apps as your normal user. Put the following in your user’s ~/.bashrc (you just insert removefrom, qt4-copy and kde4 if you like):
function removefrom() { local varname=$1 local entry="$2" unset newvar for value in `IFS=: eval echo \\$$varname`; do if [ "$value" != "$entry" ]; then newvar="${newvar}${newvar+:}${value}" fi done # Set it again eval $varname="$newvar" unset newvar } function qt3() { removefrom PATH $QTDIR/bin removefrom LD_LIBRARY_PATH $QTDIR/lib removefrom PKG_CONFIG_PATH $QTDIR/lib removefrom MANPATH $QTDIR/man source /etc/profile.d/qt.sh echo "Using QT 3 ($QTDIR)" } function qt4() { removefrom PATH $QTDIR/bin removefrom LD_LIBRARY_PATH $QTDIR/lib removefrom PKG_CONFIG_PATH $QTDIR/lib removefrom MANPATH $QTDIR/man source /etc/profile.d/qt4.sh echo "Using system QT 4 ($QTDIR)" } function qt4-copy() { removefrom PATH $QTDIR/bin removefrom LD_LIBRARY_PATH $QTDIR/lib removefrom PKG_CONFIG_PATH $QTDIR/lib removefrom MANPATH $QTDIR/man export QTDIR=/home/kde-devel/build/qt-copy export PATH=$QTDIR/bin:$PATH export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH export PKG_CONFIG_PATH=$QTDIR/lib:$PKG_CONFIG_PATH export MANPATH=$MANPATH:$QTDIR/man export QMAKESPEC=$QTDIR/mkspecs/linux-g++ echo "Using QT 4 from KDE SVN ($QTDIR)" } function kde3() { qt3 # Remove the current KDE from variables removefrom PATH $KDEDIR/bin removefrom LD_LIBRARY_PATH $KDEDIR/lib unset QT_PLUGIN_PATH unset KDEHOME unset KDETMP unset KDEVARTMP # Add the new ones source /etc/profile.d/kde.sh echo "Using KDE 3 ($KDEDIR)" } function kde4() { qt4-copy # Remove the current KDE from variables removefrom PATH $KDEDIR/bin removefrom LD_LIBRARY_PATH $KDEDIR/lib removefrom PKG_CONFIG_PATH $KDEDIR/lib/pkgconfig # Add the new one export KDEDIR=/home/kde-devel/kde export KDEDIRS=$KDEDIR export KDEHOME=$HOME/.kde4 export KDETMP=${TMPDIR-/tmp}/kde4-$USER export KDEVARTMP=/var/tmp/kde4cache-$USER export KDE_DATA_DIRS=$KDEDIR/share export PATH=$KDEDIR/bin:$PATH export XDG_CONFIG_DIRS=$KDEDIR/etc/xdg export QT_PLUGIN_PATH=$KDEDIR/lib/plugins export LD_LIBRARY_PATH=$KDEDIR/lib:$LD_LIBRARY_PATH export PKG_CONFIG_PATH=$KDEDIR/lib/pkgconfig:$LD_LIBRARY_PATH export KDE_COLOR_DEBUG=1 # Ensure that they exist mkdir -p $KDEDIR $KDETMP $KDEVARTMP echo "Using KDE 4 ($KDEDIR)" }
Now you can type “kde4” at a prompt, and thereafter you are in a KDE4 environment. So typing konqueror will give you Konqi from KDE 4 (exactly how I’m typing this post). “kde3” will get you back to a KDE 3 session.
Now for switching to kde-devel. The problem is that you want kde-devel to have the magic cookie that allows it to connect to your X server. Your normal user needs to give it out like so:
function go-kde() { xauth list $DISPLAY | sed "s/^.*$DISPLAY/$DISPLAY/" > /tmp/x.auth sudo su - kde-devel rm -f /tmp/x.auth }
Typing “go-kde” should now take you to a kde-devel session, with your magic cookie saved in /tmp/x.auth. But how do applications find out about it? Put the following in kde-devel’s ~/.bashrc:
if [ -f /tmp/x.auth ]; then xauth add $(cat /tmp/x.auth) fi
Easy, huh?