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

[Bug report] tinty doesn't respect custom path for custom themes #83

Open
screwyprof opened this issue Nov 18, 2024 · 5 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@screwyprof
Copy link

Describe the bug

When using a custom path for themes in config.toml, tinty still tries to find themes in the repos directory instead of using the configured custom path.

Expected behavior

Tinty should use the custom path configured in config.toml for custom themes instead of defaulting to the repos directory.

Screenshots

N/A

System

Operating system: macOS 15.1
Terminal: iterm2

Minimal configuration file

shell = "zsh -c '{}'"
default-scheme = "${theme}"
schemes-dir = "~/.local/share/tinted-theming/tinty/repos/schemes"

[[items]]
name = "bat"
path = "~/.config//tinted-theming/tinty/custom-schemes/bat"
themes-dir = "themes"
supported-systems = ["base16", "base24"]
hook = "cp -f %f ~/.config/bat/themes/gopher.tmTheme && bat cache --build"

Additional context

❯ tinty apply base24-dracula
Error: Failed to apply theme ""base24-dracula""

Caused by:
    Provided theme path for bat does not exist: /Users/happygopher/.local/share/tinted-theming/tinty/repos/bat/themes
    Try running `tinty install` or `tinty update` or check your config.toml file and try again.

❯ ls -al ~/.config/tinted-theming/tinty/custom-schemes
lrwxr-xr-x@ - happygopher 18 Nov 03:59  bat -> /nix/store/ffb4vis6bbd09b2vpkk551z81qswawcb-home-manager-files/.config/tinted-theming/tinty/custom-schemes/bat

❯ ls -al /nix/store/ffb4vis6bbd09b2vpkk551z81qswawcb-home-manager-files/.config/tinted-theming/tinty/custom-schemes/bat/themes
.r--r--r--@ 31k root  1 Jan  1970  base24-gopher.tmTheme
@screwyprof screwyprof added the bug Something isn't working label Nov 18, 2024
@screwyprof screwyprof changed the title [Bug report] [Bug report] tinty doesn't respect custom path for custom themes Nov 18, 2024
@screwyprof
Copy link
Author

Also, I'm not sure whether it is by design or not, but at the moment it's not possible to set different themes for different items. What if for shell I wanted one theme and for bat another?

@screwyprof
Copy link
Author

screwyprof commented Nov 18, 2024

For the context, I'm trying to marry nix-darwin with home-manager and tinty. I created a custom package for tinty (btw, would really great if tinty could support it in the main nix repo). And I have a file to configure my themes which looks like this:

Click to view the full nix config
{ config, lib, pkgs, ... }:
let
  #theme = "base24-flat";
  #theme = "base24-one-dark";
  theme = "base24-dracula";

  tinted-schemes = pkgs.fetchFromGitHub {
    owner = "tinted-theming";
    repo = "schemes";
    rev = "spec-0.11";
    sha256 = "sha256-Tp1BpaF5qRav7O2TsSGjCfgRzhiasu4IuwROR66gz1o=";
  };

  tinted-shell = pkgs.fetchFromGitHub {
    owner = "tinted-theming";
    repo = "tinted-shell";
    rev = "60c80f53cd3d97c25eb0580e40f0b9de84dac55f";
    sha256 = "sha256-eyZKShUpeIAoxhVsHAm2eqYvMp5e15NtbVrjMWFqtF8=";
  };

  tinted-fzf-src = pkgs.fetchFromGitHub {
    owner = "tinted-theming";
    repo = "tinted-fzf";
    rev = "7646a7e697767271d3dd059bbd9c267163d030a3";
    sha256 = "sha256-Hoj5ib7cOwuuRmOHJd1SyCeyBoMrNTsrqrWgN955zJM=";
  };

  # Create a patched version of tinted-fzf with theme symlinks in ansi/
  tinted-fzf = pkgs.runCommand "tinted-fzf-patched" { } ''
    cp -r ${tinted-fzf-src} $out
    chmod -R +w $out

    cd $out
    mkdir -p ansi-sh
   
    for theme in sh/base16-*.sh sh/base24-*.sh; do
      name=$(basename "$theme")
      ln -s ../ansi/ansi.sh "ansi-sh/$name"
    done
  '';

  # Create bat themes directory with our custom Gopher theme
  gopher-bat = pkgs.runCommand "gopher-bat" { } ''
    mkdir -p $out/themes
    cp ${./Gopher.tmTheme} $out/themes/${theme}.tmTheme
  '';

  # Assert that a path exists or throw an error
  assertPath = path:
    assert builtins.pathExists path;
    path;
