Macro Operators

Values can be altered by adding a colon-separated suffix.

Supported operators are:

SuffixExampleDescription
:lcWord -> wordmake value lowercase
:uctest -> TESTmake value uppercase
:h1000 -> 1kmake a number more readable
:duration125 -> 2m 5sconvert a number of seconds into a human-readable duration
:age1700834034 -> 374subtract value from current Unix timestamp to get the age in seconds
:date1700834034 -> 2023-11-24 14:53:54 CETconvert a Unix timestamp into a human-readable date (local timezone)
:utc1700834034 -> 2023-11-24 13:53:54 UTCconvert a Unix timestamp into a human-readable date (UTC timezone)
:fmt=<fmt>123.45 -> 123.5apply a format, e.g. $(total | fmt=%.1f) (using Go’s fmt.Sprintf)
:s/regexp/replace/C:\ % -> Capply regexp replacement, e.g. $(name | ’s/\W//’ ) (using Go’s regexp.Compile)
:asciiC:\ % -> Cremove any non-ASCII characters
:trim" test " -> “test”remove leading and trailing whitespace
:chomp" test " -> " test"remove trailing whitespace only

Operators can be put together (spaces are optional):

$(datemacro:date : uc)

This converts $(datemacro) to a human-readable date and makes everything uppercase.

You can also use the pipe symbol to use multiple operators in a row, for example:

$(macroname | date | uc)

Use the generic fmt operator to apply a format to numbers, for example:

$(used_pct | fmt=%d)