psv Sub-Commands
Introduction to psv's Sub-Commands
psv provides additional sub-commands to help manipulate the structure of your tables.
For example, to add a new done
column to a simple todo-table, you could
use the command psv put done first
psv Sub-Commands
Index of all sub-commands, in order of relevance.
Detailed descriptions and examples are provided below…
Identifying Columns
The following formats are avaialble for specifying which columns to manipulate.
These patterns are recognised by all commands that manipulate columns in some way.
| Format | In Words | Description |
|---|---|---|
| {name} | a column name |
Selects a column by its name or position. psv first attempts to match the name against the table's column names. If no column names match and {name} is a number, then the number will be used as described for .{number} below. This behaviour is expected be suitable for most situations. Ambiguous column identification can be overcome via the following alternatives. |
| first | the word first |
selects the left-most column of a table. Tip the first keyword is implied to mean before first when used as the last argument to the put, move or insert commands. |
| last | the word last |
selects the right-most column of a table. Tip the last keyword is implied to mean after last when used as the last argument to the put, move or insert commands. |
| before | the word before |
The before keyword indicates that the next argument will be the name of a target column, before which the command's action should take place. Specifically:
e.g. psv put todo before done will
move or insert the |
| after | the word after |
The after keyword indicates that the next argument will be the name of a target column, after which the command's action should take place. Specifically:
e.g. psv put todo after done will
move or insert the |
| :{name} | colon {name} |
Selects a column exclusively by its name. Even if name is a number, it will not be used as a column's position. :first, :last, :config etc. should be used to identify columns with names that would otherwise match psv keywords. |
| .{number} | dot {number} |
selects a column exclusively by its position, starting with 1 for the left-most column. |
Configuring Columns
Columns can be implicitly re-configured by adding a ~ (tilde) character after their name, followed by a new set of configuration flags.
The following flags are available:
| Flag | In Words | Description | |
|---|---|---|---|
| no-flags | clear all of the column's flags | ||
| Alignment | - | hyphen | clear the column's alignment flags only |
| : | colon | align left | |
| :- | colon hyphen | align left | |
| -: | hyphen colon | align right | |
| :: | colon colon | align center | |
| -:- | hyphen colon hyphen | align center | |
| . | dot | align numerically | |
| .. | dot dot | align by version number | |
| Sorting | ~ | tilde | clear the column's sorting flags only |
| ^ | caret | collate in ascending order | |
| v | the letter v | collate in descending order | |
| 0 … 7 | digits 0 to 7 | collation priority |
Profile
profile {profile name}
Select a formatting profile to apply when generating tables.
- psv
-
The default profile, allowing all of psv's features.
- markdown
-
For generating markdown compatible tables.
Rules:
- only one ruler will be rendered, as the second line of the table
- each field in the ruler will contain at least 3 - or = characters
- alignment hints are reduced to left :---, right ---: and center :---: only
- gherkin
-
For generating Data-Tables for behaviour driven development (BDD) scenario definitions.
Rules:
- no rulers will be generated
Match
Specify which characters to allow before looking for the first | (pipe) of a table's row.
psv match #
- reformat all tables, including any preceeded by any number of # characters
- match / matches / and //
Prefix
Specify a new prefix to be used before any generated tables.
psv prefix #
- Render a table suitable for use in a shell comment block.
- Render a table suitable for use in a C/C++/golang/... comment block
Sort
sort
sort {column} …
Sort a table's rows.
If no columns are specified, the rows are collated by comparing their values from left to right.
If columns are specified, the rows are collated using the specified columns only, in the order that they appear after the sort keyword.
The special keywords first and last are interpreted as the first (left-most) and last (right-most) columns of the table.
Use :first, :last, :before
or :after to reference columns named
first
, last
etc..
See also Sorting
psv sort
- sort each table using the first column
psv sort value
- Sort each table by its value column
- Any tables wihtout a value column are sorted by their first column.
psv sort symbol value
- Sort each table by their symbol and then value columns
psv sort value symbol
- Sort each table by their value and then symbol columns
- Note that the value column appears after the symbol column, so they are given additional priority markers to ensure the correct colation order.
psv sort value~v
- Sort each table by their value column, in descending order
Locale
locale {language-tag}
Select a language to use when sorting.
The languages collation rules will be used are used for all non-numeric comparisons.
See also
psv sort locale da
- sort using the danish collation rules (å and aa appear after z)
Config
(Re-)configure one or more columns.
psv config symbol~::
- Change the symbol column's alignment to
center aligned
psv config value~.
- Change the value column's alignment to
numeric alignment
psv config value~v
- Change the sort direction of the value column to descending order
See the Configuring Columns section above for all of the column configuration options.
Put
put {column} …
put {column} … before {column}
put {column} … after {column}
move or insert columns to a target location.
The default target of the put command is before first, i.e. to the left of a table.
The addition of before {column} or after {column} can be used to place the columns relative to another, taget column.
The column names first and last
are interpreted as the first column
and
the last column
respectively.
Use :first, :last, :before
or :after to reference columns named
first
, last
etc..
Use move to move existing columns only.
Use insert to insert new columns regardless of existing columns.
psv put wip done
- move or add the columns wip and done to the left of each table
- Existing columns are moved (including their data).
- Missing columns are added
psv put wip done before task
- Place the columns wip and done before the task column.
- If the target column, task does not exist, place the columns at the left of the table.
psv put wip done last
- Place the columns wip and done on the right of each table.
Delete
Remove one or more columns from a table.
psv delete wip
- Delete the wip column
Move
put is often a better choice, as it also ensures that missing columns are added if necessary.
move {column} …
move {column} … before {column}
move {column} … after {column}
mv … - alias for move
Move existing columns to a new position within a table.
- Missing columns are ignored.
- No new columns will be created.
The default target of the move command is before first, i.e. to the left of a table.
Insert
put is often a better choice, as it prevents duplication of existing columns.
insert {column} …
insert {column} … before {column}
insert {column} … after {column}
ins … - alias for insert
add … - add columns to the right of a table
append … - alias for add
Insert new columns into a table.
The default target of the insert (and ins) command is before first, i.e. to the left of a table.
The default target of the add and append commands is after last, i.e. to the right of a table.
Fill & Clear
fill {column} … with {value}
fill {column} …
Fill all of the fields in a column with a specific value.
psv clear wip
- Set all of the fields in the wip column to "" (empty)
- clear is the same as fill … with ""