Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Code inection like flavours #79

Open
salahoued opened this issue Nov 1, 2024 · 6 comments
Open

[Question] Code inection like flavours #79

salahoued opened this issue Nov 1, 2024 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@salahoued
Copy link

What version of tinty are you using?
tinty 0.22.0

Is there any plans to implement flavours option to inject code in a file, like

[[item]]
    file = '~/.config/starship.toml'
    template = 'starship'
    rewrite = false
    start = "### Here starts Flavours colors"
    end = "### Here ends Flavours colors"

I still use flavours to inject code to conf files that does not support imports, like for starship and swaylock.
I use tinty to generate schemes from wallpaper, and I have this flavours item in my tinty config file:

[[items]]
name = "base16-flavours"
path = "~/.local/share/tinted-theming/tinty/repos/base16-flavours"
themes-dir = "colors"
hook = "cp -r %f ~/.local/share/flavours/base16/schemes/generated/"
supported-systems = ["base16"]

then use flavours to apply the generated scheme to starship for example

Here is a script I use to to choose a wallpaper and apply generated scheme:

#!/usr/bin/env bash

currwall="$(xdg-user-dir PICTURES)/current-wallpaper"
blurwall="$(xdg-user-dir PICTURES)/blured-wallpaper"
# basedir="path/to/my/wallpapers/directory"
basedir="/usr/share/wallpapers"

function set_bg() {
    if [ "$XDG_CURRENT_DESKTOP" == "sway" ]; then
        swaymsg output "*" background "$currwall" fill
    elif ["$XDG_CURRENT_DESKTOP" == "Hyprland" ]; then
        hyprctl hyprpaper preload "$currwall"
    else
        if command -v swaybg; then
            swaybg -i "$1" &
        elif command -v hyprpaper; then
            hyperpaper "$1"
        else
            exit 2
        fi
    fi

}

image=$(fd -tf --absolute-path --base-directory "$basedir" | fzf --preview 'fzf-preview.sh {}')

if [ -f "$image" ]; then
#     tintyname=$(echo $image | awk '{l=split($0, A, /\//); gsub(/[\. ]/, "-", A[l]); print A[l] }')

    tintyname=$(basename $image | awk '{ gsub(/[\. ]/, "-"); print }')

    rm "$currwall"
    cp "$image" "$currwall"

    set_bg "$image"

    base_sys="base16"
    if [ ! -z "$1" -a "$1" == "base24" ]; then
        base_sys="$1"
    fi

    tinty generate-scheme --name $tintyname --slug $tintyname --system $base_sys --variant dark --save  $image

    tinty apply "$base_sys-$tintyname"

    # for apps that I couldn't theme with tinty
    flavours apply base16-flavours-colors-file

    accentcolor=$(grep base0E ~/.local/share/tinted-theming/tinty/custom-schemes/base16/$tintyname.yaml | awk '{print $2}' | sd "'" "")

#     plasma-apply-colorscheme -a "#$accentcolor" BreezeDark
#     plasma-apply-lookandfeel -a org.kde.breezedark.desktop

    magick "$image" -blur "50x30" "$blurwall"

    so-bg-locker.sh "image" "$currwall"

#     echo "window { background: url('$blurwall'); background-size: cover;}" > ~/.config/wleave/background.css

    exit 0

else
    exit 1
fi
@salahoued salahoued added the question Further information is requested label Nov 1, 2024
@JamyGolden
Copy link
Member

I didn’t have plans to add it but I do see the value. I’ve tended towards doing things in the “hook” property via a shell script where possible to keep things simple, however I do see the value in having this built in.

Do you have any thoughts or suggestions on the api/settings properties for this or feel that copying the Flavours implementation is the best way to add to Tinty?

@salahoued
Copy link
Author

I'm not sure about the best way to implement, but the flavours is way is tested and working.
But in the end it all depends on tinty and you maintainers in how to implement it if there are any plans to. (I don't have experience in developing and maintaining a project)

@JamyGolden
Copy link
Member

Would something like this work for you with tinty and allow you to stop using flavours?

[[items]]
path = "~/projects/tinted-theming/tinted-alacritty"
name = "tinted-alacritty"
hook = """
  # Delete lines between the comments, keeping the comments intact
  sed -i "/^# TINTY START$/,/^# TINTY END$/{//!d}" ~/.config/alacritty/colors.toml

  # Insert the contents of %f (filepath) after # TINTY START
  sed -i "/^# TINTY START$/r %f" ~/.config/alacritty/colors.toml
fi
"""
themes-dir = "colors-256"
supported-systems = ["base16", "base24"]

@salahoued
Copy link
Author

It didn't work,
I use Flavours to theme starship, swaylock and satty, but there were no modifications to their config files when using it.
Tried sed -i "/^# TINTY START$/,/^# TINTY END$/{//!d}" ~/.config/starship.toml alone and got: bash: !d}: event not found

I'm not familiar with sed, so sorry about this

@JamyGolden
Copy link
Member

Hmm I think bash is trying to expand the !. Can you try that specific command with single quotes? sed -i '/^# TINTY START$/,/^# TINTY END$/{//!d}' ~/.config/starship.toml

@salahoued
Copy link
Author

It works 'the content is removed', with the following message (sed preserves permissions for "file": operation not allowed):
sed: préserve les permissions de « /home/salo/.config/swaylock/seddILZ9v »: Opération non permise

sed -i "/^# TINTY START$/r /home/salo/.local/share/tinted-theming/tinty/base16-swaylock-colors-file.config" ~/.config/swaylock/config also works with the same message.

But when using tinty to apply a scheme it doesn't work

sed: -e expression n°1, caractère 3: expression régulière d'adresse inachevée
sed: -e expression n°1, caractère 3: expression régulière d'adresse inachevée

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants