Skip to content

Instantly share code, notes, and snippets.

@lexeii
Last active January 31, 2020 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lexeii/02262b4742c6b664be925174b2aeea8b to your computer and use it in GitHub Desktop.
Save lexeii/02262b4742c6b664be925174b2aeea8b to your computer and use it in GitHub Desktop.
Use emblems in PCManFM for SliTaz

Emblem support in PCManFM

Emblem support was provided in commit Add emblem support by reading the "metadata::emblems" attribute provided by GFileInfo. and was included in the next libfm release, 1.3.0 dated 2018-04-21.

  1. Make sure you use PCManFM and LibFM not older than version 1.3.0.
  2. Put all the files from this gist in the file system. You will need root privileges to do this. Make sure the script in /usr/bin has execute permission.
  • gvfs-manage-emblems.desktop -> /usr/share/file-manager/actions/gvfs-manage-emblems.desktop
  • extended-menu.desktop -> /usr/share/file-manager/actions/extended-menu.desktop
  • gvfs-manage-emblems -> /usr/bin/gvfs-manage-emblems
  1. Make sure your icons theme contains emblems. For example, the Paper theme contains them in the /usr/share/icons/Paper/*/emblems/ folders, and the Faenza theme contains them in /usr/share/icons/Faenza/emblems/*/.
  2. Reload your PCManFM. If you do not know how to do this, restart the computer.
  3. Open PCManFM.
  4. Right click on any file or folder in file system (I repeat, this can be absolutely any file that you have access to, and even may not have write permissions).
  5. In the context menu locate the Extended Actions, and then click on Manage emblems.
  6. A dialog should open in which you can add and remove emblems for the selected file.
  7. Select the required emblems using checkboxes. Add any existing icon from the icon theme using its name by pressing "Add" button. Note, you can browse icon names using Icon Browser application. Click "Apply".
  8. Reload the folder in PCManFM (Ctrl+R). The emblems for the selected file or folder should be updated.
[Desktop Entry]
Type=Menu
ItemsList=gvfs-manage-emblems;slideshow;wallpaper;tazpkg-get;root;rootedit;
Icon=applications-system
Name=Extended
Tooltip=Extended Actions
Tooltip[ru]=Расширенные действия
#!/bin/sh
# Manage file emblems
# Tool for use with PCManFM context menu in SliTaz Linux
# Aleksey Bobylev, 24 July 2019; 31 January 2020
# Input:
# $1 - mode: 'list' (default) or 'add' - used internally
# $2 - URI of the requested file (folder); it is may be prefixed
# by 'file://' protocol like 'file:///usr/bin' or with any other supported one
# (network file stores like smb://, etc.)
# Note, user can attach an emblems to any file or folder, for example to /bin/.
mode="$1"
URI="$2"
simpleURI="$(echo -n "$URI" | sed 's|file://||')"
# Semi-random list of available emblems since it's not standardized anywhere
AVAILABLE="emblem-default emblem-favorite emblem-important emblem-shared \
emblem-documents emblem-downloads emblem-music emblem-photos \
emblem-videos emblem-mail emblem-ok emblem-link emblem-symbolic-link \
emblem-generic emblem-new emblem-urgent emblem-web \
emblem-synchronizing emblem-system emblem-readonly emblem-unreadable"
# Get emblems from the requested file (folder).
# Responce of `gvfs-info -a 'metadata::emblems' /bin` looks like:
# uri: file:///bin <- can't switch off this line using gvfs-info attributes
# attributes: <- this too, and it's translatable
# metadata::emblems: [emblem-important, emblem-system] <- what we need
EMBLEMS=" $(gvfs-info -a 'metadata::emblems' $URI \
| sed -n '/metadata::emblems:/s|.*\[||;s|,||g;s|\]||p') "
# Result is " emblem-important emblem-system " (note all the spaces!)
#notify-send "mode=«$mode» URI=«$URI» simpleURI=«$simpleURI» EMBLEMS=«$EMBLEMS»"
# Auxiliary function for Yad: make the checkboxed list
# Find the rest of emblems to support any (already set) emblems not listed above
list_emblems() {
REST="$EMBLEMS"
for i in $AVAILABLE; do
if [ "${EMBLEMS/$i /}" != "$EMBLEMS" ]; then
echo -n "true $i $i "
else
echo -n "false $i $i "
fi
REST="${REST/$i /}"
done
for i in $REST; do
echo -n "true $i $i "
done
}
# Display Yad dialog
# Unfortunately, PCManFM don't redraw its window automatically, so to see
# updated emblems user need to refresh it manually (Ctrl+R or F5)
use_list() {
new_emblems=$(yad \
--mouse --width=300 --height=400 \
--window-icon=emblem-favorite \
--title="$simpleURI emblems" \
--image=emblem-favorite --image-on-top \
--text="Select the required emblems.
<i>Refresh the folder (Ctrl+R or F5) to update the view when done.</i>" \
--button='gtk-add:2' \
--button='gtk-cancel:1' \
--button='gtk-apply:0' \
--list \
--column='Select:CHK' \
--column='Icon:IMG' \
--column='Name:TEXT' \
--always-print-result --print-column='3' --separator='' \
--checklist \
$(list_emblems) \
)
code="$?"
case $code in
0)
# Set the emblems
# New emblems should come as separate arguments, so $new_emblems isn't quoted here
# notify-send "gvfs-set-attribute \"$URI\" -t stringv metadata::emblems $new_emblems"
# URIsafe="$(echo "$URI" | sed 's|(|\\(|g;s|)|\\)|g')"
if [ -z $new_emblems ]; then
# remove all the emblems
gvfs-set-attribute $URI -t stringv metadata::emblems ''
else
gvfs-set-attribute $URI -t stringv metadata::emblems $new_emblems
fi
;;
2)
$0 add "$URI"
;;
# 1 = [Cancel], 252 = [Esc]
esac
}
# Add arbitrary icon to the emblems
use_add() {
add_emblem=$(yad \
--mouse --width=300 --height=100 \
--window-icon=emblem-favorite \
--title="Add emblem" \
--image=emblem-favorite --image-on-top \
--text="Enter icon name you want to add to emblems.
Press the find icon to browse icons installed on your system, then close the icon browser and enter icon name manually." \
--button='gtk-cancel:1' \
--button='gtk-add:0' \
--entry \
--ricon='gtk-find' \
--ricon-action='yad-icon-browser &' \
)
code="$?"
case $code in
0)
# Set the emblems
if [ -z $EMBLEMS -a -z $add_emblem ]; then
# remove all the emblems
gvfs-set-attribute $URI -t stringv metadata::emblems ''
else
gvfs-set-attribute $URI -t stringv metadata::emblems $EMBLEMS $add_emblem
fi
;;
# 1 = [Cancel], 252 = [Esc]
esac
}
case $mode in
list) use_list;;
add) use_add;;
esac
exit
[Desktop Entry]
Type=Action
Icon=emblem-favorite
Profiles=gvfs-manage-emblems;
Name=Manage emblems
Name[ru]=Управление эмблемами
[X-Action-Profile gvfs-manage-emblems]
Exec=sh -c "gvfs-manage-emblems list %u 2>&1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment