portfmt
—
format FreeBSD Ports Collection Makefiles
portfmt |
[-D [context]]
[-ditu ] [-w
wrapcol] [Makefile] |
portfmt
is a tool for formatting
FreeBSD Ports Collection Makefiles.
If the optional Makefile argument is not
given, the Makefile will be read from stdin. This can be useful for editor
integration where you might want to only format portions of your
Makefile.
The following options are available:
-D
[context]
- Output a unified diff from the original to the formatted version. This can
optionally be followed by the number of context lines. It defaults to 3
lines of context. For full context use 0.
-d
- Dump the AST to stdout. This is only useful for debugging purposes. If
this flag is specified
-i
is ignored.
-i
- Format Makefile in-place instead of writing the
result to stdout.
-t
- Format and reindent target commands.
-u
- Leave variables unsorted.
-U
- Always sort variables.
-w
wrapcol
- Sets the wrapping column to wrapcol (default: 80).
This is a goal not a hard value. It will be ignored for several variables
like COMMENT, DISTFILES, MASTER_SITES, etc.
With a value of -1 it is ignored for all variables. Variables
with wrapped tokens over multiple lines will be concatenated onto a
single line.
You can integrate Portfmt into your editor to conveniently run it only on parts
of the port, e.g., to reformat USES after adding a new item to it.
Add this to ~/.emacs.d/init.el to format the current
region with C-c p:
(defun portfmt (&optional b e)
"PORTFMT(1) on region"
(interactive "r")
(shell-command-on-region b e "portfmt " (current-buffer) t
"*portfmt errors*" t))
(with-eval-after-load 'make-mode
(define-key makefile-bsdmake-mode-map (kbd "C-c p") 'portfmt))
Add this to ~/.config/kak/kakrc for filtering the
current selection through portfmt
with
,1:
map global user 1 '|portfmt<ret>;' \
-docstring "portfmt on selection"
Add this to ~/.vimrc for filtering the current selection
through portfmt
with \1:
xnoremap <leader>1 <esc>:'<,'>!portfmt<CR>
The following environment variables affect the execution of
portfmt
:
CLICOLOR_FORCE
- If defined
portfmt
will output text with ANSI
colors even when stdout is not a tty or NO_COLOR
is set.
NO_COLOR
- If defined colors will be disabled.
portfmt
will exit with one of the following values:
- 0
- Success.
- 1
- An error occurred.
- 2
- There were changes when compared to the original file. Only possible with
-D
.
In-place format /usr/ports/audio/sndio/Makefile:
portfmt -i /usr/ports/audio/sndio/Makefile