Skip to content

tonyd33/dotpreprocessor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

dotpreprocessor

Motivation

When creating settings, we often have to redefine variables that should really be centralized and shared. For example, in a terminal emulator configuration file, we might be using fonts and colors that is also used in a browser configuration file, window manager configuration file, etc. If we ever decided to change the font or colors, we'd have to change all instances of where those variables were used.

Quickstart

chmod +x dotpp
./dotpp --source <python file with lookup dictionary> --target <file to be preprocessed>

Usage

Suppose we have a file colors.conf with the following contents.

foreground_color #ffffff
background_color #000000

We use the same foreground_color and background_color in other files though, so we want to replace foreground_color and background_color with variables, say fg and bg, respectively. To do this, create a new file colors.conf.dot with the following contents:

foreground_color $$fg$$
background_color $$bg$$

and a Python file lookup.py:

lookup = {
  "fg": "#ffffff",
  "bg": "#000000"
}

Now run ./dotppy.py --source lookup.py --target colors.conf.dot --output colors.conf.

Workflow

A simple script to build all .dot files I use in my dotfiles

function build() {
  directory=$(dirname $1)
  filename=$(basename $1)
  [ ${filename##*.} != 'dot' ] && exit # ignore non .dot files
  built="$directory/${filename::-4}"
  dotpp -s lookup.py -t $1 -o $built
  echo "built $1->$built"
}

export -f build # we have to export this for the find subshell to pick it up

find . type f -exec bash -c 'build "{}"' \;

About

Simple preprocessor for my dotfiles

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages