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

Add a "done" column to the left of my todo list... | task | --- | build a bird-house | clean the kitchen | walk the dog

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:

  • before must be the second-last argument for a command
  • the column named after the before keyword will be the command's target
  • use :before to address a column named before

e.g. psv put todo before done will move or insert the todo column before the done column.

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:

  • after must be the second-last argument for a command
  • the column named after the after keyword will be the command's target
  • use :after to address a column named after

e.g. psv put todo after done will move or insert the todo column after the done column.

:{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.

Let's move the column "40" to the front of the table... | eight (8) | six (6) | four (4) | two (2) | first | last | 10 | 20 | 30 | 40 | Ok, 4 was not good enough, what about "40" | eight (8) | six (6) | four (4) | two (2) | first | last | 10 | 20 | 30 | 40 | ".3" will move the 3rd column... | eight (8) | six (6) | four (4) | two (2) | first | last | 10 | 20 | 30 | 40 | ":4" can be used to ensure that the number "4" will not be used as a column position - in this case, "four (4)" is chosen - embedded numeric matches have higher priority than string prefixes (i.e. "40") | eight (8) | six (6) | four (4) | two (2) | first | last | 10 | 20 | 30 | 40 | Move columns by the "most appropriate match" - "last" identifies the last column ("40") - "2" matches the left-most character in "20" - "7" identifies the 7th column, since no columns have a "7" in their names - "our" matches the "our" in "four (4)" | eight (8) | six (6) | four (4) | two (2) | first | last | 10 | 20 | 30 | 40 |

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
07 digits 0 to 7 collation priority

Place a "done" and "wip" column on the left of this table. - the done column should be sorted - the wip column should be center aligned % psv put wip~:: done. | Task | Done | ----------------- | ----- | clean the kitchen | done | wash the dished | done | vacuum | in progress

Profile

Command

profile {profile name}

Prupose

Select a formatting profile to apply when generating tables.

Profiles
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

Command match {prefix} Purpose

Specify which characters to allow before looking for the first | (pipe) of a table's row.

Example

psv match #

  • reformat all tables, including any preceeded by any number of # characters
psv match /
  • match / matches / and //

Playground By default, psv ignores any lines which do not begin with a '|' (pipe) +- | one | two | three | = | 1|2|3 | will | you | dance| with | me? +- # A table inside a shell comment block # # +- # | one | two | three # | = # | 1|2|3 # | will | you | dance| with | me? # +- What happens when the sub-command "match #" is used? +- | one | two | three | = | 1|2|3 | will | you | dance| with | me? +- # A table inside a shell comment block # # +- # | one | two | three # | = # | 1|2|3 # | will | you | dance| with | me? # +- The prefix pattern "/" also matches "//", and "/ /", and "// //", ... // A table inside a C++ comment block // // +- // | one | two | three // | = // | 1|2|3 // | will | you | dance| with | me? // +-

Prefix

Command prefix {prefix} Purpose

Specify a new prefix to be used before any generated tables.

Example

psv prefix #

  • Render a table suitable for use in a shell comment block.
psv prefix //
  • Render a table suitable for use in a C/C++/golang/... comment block

Playground #!/bin/sh # Here is an example of a table to be included in the comments of a shell script: | option | description | - | -h | show help | -v | show version | -d | show debug messages #!/bin/sh # Here is an example of a table to be included in the comments of a shell script: # # Use quotes to add trailing spaces: psv prefix '# ' | option | description | - | -h | show help | -v | show version | -d | show debug messages

Sort

Command

sort

sort {column}

Purpose

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

Examples

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

Playground "sort" example - default: sort using the left-most column % psv sort | Symbol | Description | Value | | --:--- | ---------------------------------------------- | ---------.--------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 | "sort" example: specific column - "psv sort {name}" will sort using the values in a specific column % psv sort value | Symbol | Description | Value | | --:--- | ---------------------------------------------- | ---------.--------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 | "sort" example: sorting by non-consecutive columns - "psv sort {name} {name}" will sort using the values in the specified columns % psv sort symbol value | Symbol | Description | Value | | --:--- | ---------------------------------------------- | ---------.--------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 | "sort" example: sorting by columns in any order - the columns used for sorting do not need to be in left-to-right order - let's sort by value and then symbol % psv sort value symbol | Symbol | Description | Value | | --:--- | ---------------------------------------------- | ---------.--------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 | "sort" example: changing sorting direction - the addition of `~` and a combination of flags can be used to change a column's type affiliation and sort direction - e.g `~v` will sort in descending order % psv sort value~v | Symbol | Description | Value | | --:--- | ---------------------------------------------- | ---------.--------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 |

Locale

Command

locale {language-tag}

Purpose

Select a language to use when sorting.

The languages collation rules will be used are used for all non-numeric comparisons.

See also

Examples

psv sort locale da

  • sort using the danish collation rules (å and aa appear after z)

Config

Command config {column} Purpose

(Re-)configure one or more columns.

Examples

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.

Playground "config" example: - center-align the symbol column - number-align the values and collate in ascending order % psv config symbol~:: value~.^ | Symbol | Description | Value | | ------ | ---------------------------------------------- | ----------------- | | e | base of the natural logarithm | 2.71828... | | b | binary base | 2 | | e | elementary charge | 1.602176634e−19 C | | π | ratio of circumference to diameter of a circle | 3.14159... | | c | speed of light in a vacuum | 299792458 m/s | | sq | square power | 2 |

Put

Command

put {column}

put {column} … before {column}

put {column} … after {column}

Alternative put {column} Purpose

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..

Tips

Use move to move existing columns only.

Use insert to insert new columns regardless of existing columns.

Examples

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.

Playground - alter all tables so that they begin with a "wip" and "done" column % psv put wip done Chores: | Task | Done | ----------------- | ----- | clean the kitchen | done | wash the dished | done | vacuum | in progress Projects: | Project | Task | -------- | -------------------- | bird house | design bird house | | buy wood | | cut parts | | assemble parts | - | fully-over-engineered letter box - alter all tables so that they begin with a "wip" and "done" column % psv put wip done before task Chores: | Task | Done | ----------------- | ----- | clean the kitchen | done | wash the dished | done | vacuum | in progress Projects: | Project | Task | -------- | -------------------- | bird house | design bird house | | buy wood | | cut parts | | assemble parts | - | fully-over-engineered letter box # this table no "task" column, so the "before" keyword puts the columns on the # left of the table. Cooking: | Step | Description | ---- | ---------- | 1 | boil water | 2 | add eggs | 3 | wait 4 minutes | 4 | serve - move / add a "wip" and "done" at the end of the table % psv put wip done last Chores: | Task | Done | ----------------- | ----- | clean the kitchen | done | wash the dished | done | vacuum | in progress Projects: | Project | Task | -------- | -------------------- | bird house | design bird house | | buy wood | | cut parts | | assemble parts | - | fully-over-engineered letter box Cooking: | Step | Description | ---- | ---------- | 1 | boil water | 2 | add eggs | 3 | wait 4 minutes | 4 | serve

Delete

Command delete {column} Alternative del {column} Purpose

Remove one or more columns from a table.

Examples

psv delete wip

  • Delete the wip column

Playground Remove the "wip" column: % psv delete wip Home Activities: | wip | done | activity | | -:- | --:--- | ------------------ | | | 6:30pm | feed the dog | | | 6:45pm | play with the kids | | * | - | walk the dog |

Move

Hint

put is often a better choice, as it also ensures that missing columns are added if necessary.

Command

move {column}

move {column} … before {column}

move {column} … after {column}

Alternative

mv … - alias for move

Purpose

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.

Playground "move" only moves existing columns: | wip | done | activity | | -:- | --:--- | ------------------ | | | 6:30pm | feed the dog | | | 6:45pm | play with the kids | | * | - | walk the dog |

Insert

Hint

put is often a better choice, as it prevents duplication of existing columns.

Command

insert {column}

insert {column} … before {column}

insert {column} … after {column}

Alternative

ins … - alias for insert

add … - add columns to the right of a table

append … - alias for add

Purpose

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.

Playground "insert" always inserts new columns, even if they already exist: | wip | done | activity | | -:- | --:--- | ------------------ | | | 6:30pm | feed the dog | | | 6:45pm | play with the kids | | * | - | walk the dog | Compared with "put" | wip | done | activity | | -:- | --:--- | ------------------ | | | 6:30pm | feed the dog | | | 6:45pm | play with the kids | | * | - | walk the dog |

Fill & Clear

Command

fill {column} … with {value}

fill {column}

Alternative clear {column} Purpose

Fill all of the fields in a column with a specific value.

Examples

psv clear wip

  • Set all of the fields in the wip column to "" (empty)
  • clear is the same as fill … with ""

Playground After finishing a task, clear the work in progress (wip) column: % psv fill wip with done Home Activities: | wip | activity | | -:- | ------------------ | | | play with the kids | | --- | ------------------ | | | feed the dog | | * | walk the dog | Using the fill command without a value sets the column's values to "" (empty string) % psv fill wip Home Activities: | wip | activity | | -:-- | ------------------ | | done | play with the kids | | ---- | ------------------ | | done | feed the dog | | done | walk the dog | "clear" is perhaps more self-explanatory. % psv clear wip Home Activities: | wip | activity | | -:-- | ------------------ | | done | play with the kids | | ---- | ------------------ | | done | feed the dog | | done | walk the dog | and of course, "delete" also works... Home Activities: | wip | activity | | ---- | ------------------ | | done | play with the kids | | ---- | ------------------ | | done | feed the dog | | done | walk the dog |
Previous Next