kickoffcfg: new options --update-favorite and --autoupdate-favorites

This commit is contained in:
Silvan Calarco 2016-07-06 12:41:11 +02:00
parent 80ece9b860
commit c93c27328b

View File

@ -4,19 +4,26 @@ if [ `id -u` -eq 0 ]; then
else else
CONFDIR=~/.kde4/share/config CONFDIR=~/.kde4/share/config
fi fi
XDG_APPS_DIR=/usr/share/applications
FAVORITES=`/opt/kde/bin/kreadconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs 2>/dev/null` FAVORITES=`/opt/kde/bin/kreadconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs 2>/dev/null`
[ "$1" -a "$2" ] || { function usage() {
echo "KDE4 kickoff configuration tool" echo "KDE4 kickoff configuration tool"
echo echo
echo "Usage: kickoffcfg {--add-favorite|--del-favorite} /path/to/desktopfile.desktop" 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
echo "Current favorites:" echo "Current favorites:"
echo $FAVORITES echo $FAVORITES
exit 1 exit 1
} }
[ "$1" ] || usage
if [ "$1" = "--add-favorite" ]; then if [ "$1" = "--add-favorite" ]; then
[ "$2" ] || usage
# ADD # ADD
echo "$FAVORITES" | grep $2 >/dev/null || { echo "$FAVORITES" | grep $2 >/dev/null || {
if [ "$FAVORITES" ]; then if [ "$FAVORITES" ]; then
@ -27,6 +34,7 @@ if [ "$1" = "--add-favorite" ]; then
/opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $FAVORITES /opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $FAVORITES
} }
elif [ "$1" = "--del-favorite" ]; then elif [ "$1" = "--del-favorite" ]; then
[ "$2" ] || usage
# DELETE # DELETE
MODFAVORITES=`echo "$FAVORITES" | sed "s|$2||;s|^,||;s|,,|,|"` MODFAVORITES=`echo "$FAVORITES" | sed "s|$2||;s|^,||;s|,,|,|"`
if [ ! "$MODFAVORITES" ]; then if [ ! "$MODFAVORITES" ]; then
@ -34,8 +42,40 @@ elif [ "$1" = "--del-favorite" ]; then
elif [ "$FAVORITES" != "$MODFAVORITES" ]; then elif [ "$FAVORITES" != "$MODFAVORITES" ]; then
/opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $MODFAVORITES /opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $MODFAVORITES
fi 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 else
echo "Invalid option $1; aborting." echo "Invalid option $1; aborting."
exit 1 echo
usage
fi fi
exit 0 exit 0