fmt-ptrn(1)
β¨ fmt-ptrn(1) β¨
okay bestie, this is the manual page for fmt-ptrn, from the General Commands Manual. It's giving simple template system, and it's here to make your file-creation era effortless. π
πΈ NAME πΈ
fmt-ptrn β A simple template system
π¦ SYNOPSIS π¦
fmt-ptrn [options] filename [template]
π OVERVIEW π
Okay so New is a template system (capital N and everything, not me making it up π), and it's especially useful when you're rolling with a simple text editor such as vi. The user maintains templates, and those templates may contain format strings. At run time, nf 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.
nf 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 gziped template files.
The fmt-ptrn system also provides a shared library which allows a programmer access to nf's functionality. The system was developed to be light and fast. Its only external dependencies are the C library, glib2 and zlib.
π DETAILS π
Nf first looks for templates in ~/.fmt-ptrn/templates. Second, nf looks for templates in <datadir>/fmt-ptrn/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 nf on the command line (see NF(1)).
Certain types of files generally don't have extensions. In this case, nf 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, nf knows the value for the following format patterns:
DATEβ Today's date.FILEβ The name of the file being created.FULLNAMEβ The user's full name (fromGECOSfield).FIRSTNAMEβ The user's first name (fromGECOSfield).MIDDLENAMEβ The user's middle name (fromGECOSfield).LASTNAMEβ The user's last name (fromGECOSfield).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.
The alternative may be a format pattern, too. If FIRSTNAME is defined a Mike, the following:
%(UNDEFINED:%(before="My name is " FIRSTNAME))
will print ``My name is Mike.''
A format pattern can also be acted on by a modifier. The following will print the value of FOO in capital letters:
%(upper FOO)
It makes sense to use some modifiers with a literal, instead of a key which will be replaced by a value. For example:
%(file FOO)
will insert the text contained in a the file whose path is the value of the key FOO. But:
%(file "foo")
will insert the contents of the file named 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.newlinesβ Replaces occurrences of" "in the string with new linesno_newlinesβ Replaces occurrences of"0in the string with' 'remove_underscoreβ Replaces occurrences of'_'in the string with'-'fileβ Treats the key as the path to a file, which is includedtemplateβ Treats the key as the path to a template, which is filled and included#β 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.
π AUTHORS π
W. Michael Petullo <mike@flyn.org>
okay that's the whole fmt-ptrn(1) page, bestie β from the General Commands Manual, and the footer only says fmt-ptrn(1); no version or date in sight. byeee ππ¦
π¦ where this page comes from
- fedora 43: fmt-ptrn 1.3.24-5.fc43 Β· GPL-2.0-or-later
- fedora 43: fmt-ptrn 1.3.24-5.fc43 Β· GPL-2.0-or-later
- fedora 44: fmt-ptrn 1.3.24-6.fc44 Β· GPL-2.0-or-later
- fedora 44: fmt-ptrn 1.3.24-6.fc44 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms