Cookie – A Template-Based File Generator for Projects

Cookie is a free and open source template-based file generator that speeds up the process of writing scripts, Makefiles, LaTeX documents, and other one-off files.

Cookie demo
Cookie

Cookie is similar to cookiecutter, a command-line utility that creates projects from project templates (stylistically referred to as “cookiecutters“) in any markup format or programming language. But unlike cookiecutter, Cookie creates pages from file templates.

The templates are stored in the ~/.cookiecutters directory or the directory specified by $COOKIE_DIR. You can see examples of the main developer’s templates here.

Features in Cookie

  • Free and open source with source code available on GitHub.
  • Cross-platform: available on Windows, GNU/Linux, and macOS.
  • Quickly create files from page templates.
  • Supports aliases and functions which serve as task and filetype-specific custom initialization commands.
  • Variable substitution.

Installation of Cookie in Linux

Root Installation

With root permission all you need to do is clone the project from git and building the app with the following commands:

$ git clone https://github.com/bbugyi200/cookie
$ cd cookie
$ sudo make install
User Installation

Without root permission you will need to use an alternate bin directory which you would clone the git repo into and then build with the command:

# make DESTDIR=/home/<user>/.local PREFIX= install

Replace <user> with your username and make sure that the /home/<user>/.local/bindirectory is in your system’s path.

Usage

Usage: cookie [-d] [-D TARGET_DIR] [-f] [-m MODE] [-v] [-x] TEMPLATE [TARGET]
       cookie -c
       cookie -e TEMPLATE
       cookie -h
       cookie -l [TEMPLATE]
       cookie -r TEMPLATE

Initializes a new file (TARGET) using a predefined template (TEMPLATE).
The target file can be a new script, configuration file, markup file, etc....
After the target file has been initialized, it is opened for editing using the
system's default editor.

Positional Arguments:
    TARGET          The name of the file to initialize.

Optional Arguments:
    -d | --debug
        Enable debug mode.

    -c | --config
        Edit the configuration file.

    -D DIR | --bin-subdir DIR
        Initialize TARGET into DIR, which should be a subdirectory of the
        default bin directory (see the configuration file).

    -e TEMPLATE | --edit TEMPLATE
        Add / edit cookie template.

    -f | --force
        Force TARGET initialization to be relative to the current
        directory. This option essentially overrides the ROOT_DIR
        configuration setting. Enabled by default for non-executable
        targets.

    -h | --help
        View this help message.

    -l [TEMPLATE] | --list [TEMPLATE]
        If TEMPLATE is provided, output template contents to STDOUT.
        Otherwise, list available templates. 

    -m MODE | --mode MODE
        Sets file mode bits. Accepts any form for MODE that is recognized
        by the 'chmod' command.

    -r TEMPLATE | --remove TEMPLATE
        Delete cookie template.

    -x
        Make TARGET executable. Equivalent to '-m +x'.

    -v | --verbose
        Enable verbose output.

Using Cookie should come easily to you if you are familiar with Cookiecutter. But if you’re new to either of both tools then you need to go over the guide before delving in.

Divine Okoi is a cybersecurity postgrad with a passion for the open-source community. With 700+ articles covering different topics in IT, you can always trust him to inform you about the coolest tech.

Each tutorial at GeeksMint is created by a team of experienced writers so that it meets our high-quality writing standards.

Got Something to Say? Join the Discussion...