Giter VIP home page Giter VIP logo

base16-universal-manager's Introduction

Build Status GoDoc Go Report Card codecov HitCount

Base16

About

Base16 Universal Manager

Gets a base16 colorscheme the configured templates from the official repos and renders them out to the given locations It will use the levenstein distance to find the matching colorscheme from the supplied name.

Base16 themes

An architecture for building themes based on carefully chosen syntax highlighting using a base of sixteen colors. Base16 provides a set of guidelines detailing how to style syntax and how to code a builder for compiling Base16 schemes and templates.

Why another manager/builder?

Base16 themes look great and the fact that you can use them on a lot of different applications makes it easy to get a desktop configuration set up easealy that looks uniformly themed. I really like the idea of having theme colors and the templates for different applications separated.

The common workflow to set up a theme on your system looks like this in most cases:

  1. Search for a theme you like
  2. Scroll through the support list of supported applications to find all the ones you need
  3. Download or build the theme files for every application
  4. Copy them all in their respective places.
  5. Restart or refresh every application

I found this pretty tedious to do, since I like to change my theme every now and then. This is where the need for a manager came up.

The idea: automate the complete workflow above. After setting up my configuration for the manager once I ideally want to run one command and have all my applicatins set-up and ready whith the theme I choose.

There are other projects that try to simplify this workflow, but I have had problems with them in the past and don't particulary like the designs. Setting a theme should not require me to download or build them all. It also should really set them, avoiding having to run a theme-setting script every time the application is started.

What Base16 Universal Manager is NOT

Even though this project builds the themes needed and could probably be expanded or used as a theme builder in the sense described in the official base16 guidelines, this is not what it is intended for. It is mainly aimed at users and not theme or template maintainers and desigend to only get and build the stuff the user really needs.

Similar projects

base16-shell A shell script to change your shell's default ANSI colors

I liked the idea, but it limits the use to command line applications. Also I found the script to be to slow on my system, which results in the colors of new terminals been changed about ~0.5s after start. In the meantime my terminal waits. There probably are usecases, where this is the better choice, but it was not what I was looking for.

base16-manager A command line tool to install base16 templates and set themes globally.

Even though this project aimed to provide the same funcionality, only very few applications are supported. Also it required me to download a lot of repos I will never use.

Installation

At the moment, you can only build and install this with go. You can install it directly or build it from source. I might provide packages for multiple linux distributions and pre-build binaries in the future.

Install directly

mkdir -p "$(go env GOPATH)/src"
go install github.com/pinpox/base16-universal-manager@latest

Get source and build manually

go get github.com/pinpox/base16-universal-manager
cd $GOPATH/src/github.com/pinpox/base16-universal-manager
go build

If you get errors on missing dependencies, install them as usual with go get.

Shell completions

  • fish shell completions: Add the completions/fish/base16-universal-manager.fish to ~/.config/fish/completions/

    wget https://raw.githubusercontent.com/pinpox/base16-universal-manager/master/completions/fish/base16-universal-manager.fish -O ~/.config/fish/completions/base16-universal-manager.fish
    

Usage

To run, just execute the application without any command line flags. It will expect a config.yaml (example provided) in $XDG_CONFIG_HOME/.config/base16-universal-manager/ ($XDG_CONFIG_HOME defaults to ~/.config on *nix systems if unspecified) and renders all specified application templates with the selected colorscheme.

The following flags are planned and will be implemented soon:

usage: base16-universal-manager [<flags>]

Flags:
  --help             Show context-sensitive help (also try --help-long and --help-man).
  --update-list      Update the list of templates and colorschemes
  --clear-list       Delete local master list caches
  --clear-schemes    Delete local scheme caches
  --clear-templates  Delete local template caches
  --version          Show application version.

Configuration

GitHub Token (optional)

This program fetches data using the GitHub API. If you are not logged in, you might get blocked by the API's rate limiting

To increase the amout of allowed request, you can use personal access-token. Generate one here (Default options should be enough, just provide a name) and put it in your configuration file.

Putting the token in the configuration will automatically use it to make all requests as a registered user.

Configuration file

The configuration file specifies everything the program should do when run. It consists mainly of two parts:

General configuration values

