82 lines
2.8 KiB
Bash
Executable File
82 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
if [ `id -u` -eq 0 ]; then
|
|
CONFDIR=/opt/kde/share/config
|
|
else
|
|
CONFDIR=~/.kde4/share/config
|
|
fi
|
|
XDG_APPS_DIR=/usr/share/applications
|
|
FAVORITES=`/opt/kde/bin/kreadconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs 2>/dev/null`
|
|
|
|
function usage() {
|
|
echo "KDE4 kickoff configuration tool"
|
|
echo
|
|
echo "Usage:"
|
|
echo " kickoffcfg {--add-favorite|--del-favorite} /path/to/desktopfile.desktop"
|
|
echo " kickoffcfg --update-favorite /path/to/old/desktopfile.desktop /path/to/new/desktopfile.desktop"
|
|
echo " kickoffcfg --autoupdate-favorites"
|
|
echo
|
|
echo "Current favorites:"
|
|
echo $FAVORITES
|
|
exit 1
|
|
}
|
|
|
|
[ "$1" ] || usage
|
|
|
|
if [ "$1" = "--add-favorite" ]; then
|
|
[ "$2" ] || usage
|
|
# ADD
|
|
echo "$FAVORITES" | grep $2 >/dev/null || {
|
|
if [ "$FAVORITES" ]; then
|
|
FAVORITES="$FAVORITES,$2"
|
|
else
|
|
FAVORITES="$2"
|
|
fi
|
|
/opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $FAVORITES
|
|
}
|
|
elif [ "$1" = "--del-favorite" ]; then
|
|
[ "$2" ] || usage
|
|
# DELETE
|
|
MODFAVORITES=`echo "$FAVORITES" | sed "s|$2||;s|^,||;s|,,|,|"`
|
|
if [ ! "$MODFAVORITES" ]; then
|
|
/opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs ''
|
|
elif [ "$FAVORITES" != "$MODFAVORITES" ]; then
|
|
/opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $MODFAVORITES
|
|
fi
|
|
elif [ "$1" = "--update-favorite" ]; then
|
|
[ "$2" -a "$3" ] || usage
|
|
# UPDATE
|
|
MODFAVORITES=`echo "$FAVORITES" | sed "s|$2|$3|"`
|
|
/opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $MODFAVORITES
|
|
elif [ "$1" = "--autoupdate-favorites" ]; then
|
|
SAVEIFS=$IFS
|
|
IFS=","
|
|
for f in $FAVORITES; do
|
|
if [ "$f" = "$XDG_APPS_DIR/chromium-devel.desktop" ]; then
|
|
kickoffcfg --update-favorite $f $XDG_APPS_DIR/chromium.desktop
|
|
fi
|
|
if [ ! -e "$f" ]; then
|
|
DIRNAME=`dirname $f`
|
|
BASENAME=`basename $f`
|
|
BASENAME_LC=`echo $BASENAME | tr '[:upper:]' '[:lower:]'`
|
|
if [ -e $XDG_APPS_DIR/$BASENAME ]; then
|
|
echo "kickoffcfg: migrating $f to $XDG_APPS_DIR/$BASENAME"
|
|
kickoffcfg --update-favorite $f $XDG_APPS_DIR/$BASENAME
|
|
elif [ -e $XDG_APPS_DIR/org.kde.$BASENAME ]; then
|
|
echo "kickoffcfg: migrating $f to $XDG_APPS_DIR/org.kde.$BASENAME"
|
|
kickoffcfg --update-favorite $f $XDG_APPS_DIR/org.kde.$BASENAME
|
|
elif [ -e $XDG_APPS_DIR/org.kde.$BASENAME_LC ]; then
|
|
echo "kickoffcfg: migrating $f to $XDG_APPS_DIR/org.kde.$BASENAME_LC"
|
|
kickoffcfg --update-favorite $f $XDG_APPS_DIR/org.kde.$BASENAME_LC
|
|
else
|
|
echo "WARNING: favorite link $f does not exist; ignoring."
|
|
fi
|
|
fi
|
|
done
|
|
IFS=$SAVEIFS
|
|
else
|
|
echo "Invalid option $1; aborting."
|
|
echo
|
|
usage
|
|
fi
|
|
exit 0
|