Prefixes
psv refers to a prefix as "the characters that appear before each row and ruler of a table".
Whereas indentation refers to whitespace characters only, prefixes may also contain non-whitespace characters.
Prefixes allow psv to also format tables which are, for example, embedded in a program's comments.
By default, psv only accepts prefixes consisting of whitespace characters, i.e. plain indentation.
By specifying a prefix, e.g. // or #, psv will look for tables which have any repetition of the prefix before the first | character of each row.
- provide a prefix that would allow psv to reformat the table in the comments above
The other rules about ignoring lines which do not begin with a | character still apply, so given an entire block of comments, psv will only reformat the tables, and not effect the other lines at all.
As with indentation, the prefix of the first row of each table is re-used for all rows in the table.
Specifying Prefixes
There are two ways of specifying prefixes on the command line:
-
psv -p "//"psv prefix "//" -
The prefix is a simple, space-separated list of character sequences which psv will allow before the first | of a table row. you will need to quote the prefix if it contains any spaces or special characters
The prefix which was found at the start of the first row of each table will be re-used on all subsequent rows which also match the prefix pattern.
Tables which do not have a prefix will always be formatted and will retain their indentation. i.e. no prefix will be added to tables that do not already have a prefix.
Excercises
- can you re-beautify the table above? (extracted from a real redis configuration file)
- specifying the prefix // # (whitespace separated), will reformat tables preceded by any combination of // or #
- what happens if you remove the // from the first line of the table and re-format again?