Skip to content

Commit

Permalink
Fixed auto-reload and improved script
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmitar committed Jan 20, 2015
1 parent 98ec881 commit 14b575f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 43 deletions.
2 changes: 1 addition & 1 deletion deinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Version: 1.3
# Version: 1.4
# DEINSTALL: Only run this script

shopt -s extglob
Expand Down
4 changes: 2 additions & 2 deletions dolphin-folder-color.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
100 changes: 63 additions & 37 deletions dolphin-folder-color.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

# Copyright (C) 2014 Smith AR <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
Expand All @@ -16,9 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# 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 <ICON_NAME> [PATH1] [PATH2] ...
# <ICON_NAME>: is a color or any other folder-$icon or freedesktop icon
#########################################################################

shopt -s extglob
icon=${1:?'Name or color icon is not present'} ; shift
Expand All @@ -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

Expand All @@ -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
###
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# Version: 1.3
# Version: 1.4
# INSTALL: Only run this script

shopt -s extglob
Expand Down
4 changes: 2 additions & 2 deletions plasma5-folder-color.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 14b575f

Please sign in to comment.