You are not logged in.

#1 2017-10-20 07:49:03

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 3,337
Website

Switch folder colours in Papirus icon theme

The folder icons in Papirus come in a variety of colours: black,blue,brown,cyan,green,grey,magenta,orange,red,violet,yellow
The default is blue, and this is set by symlinks from eg user-home.svg to user-home-blue.svg
That blue is a bit bright, but the Papirus site currently says:

Papirus wrote:

Currently, there is no easy way to change the global color of folders. You may edit the themes by yourself if you wish.

Changing the folders to eg grey would mean rewriting all the symlinks to eg user-home-grey.svg
That's certainly easier than editing all the svg files, but there are still a lot of symlinks in there!

EDIT: please see the much improved script below.

Today I hacked together a one-liner using find to find all the symlinks that point to *-blue-* or *-blue.* and rewrite them to the grey equivalent (substitute some other colour for "grey" if you wish):

find /usr/share/icons/Papirus -type l -path '*/places/*' \( -ilname '*-blue-*' -o -ilname '*-blue.*' \) ! -iname '*-blue-*' ! -iname '*-blue.*' -exec bash -c 'echo "icon: $0"; link="$(readlink "$0")"; echo "link: $link"; newlink="${link/-blue/-grey}"; echo "newlink: $newlink"; sudo ln -sf "$newlink" "$0";echo' '{}' \;

It outputs what happened so you can go back and fix things if necessary. I tried to avoid mistakes with things like bluetooth, but if anyone tries this and hits a snag, please report back!

You'll probably want to do a

sudo update-icon-caches /usr/share/icons/*

to see the result.

EDIT: added a */places/* condition to keep it down to folders only.

Last edited by johnraff (2017-10-28 08:57:58)


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

#2 2017-10-20 10:15:46

nore
>2⁹
From: Timberland
Registered: 2015-09-29
Posts: 320

Re: Switch folder colours in Papirus icon theme

Clever!

Offline

#3 2017-10-28 08:55:52

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 3,337
Website

Re: Switch folder colours in Papirus icon theme

Here's a "proper" script to do the job. It generates a new icon theme in ~/.local/share/icons/Papirus-color (you can change the name) which holds the recoloured folder icons (symlinks actually) and inherits Papirus for everything else. You can choose to recolour folders to one of black,blue,brown,cyan,green,grey,magenta,orange,red,violet,yellow.
Run 'papirus-folder-color.sh -h' to see a usage message.
After running 'papirus-folder-color.sh' set your icon theme to Papirus-color to see the change.
And please post back if you hit any problems! roll

#!/bin/bash
# papirus-folder-color.sh
# Generate icon theme inheriting Papirus,
# but with different coloured folder icons.

new_theme='Papirus-color' # Name of new generated theme

source_dir=/usr/share/icons/Papirus
#source_dir="$PWD"

target_dir="$HOME/.local/share/icons/${new_theme}"
#target_dir=../"${new_theme}"

copy_files=false # If true, copy icons into new theme instead of symlinking.

USAGE="
papirus-folder-color.sh [color]
Where color can be one of:
black,blue,brown,cyan,green,grey,magenta,orange,red,violet,yellow
If color is not specified, it defaults to grey.

    Generates a user custom icon theme with a different folder color from
    the default Papirus blue.

papirus-folder-color.sh [-h|--help]

    Display this message.

The Papirus theme is read from /usr/share/icons/Papirus, and
the generated theme written to $HOME/.local/share/icons/${new_theme}
These paths can be changed by editing the variables
source_dir, target_dir and new_theme at the top of this file.

If copy_files=true then icons will be copied into the new theme,
not symlinked (which is the default). This increases the size,
but improves portability.

If source_dir and target_dir are under the same top-level directory
then symlinked icons will use relative paths, otherwise absolute paths.
"
########################################################################

defcolor=blue # the Papirus default

error_exit() {
    echo "$0 error: $1" >&2
    exit 1
}

[[ $(basename "$source_dir") = Papirus ]] || error_exit "$source_dir: Not a Papirus theme directory"
[[ $(basename "$target_dir") = Papirus* ]] || error_exit "$target_dir: Not a Papirus theme directory" # try to avoid accidents

case "$1" in
black|blue|brown|cyan|green|grey|magenta|orange|red|violet|yellow)
    color="$1";;
'')
    color=grey;;
-h|--help)
    echo "$USAGE"; exit;;
*)
    error_exit "$1: Unrecognized option."
esac

# Define function to make symlinks,
# relative if source & target have same top-level directory.
# If copy_files is true, copy instead of linking.
set_linking() {
    if [[ $copy_files = true ]]
    then
        link_file() { cp "$1" "$2"; }
    else
        local tld_src=$( readlink -f ${source_dir} )
        tld_src=${tld_src#/}
        tld_src=${tld_src%%/*}
        local tld_tgt=$( readlink -f ${target_dir} )
        tld_tgt=${tld_tgt#/}
        tld_tgt=${tld_tgt%%/*}
        if [[ $tld_src = $tld_tgt ]]
        then
            link_file() { ln -sfr "$1" "$2"; }
        else
            link_file() { ln -sf "$1" "$2"; }
        fi
    fi
}

set_linking

[[ -e "$target_dir" ]] && {
    echo "$target_dir will be removed and replaced, OK?"
    read -r -p ' remove? (y/n) '
    case ${REPLY^^} in
    Y|YES)
        rm -rf "$target_dir" || error_exit "Failed to remove $target_dir";;
    *)
        echo 'User cancelled. Exiting...'; exit;;
    esac
}
mkdir -p "$target_dir" || error_exit "Failed to create $target_dir"

shortdirlist=
longdirlist=
for subdir in "$source_dir"/*
do
    [[ -d ${subdir}/places && ! -h $subdir ]] || continue
    files=()
    while IFS= read -r -d '' file
    do
        files+=("$file")
    done < <(find "${subdir}/places" -type l \( -ilname "*-$defcolor-*" -o -lname "*-$defcolor.*" \) ! -iname "*-$defcolor-*" ! -iname "*-$defcolor.*" -print0)
    [[ ${#files[@]} -gt 0 ]] || continue
    dirname=${subdir##*/}
    mkdir -p "$target_dir/${dirname}/places" || error_exit "Failed to create $target_dir/${dirname}/places"
    scaledname=${dirname}@2x
    [[ $dirname != symbolic ]] && ln -s "${dirname}" "${target_dir}/${scaledname}" || error_exit "Failed to link ${target_dir}/${scaledname} to ${dirname}"
    for i in "${files[@]}"
    do
        find "${subdir}/places" -type l -lname "${i##*/}" -exec cp --no-dereference '{}' "$target_dir/${dirname}/places" \;
        target="$(readlink "$i")"
        target="${target/-${defcolor}/-${color}}"
        [[ -f "$subdir/places/$target" ]] || { echo "$subdir/places/$target: not found"; continue; }
        link_file "$subdir/places/$target" "$target_dir/$dirname/places/${i##*/}" || error_exit "Failed to link_file() $target_dir/$dirname/places/${i##*/} to $subdir/places/$target"
    done
    case "${dirname}" in
    64x64)
        shortdirlist+="${dirname}/places,${scaledname}/places,"
        longdirlist+="[${dirname}/places]
