papirus-icon-theme/tools/build_color_folders.sh

195 lines
6.2 KiB
Bash
Raw Normal View History

2017-09-21 23:50:32 -04:00
#!/usr/bin/env bash
# This script creates colored folder icons
#
# Colors of the folder icon:
#
# @ - primary color
# . - secondary color
# " - color of symbol
# * - color of paper
2017-09-21 23:50:32 -04:00
#
# ..................
# ..................
# ........................................
# ..************************************..
# ..************************************..
# ..************************************..
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@""""@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@""""@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@""""@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@""""@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@""""""""""""@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@""""""""""@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@""""""@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@@""@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@""""""""""""@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
set -eo pipefail
2018-09-03 02:37:39 -04:00
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
2017-09-21 23:50:32 -04:00
TARGET_DIR="$SCRIPT_DIR/../Papirus"
DEFAULT_COLOR="blue"
SIZES_REGEX="(16x16|22x22|24x24|32x32|48x48|64x64)"
COLOR_SIZES_REGEX="(22x22|24x24|32x32|48x48|64x64)"
2017-09-21 23:50:32 -04:00
FILES_REGEX="(folder|user)-"
declare -A COLORS
COLORS=(
# [0] - primary color
# [1] - secondary color
# [2] - color of symbol
# [3] - color of paper
#
# | name | [0] | [1] | [2] | [3] |
# |----------|-------|-------|-------|-------|
2022-02-25 01:55:45 -05:00
[adwaita]=" #93c0ea #3a87e5 #3a87e5 #e4e4e4"
[blue]=" #5294e2 #4877b1 #1d344f #e4e4e4"
[black]=" #4f4f4f #3f3f3f #c2c2c2 #dcdcdc"
[bluegrey]=" #607d8b #4d646f #222c31 #e4e4e4"
2020-08-08 00:05:19 -04:00
[breeze]=" #57b8ec #147eb8 #106796 #e4e4e4"
[brown]=" #ae8e6c #957552 #3d3226 #e4e4e4"
2021-05-24 04:19:50 -04:00
[carmine]=" #a30002 #7a0002 #390001 #e4e4e4"
[cyan]=" #00bcd4 #0096aa #00424a #e4e4e4"
[darkcyan]=" #45abb7 #35818a #eaeaea #e4e4e4"
[deeporange]="#eb6637 #e95420 #522413 #e4e4e4"
[green]=" #87b158 #60924b #2f3e1f #e4e4e4"
[grey]=" #8e8e8e #727272 #323232 #e4e4e4"
[indigo]=" #5c6bc0 #3f51b5 #202543 #e4e4e4"
[magenta]=" #ca71df #b259b8 #47274e #e4e4e4"
[orange]=" #ee923a #dd772f #533314 #e4e4e4"
[palebrown]=" #d1bfae #bea389 #a38d7b #e4e4e4"
[paleorange]="#eeca8f #c89e6b #917359 #e4e4e4"
[pink]=" #f06292 #ec407a #542233 #e4e4e4"
[red]=" #e25252 #bf4b4b #4f1d1d #e4e4e4"
[teal]=" #16a085 #12806a #08382e #e4e4e4"
[violet]=" #7e57c2 #5d399b #2c1e44 #e4e4e4"
[white]=" #e4e4e4 #cccccc #4f4f4f #ffffff"
2020-05-13 23:36:51 -04:00
[yaru]=" #676767 #973552 #e4e4e4 #ff7446"
2022-02-09 23:31:47 -05:00
[yellow]=" #f9bd30 #e19d00 #594411 #e4e4e4"
[nordic]=" #81a1c1 #5e81ac #3b4253 #eceff4"
[custom]=" #value_light #value_dark #323232 #e4e4e4"
2017-09-21 23:50:32 -04:00
)
2018-09-03 02:37:39 -04:00
headline() {
2019-11-19 06:34:03 -05:00
printf "%b => %b%s\n" "\e[1;32m" "\e[0m" "$*"
}
2018-09-03 02:37:39 -04:00
msg() {
2019-11-19 06:34:03 -05:00
printf "%b [+] %b%s\n" "\e[1;33m" "\e[0m" "$*"
}
2017-09-21 23:50:32 -04:00
recolor() {
# args: <old colors> <new colors> <path to file>
2018-09-03 02:37:39 -04:00
IFS=" " read -ra old_colors <<< "$1"
IFS=" " read -ra new_colors <<< "$2"
2017-09-21 23:50:32 -04:00
local filepath="$3"
[ -f "$filepath" ] || exit 1
2019-02-21 14:02:34 -05:00
for (( i = "${#old_colors[@]}" - 1; i >= 0; i-- )); do
2017-09-21 23:50:32 -04:00
sed -i "s/${old_colors[$i]}/${new_colors[$i]}/gI" "$filepath"
done
}
2018-09-03 02:37:39 -04:00
headline "PHASE 1: Delete color suffix from monochrome icons ..."
# -----------------------------------------------------------------------------
2017-09-21 23:50:32 -04:00
find "$TARGET_DIR" -regextype posix-extended \
-regex ".*/16x16/places/${FILES_REGEX}${DEFAULT_COLOR}-.*" \
2017-09-21 23:50:32 -04:00
-print0 | while read -r -d $'\0' file; do
new_file="${file/-$DEFAULT_COLOR-/-}"
2017-09-21 23:50:32 -04:00
2018-09-03 02:37:39 -04:00
msg "'$file' is renamed to '$new_file'"
mv -f "$file" "$new_file"
2017-09-21 23:50:32 -04:00
done
2018-09-03 02:37:39 -04:00
headline "PHASE 2: Create missing symlinks ..."
# -----------------------------------------------------------------------------
find "$TARGET_DIR" -type f -regextype posix-extended \
-regex ".*/${COLOR_SIZES_REGEX}/places/${FILES_REGEX}${DEFAULT_COLOR}[-\.].*" \
-print0 | while read -r -d $'\0' file; do
2017-09-21 23:50:32 -04:00
target="$(basename "$file")"
symlink="${file/-$DEFAULT_COLOR/}"
[ -e "$symlink" ] && continue
2018-09-03 02:37:39 -04:00
msg "Creating missing symlink '$symlink' ..."
ln -sf "$target" "$symlink"
done
2018-09-03 02:37:39 -04:00
headline "PHASE 3: Generate color folders ..."
# -----------------------------------------------------------------------------
find "$TARGET_DIR" -type f -regextype posix-extended \
-regex ".*/${SIZES_REGEX}/places/${FILES_REGEX}${DEFAULT_COLOR}[-\.].*" \
2017-09-21 23:50:32 -04:00
-print0 | while read -r -d $'\0' file; do
for color in "${!COLORS[@]}"; do
[[ "$color" != "$DEFAULT_COLOR" ]] || continue
new_file="${file/-$DEFAULT_COLOR/-$color}"
cp -P --remove-destination "$file" "$new_file"
recolor "${COLORS[$DEFAULT_COLOR]}" "${COLORS[$color]}" "$new_file"
2017-09-21 23:50:32 -04:00
done
done
2018-09-03 02:37:39 -04:00
headline "PHASE 4: Create symlinks for Folder Color v0.0.80 and newer ..."
# -----------------------------------------------------------------------------
# Icons mapping
2017-09-21 23:50:32 -04:00
FOLDER_COLOR_MAP=(
# Folder Color icon | Papirus icon
# --------------------------|---------------------------
2017-09-21 23:50:32 -04:00
"folder-COLOR-desktop.svg user-COLOR-desktop.svg"
"folder-COLOR-downloads.svg folder-COLOR-download.svg"
"folder-COLOR-public.svg folder-COLOR-image-people.svg"
"folder-COLOR-videos.svg folder-COLOR-video.svg"
)
for mask in "${FOLDER_COLOR_MAP[@]}"; do
for color in "${!COLORS[@]}"; do
2018-09-03 02:37:39 -04:00
IFS=" " read -ra icon_mask <<< "$mask"
2017-09-21 23:50:32 -04:00
folder_color_icon="${icon_mask[0]/COLOR/$color}"
icon="${icon_mask[1]/COLOR/$color}"
find "$TARGET_DIR" -regextype posix-extended \
-regex ".*/${SIZES_REGEX}/places/${icon}" \
-print0 | while read -r -d $'\0' file; do
base_name="$(basename "$file")"
dir_name="$(dirname "$file")"
ln -sf "$base_name" "$dir_name/$folder_color_icon"
2017-09-21 23:50:32 -04:00
done
done
done
2018-09-03 02:37:39 -04:00
headline "PHASE 5: Copy color folder icons to derivative themes ..."
# -----------------------------------------------------------------------------
COLOR_NAMES="${!COLORS[*]}" # get a string of colors
COLOR_REGEX="(${COLOR_NAMES// /|})" # convert the list of colors to regex
DERIVATIVES=(
ePapirus
Papirus-Dark
) # array of derivative icon themes with 16x16 places
find "$TARGET_DIR" -regextype posix-extended \
-regex ".*/16x16/places/folder-${COLOR_REGEX}.*" \
-print0 | while read -r -d $'\0' file; do
for d in "${DERIVATIVES[@]}"; do
cp -P --remove-destination "$file" "${file/Papirus/$d}"
done
done