#!/bin/bash# columnize.sh# Take a list of values and output them in a nicely formatted column view.# Author: Loïc Cattani "Arko" <loic cattani at gmail com># https://github.com/Arko/Columnizevalues=($*)longest_value=0# Find the longest valuefor value in${values[@]};do if[[${#value}-gt$longest_value]];thenlongest_value=${#value}fidone# Compute column spanterm_width=${COLUMNS:-$(tput cols)}(( columns =$term_width / ($longest_value + 2)))# Print values with pretty column widthcurr_col=0for value in${values[@]};dovalue_len=${#value}echo-n$value(( spaces_missing =$longest_value - $value_len + 2 ))printf"%*s"$spaces_missing(( curr_col++ ))if[[$curr_col==$columns]];thenechocurr_col=0fidone# Make sure there is a newline at the endif[[$curr_col!= 0 ]];then echo;fi