All pastes #201318 Raw Edit

Something

public shellscript v1 · immutable
#201318 ·published 2006-10-13 19:41 UTC
rendered paste body
# -*- mode: sh -*-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 addto(){    local varname=$1    local newvalue=$2    eval $varname="$newvalue:\${$varname}"    eval $varname=\${$varname/%:}}function cdreplace(){    newdir=${PWD/$1/$2}    command cd "$newdir"}function updatedirs(){    # initialise variables    local devhome=${DEVHOME-$HOME}    local srchome=${SRCHOME-$devhome/src}    local objhome=${OBJHOME-$devhome/obj}    # the other ones    export srcdir=$PWD    export objdir=$PWD    # find out if we're in src or obj    case $PWD in	$srchome*)	    # we're in a srcdir - try to find the objdir	    objdir=${PWD/#$srchome/$objhome}	    ;;	$objhome*)	    # we're in an objdir - try to find the srcdir	    srcdir=${PWD/#$objhome/$srchome}	    ;;    esac    if [ \! -d $srcdir ]; then	srcdir=$PWD    fi    if [ \! -d $objdir ]; then	objdir=$PWD    fi}function cd(){    if [ $# -eq 2 ]; then	cdreplace "$1" "$2"    else	command cd "$@"    fi    updatedirs}function pushd(){    command pushd "$@"    updatedirs}function popd(){    command popd    updatedirs}function src(){    cd obj src}function obj(){    cd src obj}function qt(){    local devhome=${DEVHOME-$HOME}    local srchome=${SRCHOME-$devhome/src}    local objhome=${OBJHOME-$devhome/obj}    local qthome=${QTHOME-$objhome/troll}    # Get or set the Qt version    if [ $# -eq 0 ]; then	# Get the Qt version	if [ -z "$QTDIR" ]; then	    echo "Not using Qt."	else	    ver=${QTDIR/#$qthome\/qt}	    ver=${ver/#-}	    echo "Using Qt $ver"	fi    else	# Set the working Qt version	wanted=$qthome/qt-$1	test -d $wanted || wanted=$qthome/qt$1	if [ ! -d $wanted ]; then	    echo "Cannot find Qt $1"	else	    # Remove old	    removefrom PATH $QTDIR/bin	    removefrom LD_LIBRARY_PATH $QTDIR/lib	    removefrom PKG_CONFIG_PATH $QTDIR/lib	    # Add new	    QTDIR=$wanted	    addto PATH $QTDIR/bin	    addto LD_LIBRARY_PATH $QTDIR/lib	    addto PKG_CONFIG_PATH $QTDIR/lib	    echo "Using Qt $1"	fi    fi}function kde3(){    # 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    export KDEDIR=/usr/local/kde3    export KDEDIRS=$KDEDIR:/usr    export PATH=$KDEDIR/bin:$PATH    export XDG_CONFIG_DIRS=$KDEDIR/etc/xdg    echo "Using KDE 3 ($KDEDIR)"}function kde4(){    # Remove the current KDE from variables    removefrom PATH $KDEDIR/bin    removefrom LD_LIBRARY_PATH $KDEDIR/lib    unset QT_PLUGIN_PATH    # Add the new one    export KDEDIR=$HOME/KDE4    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    # Ensure that they exist    mkdir -p $KDEDIR $KDETMP $KDEVARTMP    echo "Using KDE 4 ($KDEDIR)"}