Commit c93c27328b58ce302af08d8f9b24d7f72b6117d5

Authored by Silvan Calarco
1 parent 80ece9b860
Exists in master

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

Showing 1 changed file with 43 additions and 3 deletions Side-by-side Diff

... ... @@ -4,19 +4,26 @@
4 4 else
5 5 CONFDIR=~/.kde4/share/config
6 6 fi
  7 +XDG_APPS_DIR=/usr/share/applications
7 8 FAVORITES=`/opt/kde/bin/kreadconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs 2>/dev/null`
8 9  
9   -[ "$1" -a "$2" ] || {
  10 +function usage() {
10 11 echo "KDE4 kickoff configuration tool"
11 12 echo
12   - echo "Usage: kickoffcfg {--add-favorite|--del-favorite} /path/to/desktopfile.desktop"
  13 + echo "Usage:"
  14 + echo " kickoffcfg {--add-favorite|--del-favorite} /path/to/desktopfile.desktop"
  15 + echo " kickoffcfg --update-favorite /path/to/old/desktopfile.desktop /path/to/new/desktopfile.desktop"
  16 + echo " kickoffcfg --autoupdate-favorites"
13 17 echo
14 18 echo "Current favorites:"
15 19 echo $FAVORITES
16 20 exit 1
17 21 }
18 22  
  23 +[ "$1" ] || usage
  24 +
19 25 if [ "$1" = "--add-favorite" ]; then
  26 + [ "$2" ] || usage
20 27 # ADD
21 28 echo "$FAVORITES" | grep $2 >/dev/null || {
22 29 if [ "$FAVORITES" ]; then
... ... @@ -27,6 +34,7 @@
27 34 /opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $FAVORITES
28 35 }
29 36 elif [ "$1" = "--del-favorite" ]; then
  37 + [ "$2" ] || usage
30 38 # DELETE
31 39 MODFAVORITES=`echo "$FAVORITES" | sed "s|$2||;s|^,||;s|,,|,|"`
32 40 if [ ! "$MODFAVORITES" ]; then
33 41  
... ... @@ -34,9 +42,41 @@
34 42 elif [ "$FAVORITES" != "$MODFAVORITES" ]; then
35 43 /opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $MODFAVORITES
36 44 fi
  45 +elif [ "$1" = "--update-favorite" ]; then
  46 + [ "$2" -a "$3" ] || usage
  47 + # UPDATE
  48 + MODFAVORITES=`echo "$FAVORITES" | sed "s|$2|$3|"`
  49 + /opt/kde/bin/kwriteconfig --file $CONFDIR/kickoffrc --group Favorites --key FavoriteURLs $MODFAVORITES
  50 +elif [ "$1" = "--autoupdate-favorites" ]; then
  51 + SAVEIFS=$IFS
  52 + IFS=","
  53 + for f in $FAVORITES; do
  54 + if [ "$f" = "$XDG_APPS_DIR/chromium-devel.desktop" ]; then
  55 + kickoffcfg --update-favorite $f $XDG_APPS_DIR/chromium.desktop
  56 + fi
  57 + if [ ! -e "$f" ]; then
  58 + DIRNAME=`dirname $f`
  59 + BASENAME=`basename $f`
  60 + BASENAME_LC=`echo $BASENAME | tr '[:upper:]' '[:lower:]'`
  61 + if [ -e $XDG_APPS_DIR/$BASENAME ]; then
  62 + echo "kickoffcfg: migrating $f to $XDG_APPS_DIR/$BASENAME"
  63 + kickoffcfg --update-favorite $f $XDG_APPS_DIR/$BASENAME
  64 + elif [ -e $XDG_APPS_DIR/org.kde.$BASENAME ]; then
  65 + echo "kickoffcfg: migrating $f to $XDG_APPS_DIR/org.kde.$BASENAME"
  66 + kickoffcfg --update-favorite $f $XDG_APPS_DIR/org.kde.$BASENAME
  67 + elif [ -e $XDG_APPS_DIR/org.kde.$BASENAME_LC ]; then
  68 + echo "kickoffcfg: migrating $f to $XDG_APPS_DIR/org.kde.$BASENAME_LC"
  69 + kickoffcfg --update-favorite $f $XDG_APPS_DIR/org.kde.$BASENAME_LC
  70 + else
  71 + echo "WARNING: favorite link $f does not exist; ignoring."
  72 + fi
  73 + fi
  74 + done
  75 + IFS=$SAVEIFS
37 76 else
38 77 echo "Invalid option $1; aborting."
39   - exit 1
  78 + echo
  79 + usage
40 80 fi
41 81 exit 0