From 14b575f387d01be869dbd6a95430d3b7f0a12db1 Mon Sep 17 00:00:00 2001 From: audoban Date: Mon, 19 Jan 2015 23:08:32 -0500 Subject: [PATCH] Fixed auto-reload and improved script --- deinstall.sh | 2 +- dolphin-folder-color.desktop | 4 +- dolphin-folder-color.sh | 100 ++++++++++++++++++++++------------- install.sh | 2 +- plasma5-folder-color.desktop | 4 +- 5 files changed, 69 insertions(+), 43 deletions(-) diff --git a/deinstall.sh b/deinstall.sh index 9e550ca..b26262e 100755 --- a/deinstall.sh +++ b/deinstall.sh @@ -16,7 +16,7 @@ # along with this program. If not, see . # # -# Version: 1.3 +# Version: 1.4 # DEINSTALL: Only run this script shopt -s extglob diff --git a/dolphin-folder-color.desktop b/dolphin-folder-color.desktop index 4d6a086..0f44c7a 100755 --- a/dolphin-folder-color.desktop +++ b/dolphin-folder-color.desktop @@ -2,13 +2,13 @@ Name=Folder Color Encoding=UTF-8 -Version=1.3 +Version=1.4 Icon=folder-red Type=Service ServiceTypes=KonqPopupMenu/Plugin MimeType=inode/directory; -X-KDE-Submenu=Color folder +X-KDE-Submenu=Folder Color X-KDE-Submenu[es]=Color X-KDE-Submenu[fr]=Dossier de couleur X-KDE-Submenu[it]=Cartella colori diff --git a/dolphin-folder-color.sh b/dolphin-folder-color.sh index dc8d131..38c6107 100755 --- a/dolphin-folder-color.sh +++ b/dolphin-folder-color.sh @@ -1,5 +1,4 @@ #!/bin/bash - # Copyright (C) 2014 Smith AR # # This program is free software: you can redistribute it and/or modify @@ -16,9 +15,12 @@ # along with this program. If not, see . # # -# Version 1.3 -# dolphin-folder-color.sh ICON_NAME PATH1 PATH2 ... -# name: is a color or any other folder-$icon or freedesktop icon +# Version 1.4 + +### USAGE: +# dolphin-folder-color.sh [PATH1] [PATH2] ... +# : is a color or any other folder-$icon or freedesktop icon +######################################################################### shopt -s extglob icon=${1:?'Name or color icon is not present'} ; shift @@ -27,39 +29,46 @@ tmp=$TMPDIR/$desktopEntry-$PPID case $icon in - default | black | blue | brown |\ - cyan | green | grey | orange |\ - red | violet | yellow |\ - bookmark | remote | tar | sound |\ - temp | txt | text | video | videos |\ - activities | development | documents | html |\ - favorites | download | downloads | locked |\ - image | images | image-people | important |\ - network | templates | public | publicshare | print ) - - if [ $icon != 'default' ] ; then - icon="folder-$icon" - fi -;; custom ) - icon=$(kdialog --caption 'Folder Color' --title 'Select Icon' \ - --geticon Desktop Place 2> /dev/null) - if [ ${#icon} = 0 ] - then exit - fi -;; *) - if ! [ -f $(kiconfinder $icon) ] ; then - icon="default" - fi + default | black | blue | brown |\ + cyan | green | grey | orange |\ + red | violet | yellow |\ + bookmark | remote | tar | sound |\ + temp | txt | text | video | videos |\ + activities | development | documents | html |\ + favorites | download | downloads | locked |\ + image | images | image-people | important |\ + network | templates | public | publicshare | print ) + + if [ $icon != 'default' ] ; then + icon="folder-$icon" + fi + ;; custom ) + icon=$(kdialog --caption 'Folder Color' --title 'Select Icon' \ + --geticon Desktop Place 2> /dev/null) + if [ ${#icon} = 0 ] + then exit + fi + ;; *) + if ! [ -f $(kiconfinder $icon) ] ; then + icon="default" + fi esac -for dir in "$@" ; do - cd "$dir" - tag=$(grep 'Icon=.*' $desktopEntry) - header=$(grep '\[Desktop Entry\]' $desktopEntry) - if [ -d "$dir" ] && [ -w $desktopEntry ] && [ -n "$(< $desktopEntry)" ] ; then - icon=${icon//+(\/)/\\/} +for dir in "$@" ; do + if [ -d "$dir" ] ; then + cd "$dir" + else + echo "Directory not found: $dir" ; continue + fi + + if [ -w $desktopEntry ] && [ -n "$(< $desktopEntry)" ] ; then + + tag=$(grep 'Icon=.*' $desktopEntry) + header=$(grep '\[Desktop Entry\]' $desktopEntry) + icon=${icon//+(\/)/\\/} ##syntax ${parameter//pattern/string} + if [ $icon = 'default' ] ; then sed '/Icon=.*/d' $desktopEntry > $tmp @@ -82,12 +91,29 @@ for dir in "$@" ; do cat $tmp > $desktopEntry rm $tmp - elif [ -d "$dir" ] && [ $icon != 'default' ] ; then + elif [[ $icon != 'default' ]] ; then echo -e "[Desktop Entry]\nIcon=$icon" > $desktopEntry fi - + + ## Return to parent directory + cd .. done -service="org.kde.dolphin-$PPID" +# Reload the Dolphin windows with qdbus method='/dolphin/Dolphin_1/actions/reload org.qtproject.Qt.QAction.trigger' -qdbus $service $method &> /dev/null +service='org.kde.dolphin-' +reloaded=false + +for pid in $(pidof "dolphin") ; do + if [ $pid = $PPID ] ; then + qdbus $service$PPID $method &> /dev/null + reloaded=true + fi +done + +if ! $reloaded ; then + for pid in $(pidof "dolphin") ; do + qdbus $service$pid $method &> /dev/null + done +fi +### diff --git a/install.sh b/install.sh index 51931ed..0fe3fb9 100755 --- a/install.sh +++ b/install.sh @@ -16,7 +16,7 @@ # along with this program. If not, see . # # -# Version: 1.3 +# Version: 1.4 # INSTALL: Only run this script shopt -s extglob diff --git a/plasma5-folder-color.desktop b/plasma5-folder-color.desktop index 6179b71..b0ecb83 100755 --- a/plasma5-folder-color.desktop +++ b/plasma5-folder-color.desktop @@ -2,13 +2,13 @@ Name=Folder Color Encoding=UTF-8 -Version=1.3 +Version=1.4 Icon=folder-cyan Type=Service ServiceTypes=KonqPopupMenu/Plugin MimeType=inode/directory; -X-KDE-Submenu=Color folder +X-KDE-Submenu=Folder Color X-KDE-Submenu[es]=Color X-KDE-Submenu[fr]=Dossier de couleur X-KDE-Submenu[it]=Cartella colori