Skip to content

A shell script to pretty print tabular data into the terminal

License

Notifications You must be signed in to change notification settings

idanb1/prettytable.sh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

PrettyTable

PrettyTable is a simple shell implementation to draw nice looking ascii tables with auto sizing columns to the screen.

Prerequisites

The column utillity as well as sed are needed for this script to work.

The implementation has been tested using bash as well as zsh.

Usage

You may either source the prettytable.sh file or use it as an executable. Both works just fine.

Multiline table data is simply piped into prettytable for formating, while the number of columns needs to be specified. Columns need to be delimited using a \t (Tab) character.

Optionally a color may be specified as second argument to prettytable. This color will be used to to color the header text. Available colors:

  • blue
  • green
  • cyan
  • red
  • purple
  • yellow
  • gray
  • light_blue
  • light_green
  • light_cyan
  • light_red
  • light_purple
  • light_yellow
  • light_gray

Example

{
 printf 'PID\tUSER\tAPPNAME\n';
 printf '%s\t%s\t%s\n' "1" "john" "foo bar";
 printf '%s\t%s\t%s\n' "12345678" "someone_with_a_long_name" "blub blib blab bam boom";
} | prettytable 3
┌──────────┬──────────────────────────┬─────────────────────────┐
│PID       │USER                      │APPNAME                  │
├──────────┼──────────────────────────┼─────────────────────────┤
│1         │john                      │foo bar                  │
│12345678  │someone_with_a_long_name  │blub blib blab bam boom  │
└──────────┴──────────────────────────┴─────────────────────────┘

NOTE: The spacing between lines is a result of Githubs formatting and should not occure in your terminal.

About

A shell script to pretty print tabular data into the terminal

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%