in
{
  home = {
    packages = [ pkgs.tinty ];
    file = {
      "${config.xdg.dataHome}/tinted-theming/tinty/repos/schemes".source = assertPath tinted-schemes;
      "${config.xdg.dataHome}/tinted-theming/tinty/repos/tinted-shell".source = assertPath tinted-shell;
      "${config.xdg.dataHome}/tinted-theming/tinty/repos/fzf".source = assertPath tinted-fzf;

      "${config.xdg.dataHome}/tinted-theming/tinty/repos/bat".source = assertPath gopher-bat;

      "${config.xdg.configHome}/zsh/colors.sh".source = assertPath "${tinted-shell}/scripts/${theme}.sh";
      "${config.xdg.configHome}/fzf/colors.sh".source = assertPath "${tinted-fzf}/ansi/ansi.sh";
      "${config.xdg.configHome}/bat/themes/${theme}.tmTheme".source = assertPath ./Gopher.tmTheme;
    };
  };

  programs.zsh = {
    envExtra = lib.mkAfter ''
      # fzf theme
      [ -f ~/.config/fzf/colors.sh ] && source ~/.config/fzf/colors.sh

      # bat theme
      if [[ -f ~/.config/bat/themes/${theme}.tmTheme ]]; then
        export BAT_THEME="${theme}"
      fi
    '';

    initExtra = lib.mkAfter ''
      # bat theme
      # Only rebuild cache if the theme isn't in the themes list
      if ! bat --list-themes | grep -q "${theme}"; then
        bat cache --build
      fi
    '';
  };


  xdg.configFile = {
    "tinted-theming/tinty/config.toml".text = ''
        shell = "zsh -c '{}'"
      default-scheme = "${theme}"
      schemes-dir = "${config.xdg.dataHome}/tinted-theming/tinty/repos/schemes"

      [[items]]
      name = "tinted-shell"
      path = "${config.xdg.dataHome}/tinted-theming/tinty/repos/tinted-shell"
      themes-dir = "scripts"
      hook = "cp -f %f ~/.config/zsh/colors.sh && source ~/.config/zsh/colors.sh"
      supported-systems = ["base16", "base24"]

      [[items]]
      name = "fzf"
      path = "${config.xdg.dataHome}/tinted-theming/tinty/repos/fzf"
      themes-dir = "ansi-sh"
      supported-systems = ["base16", "base24"]
      hook = "cp -f %f ~/.config/fzf/colors.sh && source ~/.config/fzf/colors.sh"

      [[items]]
      name = "bat"
      path = "${config.xdg.dataHome}/tinted-theming/tinty/repos/bat"
      themes-dir = "themes"
      supported-systems = ["base16", "base24"]
      hook = "cp -f %f ~/.config/bat/themes/${theme}.tmTheme && bat cache --build"
    '';
  };
}

@screwyprof
Copy link
Author

Tinty pkg looks like this:

{ lib
, rustPlatform
, fetchFromGitHub
}:

rustPlatform.buildRustPackage rec {
  pname = "tinty";
  version = "0.23.0";

  src = fetchFromGitHub {
    owner = "tinted-theming";
    repo = "tinty";
    rev = "v${version}";
    sha256 = "sha256-5KrXvE+RLkypqKg01Os09XGxrqv0fCMkeSD//E5WrZc=";
  };

  cargoHash = "sha256-qTHlSP9WN39KgU7Q/4/iS1H2XOikXiCAiZ/NSAFS9mM=";

  # TODO(fix testsDisable tests for now as they require specific CI setup
  doCheck = false;

  # If we want to enable tests later, we'll need to:
  # 1. Set up proper environment variables
  # 2. Create test fixtures
  # 3. Run tests in single thread mode
  # As shown in .github/workflows/test.yml

  # Configure tests to run one at a time and with proper setup
  #   checkPhase = ''
  #     # Create test fixtures
  #     ./scripts/create_fixtures

  #     # Run tests with single thread
  #     cargo test --release --all-targets --all-features -- --test-threads=1
  #   '';

  meta = with lib; {
    description = "A theme manager for tinted-theming";
    homepage = "https://github.com/tinted-theming/tinty";
    license = licenses.mit;
    maintainers = [ ];
  };
}

For some reason when building from sources tests fail...

@JamyGolden
Copy link
Member

Tinty symlinks the custom path added to the tinty config to ~/.config/tinted-theming/tinty/repos/fzf for example. So even after you add a path to tinty that is local, you need to run “tinty sync” or “tinty install” to create those symlinks. Could this maybe be the issue you’re having in that situation?

Also, I'm not sure whether it is by design or not, but at the moment it's not possible to set different themes for different items. What if for shell I wanted one theme and for bat another?

Yeah this is true, right now. It’s by design because no one has mentioned wanting to do it differently. I wouldn’t be opposed to building something like this in though.

I’m very keen on having integrated into nix well. I’m actually busy converting my dotfiles repo install scripts to nix home-manager, but I’m still very new to it and figuring a lot of things out. Thanks for adding the nix package script here, I’ll look at adding it to the main nix repo.

@screwyprof
Copy link
Author

With nix at this stage tinty is redundant to be honest :-D I mean it doesn't make theme-configuring any easier. So looking at the example above if we removed tinty config, nothing would change - theming still would work. To make tinty actually useful we should keep in mind that nix has a read only /nix/store. So configs must be generated once and then should be managed by nix. What tinty could do to make life a bit easier is to probably orchestrate different shell/apps setups and somehow make configs easier to use in nix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants