Giter VIP home page Giter VIP logo

mktable's Introduction

mktable

Go

mktable is a simplish cli tool which consumes content via STDIN and converts it into a pretty aligned table ready for use in markdown.

Installation

brew tap keyneston/tap
brew install mktable

With go installed:

go install github.com/keyneston/mktable@latest

Or download the latest release and add to your path.

Use

$ netstat -i | head -5 | mktable -s ' +'
| Name | Mtu   | Network     | Address   | Ipkts   | Ierrs   | Opkts   | Oerrs | Coll |
| ---- | ----- | ----------- | --------- | ------- | ------- | ------- | ----- | ---- |
| lo0  | 16384 | <Link#1>    | 9583572   | 0       | 9583572 | 0       | 0     |      |
| lo0  | 16384 | 127         | localhost | 9583572 | -       | 9583572 | -     | -    |
| lo0  | 16384 | localhost   | ::1       | 9583572 | -       | 9583572 | -     | -    |
| lo0  | 16384 | keyport.loc | fe80:1::1 | 9583572 | -       | 9583572 | -     | -    |

Flags

Flag Default Description
-s [ \t]*\t[ \t]* Regexp used to set the delimiter
-no-headers false Skip printing headers
-r / -reformat false Reformat existing markdown table. Alias for -format mk
-a none Sets the alignment. See Alignment
-f / -format regexp Sets the input format. See Formats for more details

Formats

Format Description
re / regexp Regular Expression Delimiter
csv Comma Separated List
mk / markdown Consume an existing markdown table for reformatting

Alignment

EXPERIMENTAL

The alignment flag can be passed multiple times and/or passed as a comma seperated list.

It takes a number indicating a zero indexed column, and a character indicating how to align the column.

char alignment
> right
< left
= center

Examples

Example Description
-a '0<' left align the 1st column
-a '1=' center align the 2nd column
-a '1=,2>' center align the 2nd column, and right align the second
-a '1=,2>' -a '3=' as above, but also center align the 4th column

Reformat existing tables

$ mktable -r <<EOF
| Foo      | Bar |
| a | b
| a  | b |
EOF
| Foo | Bar |
| --- | --- |
| a   | b   |
| a   | b   |

This can be used with vim to easily fix tables. First select the the lines you want (Shift-V) and then pipe it :!mktable -r.

mktable's People

Contributors

keyneston avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

mktable's Issues

Handle tab to space mapping

Currently if a column has tabs you can end up with things being reformatted strangely. Add in mapping of one tab to four spaces, with an option to set the number of spaces.

Add reformat option

There should be an option which takes a markdown table in via STDIN, and reformats it before reprinting it. This is particularly useful with VIM.

Add native support for CSV

Currently you can fake csv support by setting the seperator to a comma i.e. -s ',', but this doesn't handle cases such as escaped commas, or commas in quotations. Instead we should have a -format csv option which casues it to it to read the data in using a real CSV parser.

Read files provided on the command line

Currently mktable reads from STDIN and outputs to STDOUT. Additionally mktable should accept a list of one or more files from the command line to read in and format that way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.