Context=Places
Size=64
MinSize=64
MaxSize=512
Type=Scalable

[${scaledname}/places]
Context=Places
Size=64
Scale=2
MinSize=64
MaxSize=512
Type=Scalable

"

        ;;
    symbolic)
        shortdirlist+="${dirname}/places,"
        longdirlist+="[${dirname}/places]
Context=Places
Size=16
MinSize=16
MaxSize=512
Type=Scalable

"

        ;;
    *)
        shortdirlist+="${dirname}/places,${scaledname}/places,"
        longdirlist+="[${dirname}/places]
Context=Places
Size=${dirname%x*}
Type=Fixed

[${scaledname}/places]
Context=Places
Size=${dirname%x*}
Scale=2
Type=Fixed

"

        ;;
    esac
done

cat <<EOF > "$target_dir/index.theme"
[Icon Theme]
Name=$new_theme
Comment=Recoloured Papirus icon theme for BunsenLabs
Inherits=Papirus,breeze,ubuntu-mono-dark,gnome,hicolor

DesktopDefault=48
ToolbarDefault=16
ToolbarSizes=16,22,32,48
MainToolbarDefault=16
MainToolbarSizes=16,22,32,48
PanelDefault=22
PanelSizes=16,22,32,48,64,128,256
FollowsColorScheme=true

# Directory list
Directories=${shortdirlist%,}

$longdirlist
EOF

gtk-update-icon-cache "$target_dir"

Last edited by johnraff (2017-11-01 06:33:01)


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

#4 2017-11-03 08:18:55

Steve
Member
Registered: 2017-01-03
Posts: 568

Re: Switch folder colours in Papirus icon theme

Thankyou for this John, seems to be working ok on my desktop.

Screenshot_2017-11-03_19-09-28.th.png

Offline

#5 2017-11-05 05:36:35

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 3,337
Website

Re: Switch folder colours in Papirus icon theme

^good news - thanks!


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Offline

#6 2017-11-06 02:58:06

DeepDayze
Member
From: In Linux Land
Registered: 2017-05-28
Posts: 243

Re: Switch folder colours in Papirus icon theme

Steve wrote:

Thankyou for this John, seems to be working ok on my desktop.

https://cdn.scrot.moe/images/2017/11/03/Screenshot_2017-11-03_19-09-28.th.png

That simple grey theme really looks nice and easy on the old eyes smile


Real Men Use Linux

Offline

Board footer

Powered by FluxBB