├── .github └── workflows │ └── blank.yml ├── LICENSE ├── README.md ├── package.json ├── templater └── test ├── input.template ├── output ├── test-runner.sh └── vars /.github/workflows/blank.yml: -------------------------------------------------------------------------------- 1 | # This is a basic workflow to help you get started with Actions 2 | 3 | name: CI 4 | 5 | # Controls when the workflow will run 6 | on: 7 | # Triggers the workflow on push or pull request events but only for the master branch 8 | push: 9 | branches: [ master ] 10 | pull_request: 11 | branches: [ master ] 12 | 13 | # Allows you to run this workflow manually from the Actions tab 14 | workflow_dispatch: 15 | 16 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 17 | jobs: 18 | # This workflow contains a single job called "build" 19 | build: 20 | # The type of runner that the job will run on 21 | runs-on: ubuntu-latest 22 | 23 | # Steps represent a sequence of tasks that will be executed as part of the job 24 | steps: 25 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 26 | - uses: actions/checkout@v3 27 | 28 | - name: Install shellcheck 29 | run: sudo apt install -y shellcheck 30 | 31 | # Runs a single command using the runners shell 32 | - name: shellcheck 33 | run: shellcheck -e SC1090 ./templater 34 | 35 | # Runs unit test 36 | - name: shellcheck 37 | run: | 38 | cd test 39 | ./test-runner.sh 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Vicente Adolfo Bolea Sanchez 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BASH TEMPLATER [![CI](https://github.com/vicentebolea/bash-templater/actions/workflows/blank.yml/badge.svg?branch=master)](https://github.com/vicentebolea/bash-templater/actions/workflows/blank.yml) 2 | 3 | Simplest Template Engine Ever (Written in BASH) 4 | 5 | ## TL;DR 6 | 7 | Installing: 8 | 9 | bpkg install vicentebolea/bash-templater 10 | 11 | Using it: 12 | 13 | templater vars < file.template 14 | 15 | 16 | ## USE ME 17 | You have this `file.template`: 18 | ```markdown 19 | # My template 20 | ## Author 21 | - @NAME@ <@EMAIL@> 22 | ``` 23 | And this `rules` file: 24 | ```bash 25 | NAME=LEOPOLDO WINSTON 26 | EMAIL=leothewinston\@leoserver.com 27 | ``` 28 | 29 | You execute this command: 30 | ```bash 31 | templater rules < file.template 32 | ``` 33 | 34 | You get this: 35 | ```markdown 36 | # My template 37 | ## Author 38 | - LEOPOLDO WINSTON 39 | ``` 40 | ## The only rule 41 | 42 | Escape the `@` character like `\@` in the rules file. 43 | 44 | ## INSTALL ME 45 | Use the fantastic BASH package manager BPKG and just: 46 | 47 | bpkg install vicentebolea/bash-templater 48 | 49 | ## AUTHORS 50 | - Vicente Adolfo Bolea Sanchez 51 | 52 | ## THANKS TO 53 | - https://github.com/bpkg/bpkg 54 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bash-templater", 3 | "version": "0.0.4", 4 | "description": "The most basic template engine", 5 | "scripts": [ "templater" ], 6 | "install": "install ./templater ${PREFIX}/bin/", 7 | } 8 | -------------------------------------------------------------------------------- /templater: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # shellcheck disable=SC1090 3 | rules="$1" 4 | # Read the keys 5 | mapfile -t keys < <(awk -F= '{print $1}' < "$rules") 6 | # Read the values 7 | source "$rules" 8 | 9 | for key in "${keys[@]}" 10 | do 11 | sed_args+=";s@\@${key}\@@${!key}@g" 12 | done 13 | 14 | exec sed "$sed_args" 15 | -------------------------------------------------------------------------------- /test/input.template: -------------------------------------------------------------------------------- 1 | # README 2 | You can find my information at: 3 | - @URL@ 4 | - Or just reach me at @EMAIL@ 5 | -------------------------------------------------------------------------------- /test/output: -------------------------------------------------------------------------------- 1 | # README 2 | You can find my information at: 3 | - https://vicentebolea.me 4 | - Or just reach me at vicente@unist.ac.kr 5 | -------------------------------------------------------------------------------- /test/test-runner.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | out=$(< input.template ../templater vars) 4 | 5 | diff output <(echo "$out") 6 | 7 | exit $? 8 | -------------------------------------------------------------------------------- /test/vars: -------------------------------------------------------------------------------- 1 | URL="https://vicentebolea.me" 2 | EMAIL="vicente\@unist.ac.kr" 3 | --------------------------------------------------------------------------------