Created
January 25, 2024 14:35
-
-
Save Sythelux/4ff6e736237d203802f9430484d76e37 to your computer and use it in GitHub Desktop.
Cinnamon Folder Thumbnailer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# LICENSE: BSD3-Clause | |
# made by Sythelux Rikd | |
# DESC: this script creates a montage of images within a folder to create a folder icon for nemo | |
# it respects folder.jpg and .folder.jpg being set | |
# it is rather imperformant, maybe someone will improve it. | |
# needs to be put into /usr/bin/folder-thumbnailer | |
# echo $1 $2 $3 $4 | |
IFS=$'\n' | |
# TODO: would be cool to have an early stop similar to functional programming where you can have an enumerator and then take 4 and that is it. | |
files=($(find "$2" -maxdepth 2 -type f | | |
file --mime-type -f - | | |
grep -F image/ | | |
rev | cut -d : -f 2- | rev | |
)) | |
inset=$(($1/8)) | |
border=$(($1/16)) | |
# TODO: | |
# 1. find some programm that get's an icon for name | |
# 2. lookup folder icon | |
# 3. use folder icon as bg or at least extract the median or average color from folder icon to set as BG | |
BG='#0096f3' | |
#THEME=$(gsettings get org.gnome.desktop.interface icon-theme | tr -d "'") | |
#THEME=$(gsettings get org.cinnamon.desktop.interface icon-theme | tr -d "'") | |
#FOLDER_ICON="$HOME/.themes/${THEME}/places/$1/folder.svg" | |
# FOLDER_ICON="/usr/share/icons/.themes/${THEME}/places/$1/folder.svg" | |
#FOLDER_ICON="$HOME/.local/share/icons/folder.png" | |
convert -thumbnail "$1" "$2/folder.jpg" "$3" 1>/dev/null 2>&1 ||\ | |
convert -thumbnail "$1" "$2/.folder.jpg" "$3" 1>/dev/null 2>&1 ||\ | |
montage -tile 2x2 -background "$BG" -geometry $1x$1+$inset+$inset -border $border -shadow "${files[0]}" "${files[1]}" "${files[2]}" "${files[3]}" "$3" ||\ | |
montage -tile 2x2 -background "$BG" -geometry $1x$1+$inset+$inset -border $border -shadow "${files[0]}" "${files[1]}" "${files[2]}" "$3" ||\ | |
montage -tile 2x2 -background "$BG" -geometry $1x$1+$inset+$inset -border $border -shadow "${files[0]}" "${files[1]}" "$3" ||\ | |
montage -tile 2x2 -background "$BG" -geometry $1x$1+$inset+$inset -border $border -shadow "${files[0]}" "$3" ||\ | |
rm -f "$HOME/.cache/thumbnails/normal/$(echo -n "$4" | md5sum | cut -d " " -f1).png" ||\ | |
rm -f "$HOME/.thumbnails/normal/$(echo -n "$4" | md5sum | cut -d " " -f1).png" ||\ | |
rm -f "$HOME/.cache/thumbnails/large/$(echo -n "$4" | md5sum | cut -d " " -f1).png" ||\ | |
rm -f "$HOME/.thumbnails/large/$(echo -n "$4" | md5sum | cut -d " " -f1).png" ||\ | |
exit 1 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Thumbnailer Entry] | |
Version=1.0 | |
Encoding=UTF-8 | |
Type=X-Thumbnailer | |
Name=Folder Thumbnailer | |
MimeType=inode/directory; | |
Exec=/usr/bin/folder-thumbnailer %s %i %o %u | |
# needs to be put into /usr/share/thumbnailers you also might have to remove this line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment