Code Monkey home page Code Monkey logo

mold's Introduction

mold

A simple configuration template rendering program.

The main goal of mold is to allow users to easily switch configuration files between different contexts. One example usage would be to have custom themes for multiple programs with one easy way to switch all of their configuration at once.

The context file contains multiple namespaces as well as a global namespace. Each namespace can have multiple key-value entries. Those variables can then be used in the templates like this: {% variable1 %}. The name of the variable is enclosed in {% and %} with any amount of whitespace in between allowed.

There are also file source variables enclosed in {@ and @} that point to a path in the file system. When rendering a context contents of this file will be used in place of the variable. To trim the content of the file of whitespace use {@~ and ~@} tags.

Context

Here is an example context file that could be used to render configuration:

renders:
  alacritty.yml: ~/.config/alacritty/alacritty.yml
  bspwm/bspwmrc: ~/.config/bspwm/bspwmrc
  .gtkrc-2.0: ~/.config/.gtkrc-2.0 # ~ will correctly expand to the home directory
  gtk-3.0/settings.ini: ~/.config/gtk-3.0/settings.ini
namespaces:
  - name: GLOBAL
    variables:
      _font_: JetBrains Mono
      _font_size_: '11'

      alacritty.font: "{%_font_%}"
      alacritty.font-size: "{%_font_size_%}"

      _gtk_theme_: Aritim-Dark
      gtk3.font.name: "{%_font_%}"
      gtk3.font.size: "{%_font_size_%}"
      gtk3.theme.name: "{%_gtk_theme_%}"
      gtk3.icon-theme.name: "Papirus-Dark"
      gtk2.theme.name: "{%_gtk_theme_%}"
      gtk2.font.name: "{%_font_%}"
      gtk2.font.size: "{%_font_size_%}"

      #bspwm.screen.init: randr
      bspwm.screen.init: randr rotate

      _wallpapers_path_: /usr/share/wallpapers

      vim.bg.light_or_dark: dark

  - name: gruvbox
    variables:
      alacritty.theme: gruvbox
      gtk3.theme.name: gruvbox-gtk
      wallpaper.screen0: "{%_wallpapers_path_%}/gruvbox_vertical.png"
      wallpaper.screen1: "{%_wallpapers_path_%}/gruvbox.png"
  - name: solarized
    variables:
      alacritty.theme: solarized
      gtk3.theme.name: Solarized-Dark-Orange
      wallpaper.screen0: "{%_wallpapers_path_%}/solarized_vertical.png"
      wallpaper.screen1: "{%_wallpapers_path_%}/solarized.png"

If a variable value is not available in the specified namespace one from GLOBAL namespace will be used.

Installation

To install mold you'll need the latest rust with cargo.

$ cargo build --release && cp ./target/release/mold /usr/bin/

Usage

Render context directly

If the context contains the renders field then it can be rendered directly with:

$ mold render-context context.yml

$ mold render-context context.yml -n some-namespace

Render specified files

If you want to render files directly use the render subcommand:

$ mold render -c context.yml file1 file2   # will print both files to stdout

$ mold render -c context.yml file1 file2 -n some-namespace

$ mold render -c context.yml file1 file2 -o /tmp  # will save the rendered files as /tmp/file1 and /tmp/file2

Display a diff

$ mold diff -c context.yml gtkrc-template ~/.gtkrc-2.0 # will render gtkrc-template and show a diff with ~/.gtkrc-2.0

You can checkout the context file that I use for my setup for further examples here

License

MIT

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.