kickoffcfg: support user mode and display current favorites when called with no arguments

This commit is contained in:
Silvan Calarco 2016-05-19 01:08:08 +02:00
parent 29dcce2550
commit 330bb09c58

View File

@ -1,14 +1,21 @@
#!/bin/sh #!/bin/sh
if [ `id -u` -eq 0 ]; then
CONFDIR=/opt/kde/share/config
else
CONFDIR=~/.kde4/share/config
fi
FAVORITES=`/opt/kde/bin/kreadconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs 2>/dev/null`
[ "$1" -a "$2" ] || { [ "$1" -a "$2" ] || {
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: kickoffcfg {--add-favorite|--del-favorite} /path/to/desktopfile.desktop"
echo echo
echo "Current favorites:"
echo $FAVORITES
exit 1 exit 1
} }
FAVORITES=`/opt/kde/bin/kreadconfig --file /opt/kde/share/config/kickoffrc --group Favorites --key FavoriteURLs 2>/dev/null`
if [ "$1" = "--add-favorite" ]; then if [ "$1" = "--add-favorite" ]; then
# ADD # ADD
echo "$FAVORITES" | grep $2 >/dev/null || { echo "$FAVORITES" | grep $2 >/dev/null || {
@ -17,15 +24,15 @@ if [ "$1" = "--add-favorite" ]; then
else else
FAVORITES="$2" FAVORITES="$2"
fi fi
/opt/kde/bin/kwriteconfig --file /opt/kde/share/config/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
# DELETE # DELETE
MODFAVORITES=`echo "$FAVORITES" | sed "s|$2||" | sed "s| ,||" | sed "s|,,|,|"` MODFAVORITES=`echo "$FAVORITES" | sed "s|$2||" | sed "s| ,||" | sed "s|,,|,|"`
if [ ! "$MODFAVORITES" ]; then if [ ! "$MODFAVORITES" ]; then
/opt/kde/bin/kwriteconfig --file /opt/kde/share/config/kickoffrc --group Favorites --key FavoriteURLs '' /opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs ''
elif [ "$FAVORITES" != "$MODFAVORITES" ]; then elif [ "$FAVORITES" != "$MODFAVORITES" ]; then
/opt/kde/bin/kwriteconfig --file /opt/kde/share/config/kickoffrc --group Favorites --key FavoriteURLs $MODFAVORITES /opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $MODFAVORITES
fi fi
else else
echo "Invalid option $1; aborting." echo "Invalid option $1; aborting."