man template-new (Commandes) - template-new -- A simple template system.

NAME

template-new -- A simple template system.

SYNOPSIS

template-new [options] filename [template]

DESCRIPTION

template-new is a template system, especially useful in conjunction with a simple text editor such as vi. The user maintains templates which may contain format strings. At run time, template-new replaces the format strings in a template with appropriate values to create a new file.

For example, given the following template:

//   FILE: %(FILE)
// AUTHOR: %(FULLNAME)
//   DATE: %(DATE)

// Copyright (c) 1999 %(FULLNAME) %(EMAIL) // All rights reserved.

template-new will create:

//   FILE: foo.cpp
// AUTHOR: W. Michael Petullo
//   DATE: 11 September 1999

// Copyright (c) 1999 W. Michael Petullo new@flyn.org // All rights reserved.

on my computer.

The program understands plaintext or gzip template files.

Building new also creates a shared library, libtemplate, which allows the programmer access to new's functionality.

In the Debian package the shared library is not provided since it is rarely used by other programs. If you need it - contact the Debian maintainer <baruch@ev-en.org> and he will update the package.

template-new first looks for templates in ~/.template-new/templates. Second, new looks for templates in <datadir>/template-new/template, where datadir is defined by autoconf. This directory is usually /usr/local/share or /usr/share.

The templates directory contains several subdirectories matching filename extensions. This may include directories such as html, cpp, c, and tex. Within each subdirectory are the actual template files. The template file named default is the default template used for the filename extension. Other templates can be used by specifying their filename to new on the command line (see template-new(1)).

Certain types of files generally don't have extensions. In this case, template-new looks for a template directory with the same name as the file being created. This is useful when using templates to create files with names such as Makefile and README.

When filling a format pattern, template-new knows the value for the following format patterns:

DATE
Today's date.
YEAR
Today's year.
FILE
The name of the file being created.
FULLNAME
The user's full name (from GECOS field).
FIRSTNAME
The user's first name (from GECOS field).
MIDDLENAME
The user's middle name (from GECOS field).
LASTNAME
The user's last name (from GECOS field).
EMPTY_STR
The empty string.

In addition, any environment variable can be used as a format pattern. An alternate string to be used in the case of an environment variable being undefined can be specified as follows:

%(UNDEFINED:foo)

This will be replaced with ``foo'' in the created file if UNDEFINED is not a part of one's environment.

A format pattern can also be acted on by a modifier. The following will print the value of FOO in capital letters:

%(upper FOO)

The following modifiers are currently available:

upper
Convert to upper case.
lower
Convert to lower case.
basename
Convert to the basename of a filename.
before="str"
Append the string str before.
after="str"
Append the string str after.
fn
Tag a " ()" on the end.
c_delim
Print enveloped in a C style deliminator, ie: /* == foo == */.
cpp_delim
Print enveloped in a C++ style deliminator, ie: // == foo.
sh_delim
Print enveloped in a shell script style deliminator, ie: # == foo.
tex_delim
Print eveloped in a LaTeX style deliminator, ie: % == foo.
#
A comment, this will not appear in destination file %(# Comment.)

Several modifiers can act within one format string as illustrated:

%(basename upper FOO)

Modifiers use a stack to be applied. The first modifier to be applied is the one farthest to the right. The last to be applied it the one farthest to the left.

One special modifier, template, exists which behaves differently than the others. The following example demonstrates this behavior:

%(template /path/to/file)

This example reads /path/to/file and treats it as a format string. This format string is filled and inserted into the output file.

The modifier file is similar to template but does not cause the path to be filled before being inserted.

OPTIONS

filename
Filename of the file to create
-h, --help
Print a list of options
-f, --force
Overwrite any existing file
-l, --list
List templates available for given filename
-g, --global
Use global templates instead of personal ones
-t, --template path
Use the file at path as template
-s, --set FOO=bar
Set the key FOO to the value bar
-y, --type type
Set the file's type and do not try to extract it from the filename
-p, --permissions octal
Set the new file's permissions
template
Name of the template to use within global or local template dir

FILES

${datadir}/template-new/templates System-wide template directory. ~/.template-new/templates User specific template directory.

AUTHORS

E-Mail
new@flyn.org
HTTP
Flyn Computing <URL:http://www.flyn.org>