Variable Default Explanation
GithubToken set-your-token-here see GitHub Token (optinonal)
Colorscheme flat.yml The colorscheme to use, uses local path if it contains a /
DryRun false Print the rendered files to stdout instead of saving them

The provided theme names, do not have to be exact. The Levenstein distance is used to calculate the best matching option. This is handy in case you only partly remember the name of a particular scheme, if you made a typo, or if you are just plain lazy.

Applications which you want to theme

The rest of the configuration are the application specific settings. It consists of a list of applications you want to use. Here is an example that would set up vim and i3 for you:

applications:
  i3:
    enabled: true
    hook: i3-msg 'restart'
    files:
      default:
        path: ~/.i3/i3_colors/
        mode: rewrite
      bar-colors:
        path: ~/.i3/i3_bar_colors/
        mode: rewrite
  vim:
    enabled: true
    files:
      default:
        path: ~/.vim/vim_colors/
        mode: rewrite

In this configuration we render the files called default and bar-colors from the base16-i3 templates repository to a to ~/.i3/i3_colors and ~/.i3/i3_bar_colors as well as the file called default from the base16-vim templates repo to ~/.vim/vim_colors. In the configurations of those applications you could then source that generated files.

Note: the convention for path is that if it ends with a / the rendered file will be placed in the directory path (it will be created if it doesn't exist). If it doesn't end with a / then path specifies exactly where the renered file should be placed. For example the above config will create/rewrite the following files:

  • ~/.i3/i3_colors/default.config
  • ~/.i3/i3_bar_colors/bar-colors.config
  • ~/.vim/vim_colors/default.vim

Some applications have limitations in their configuration files and cannot source other configuration files. In that case rewriting the file won't help. That's why there is another mode called replace. Here's an example config demonstating this:

applications:
  alacritty:
    enabled: true
    files:
      default:
        path: ~/.config/alacritty/alacritty.yml
        mode: replace
        start_marker: "# <<<<<<<<<<"
        end_marker: "# >>>>>>>>>>"

With this configuration the rendered colors will be placed between the lines # <<<<<<<<<< and # >>>>>>>>>> in ~/.config/alacritty/alacritty.yml. Note that start_marker and end_marker are regexes and do not have to match exactly.

The hook variable can be set for every application configured. It allows to run a command after the files have been rendererd, e.g. to refersh the application in order to show the new values. In this example we use i3-msg 'restart' to restart the i3 window manager in place, thus reloading the colors.

Application examples

Base16 Universal Manager can support all applications listed in the base16 repo. For application-specific integration examples see the list in the wiki

Contributing

I hacked this project together in a weekend and it grew to be bigger than expected. The code quality could be way better and even though it is already pretty usable, you might find bugs or other issues. The documentation is work-in-progress.

Issues, bug-reports, pull requests or ideas for features and improvements are very welcome. Also it would be great if users of specific applications can document the usage of their respective templates, as I don't use all of them and can't/won't test the integration for every single application.

base16-universal-manager's People

Contributors

combro2k avatar forrestli74 avatar jo1gi avatar justinretzolk avatar korrat avatar lhanson avatar mathisto avatar nvlbg avatar paul-ri avatar phytolizer avatar pinpox avatar weslem avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

base16-universal-manager's Issues

Github API rate limit makes first time installation impossible

Hey,

I tried do clean install on this and it seems like the initial install panics due to githubs rate limit (which is 60 requests in one hour(?))

On top of that, you don't even get the first 60 installed, because the app panics when the first limited request hits.

Not sure if this can be worked around by installing the themes in batches, but in any case, the error handler has to be bettered so that the app doesn't panic when the rate limit hits - Or at least there needs to be some clarity on why the error happens.

You can get your rate quota with: curl https://api.github.com/rate_limit (core object)

It returns:

{
  "resources": {
    "core": {
      "limit": 60,
      "remaining": 0,
      "reset": 1652448505,
      "used": 60,
      "resource": "core"
    },
...
}

Rework path handling

So I've added my intended cache directories in my config.yaml as

SchemesListFile: "~/.cache/base16/schemeslist.yaml"
TemplatesListFile: "~/.cache/base16/templateslist.yaml"
SchemesCachePath: "~/.cache/base16/schemes/"
TemplatesCachePath: "~/.cache/base16/templates/"

Yet, when I run base16-universal-manager, it turns out that a literal directory \~ is created in my current working directory instead of it referring to $HOME (which doesn't work either when used in the path strings above). Funny enough, I then replaced ~ in the config with the full, absolute path starting with /home, and even then a literal directory home was created as well!

Additionally, it shouldn't be necessary for the user to supply their own caches in the first place. It would be better if you only had a single, dedicated cache directory that would by default be something like $HOME/.cache/base16/ and have this directory applied to everything listed in the snippet above. From there, you could then allow the user to specify a new cache directory in config.yaml if they need it.

Also, speaking of config.yaml, you should also have a dedicated, default location for it in something like $HOME/.config/base16/ rather than require the user to specify a custom location each time in the program's invocation. (I know you can set an alias, but that's not fair for you to require this when it could easily be resolved with good defaults).

support for specifying the scheme as a local file

basically i want to invoke base16-universal-manager --scheme ~/.config/base16-universal-manager/schemes/custom.yaml or similar and have it point to a local file instead of fetching the color scheme from github.

i'm not very well versed in go so i'm using a patch rn that just changes the behavior of --scheme to only read local files

Implement mechanism to replace a block instead of rewriting the file

Some of the base16-supported applications have no mechanism to source other configuration files from the main config, e.g. applications that are configured via YAML.
For the apps that don't allow for a source or include statement in their configuration it would be nice to be able to place a specially marked block in their config that is replaced with the newly generated content instead of rewriting the whole file

e.g. for a YAML file:

value1: foo
value2: bar

# BEGIN BASE16 MANAGED BLOCK
color1: 333333
color2: 444444
# END BASE16 MANAGED BLOCK

value3: baz

The mechanism should then just substitute the marked block

Support for multiple applications with the same template

I was wondering if it should be possible to add multiple applications per template since some applications use the same template (e.g. vim and neovim or anything that uses css). It could be done by adding a "template" option which would overwrite the normal template.

Add flag to print configuration

It would be useful to be able to print current configuration without uncommenting and recompiling the application here . Perhaps there could be a --print-config option that does this on demand.

Unmarshal Errors

When I run the software i keep getting unmarshall errors for my default config files

โžœ  ~ base16-universal-manager --scheme dracula
panic: yaml: unmarshal errors:
  line 68: cannot unmarshal !!str `~/.conf...` into main.FileConfig

goroutine 1 [running]:
main.check(...)
        /home/c3lphie/go/src/github.com/pinpox/base16-universal-manager/main.go:206
main.NewConfig(0xc00001a4c0, 0x3a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/c3lphie/go/src/github.com/pinpox/base16-universal-manager/config.go:58 +0x55e
main.main()
        /home/c3lphie/go/src/github.com/pinpox/base16-universal-manager/main.go:39 +0x78

Here is a snippet of my config where the problem occures

    dunst:
        enabled: false 
        mode: rewrite
        hook: ""
        files:
          default: "~/.config/dunst/dunstrc"

I use arch btw ;)

I hope i can get some help with this :)

Typo in usage.

In the usage text, the descriptions for --clear-templates and --clear-schemes are swapped.

Contributing to wiki

Hi,

I'm going through some apps I use and create entries for them on wiki. However, since it's not part of the original repo, I'm not sure how to contribute. Do you want this contribution? If so, how should I proceed?

Applications' "enabled" property is ignored

In config.yaml, the enabled property of each application is not used.
For example, using the sample configuration, the program processes all applications regardless of the enabled properties being set to false:

**[CONFIG]: Selected scheme:  Flat
[RENDER]: Rendering template "c_header"
    - (dryrun) file would be written to:  /default.h
Not running hook, DryRun enabled:  
[RENDER]: Rendering template "crosh"
    - (dryrun) file would be written to:  /default.js
    - (dryrun) file would be written to:  /default-16.16.js
Not running hook, DryRun enabled:  
[RENDER]: Rendering template "emacs"
    - (dryrun) file would be written to:  /default-theme.el
Not running hook, DryRun enabled:**
...

GitHub API deprecation notice

Hi @xieve,

On July 19th, 2020 at 08:56 (UTC) your personal access token (base16-universal-manager) using Go-http-client/1.1 was used as part of a query parameter to access an endpoint through the GitHub API:

https://api.github.com/repositories/99037070/contents/

Please use the Authorization HTTP header instead, as using the access_token query parameter is deprecated. If this token is being used by an app you don't have control over, be aware that it may stop working as a result of this deprecation.

Depending on your API usage, we'll be sending you this email reminder on a monthly basis for each token and User-Agent used in API calls made on your behalf.
Just one URL that was accessed with a token and User-Agent combination will be listed in the email reminder, not all.

Visit https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param for more information about suggested workarounds and removal dates.

Thanks,
The GitHub Team

I'm not sure if this is an error on your side or on a libraries? Anyway I thought I'd report it.

Wiki config updates: dunst,i3,foot,mako,rofi,shell,termite,xresources & update vim

Hi, thanks for your program! I've migrated from base16-manager. Yours is much more flexible!

I've pushed some wiki updates on a fork of your wiki on https://github.com/paul-ri/base16-universal-manager/wiki/Configuration-examples

As stated in another issue, you can update with

git clone https://github.com/pinpox/base16-universal-manager.wiki
git pull https://github.com/paul-ri/base16-universal-manager.wiki.git
git push

The vim entry is a bit controversial as I found it wasn't so straightforward to make it work with the base16-vim plugin.

I hope that helps.

Happy to edit some bits if needed

Nix Package

I forgot to tell you that the nix package I created for base16-universal-manager is now in the official repos.

unsupported protocol scheme ""

Hi @binaryplease , and thanks for working on this manager. I look forward to seeing it become more adopted by base16 users and see an aur package for it.

I tried to install the package, but faced several issues.
Solved:

  • needed to mkdir ~/go/src before running go install
  • The executable in ~/go/bin/ is base16-universal-manager and not base16-setter

Not solved:

  • running base16-universal-manager fails with error "unsupported protocol scheme"
$ base16-universal-manager
No templates in list, pulling new one...
panic: Get ?access_token=<mytoken>: unsupported protocol scheme ""

goroutine 1 [running]:
main.check(...)
        /home/dori/go/src/github.com/binaryplease/base16-universal-manager/main.go:150
main.(*Base16ColorschemeList).UpdateSchemes(0xc0000afc00)
        /home/dori/go/src/github.com/binaryplease/base16-universal-manager/colorscheme.go:164 +0x661
main.(*Base16ColorschemeList).Find(0xc0000afc00, 0xc00001a998, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/dori/go/src/github.com/binaryplease/base16-universal-manager/colorscheme.go:198 +0x2a1
main.main()
        /home/dori/go/src/github.com/binaryplease/base16-universal-manager/main.go:87 +0x1b7

Couldn't figure out what it's trying to do here.

.config/base16-universal-manager/config.yaml:

GithubToken: "<mytoken>"
Colorscheme: "flat.yml"
#DryRun: false  # Print the rendered files to stdout instead of saving them

#https://github.com/binaryplease/base16-universal-manager#applications-which-you-want-to-theme
applications:
  alacritty:
    enabled: true
    files:
      default: "~/.config/alacritty/alacritty.yml"
  vim:
    enabled: true
    files:
      default: "~/.vim/vim_colors"

system: Arch linux

What should I do next?

Tilda is not properly expanded?

Using this in my config.yaml

    vim:
        enabled: true
        mode: rewrite
        hook: ""
        files:
          default: ~/.config/nvim/colors

Causes base16 to create a file called '' in it's config directory (/.config/base16-universal-manager) and it doesn't actually write to the file it should. Using a path like "/home/username/.config/nvim/colors" works as expected.

I spend too much time wondering why this didn't work so I'm tired and might have missed important information, please ask and I'll get it for you.

Rename `files` to `output-dir` (or something) in the config.yaml

I was surprised to notice the paths supplied to each member of the files map in an application config was actually a path to the directory that base16-universal-manager outputs the built files. I was expecting it to be the name of the actual file to output. The name seems misleading, so I suggest renaming it.

I'd prefer that it did work as I expected, too. That way I can give the file a descriptive name, rather than the usual default.ext.

Could you create a release

I'm currently trying to make a nix package for base16-universal-manager and it would be nice to have a version to match it to. It does not have to be a 1.0.0 release, but just a 0.1.0 or 0.0.1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.