more readable `make help', finally
The output was still somewhat ragged in 80x24 terminal window with fmt(1) which wasn't anticipating the word length difference subsequent column(1) would have to cope with later on. Thanks Loic Cattani for his shell columnizer implementation: https://github.com/Arko/Columnize
This commit is contained in:
parent
4afd735adb
commit
9fd0bc143e
36
bin/columnize
Executable file
36
bin/columnize
Executable file
@ -0,0 +1,36 @@
|
||||
#!/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/Columnize
|
||||
|
||||
values=($*)
|
||||
longest_value=0
|
||||
|
||||
# Find the longest value
|
||||
for value in ${values[@]}; do
|
||||
if [[ ${#value} -gt $longest_value ]]; then
|
||||
longest_value=${#value}
|
||||
fi
|
||||
done
|
||||
|
||||
# Compute column span
|
||||
term_width=${COLUMNS:-$(tput cols)}
|
||||
(( columns = $term_width / ($longest_value + 2) ))
|
||||
|
||||
# Print values with pretty column width
|
||||
curr_col=0
|
||||
for value in ${values[@]}; do
|
||||
value_len=${#value}
|
||||
echo -n $value
|
||||
(( spaces_missing = $longest_value - $value_len + 2 ))
|
||||
printf "%*s" $spaces_missing
|
||||
(( curr_col++ ))
|
||||
if [[ $curr_col == $columns ]]; then
|
||||
echo
|
||||
curr_col=0
|
||||
fi
|
||||
done
|
||||
|
||||
# Make sure there is a newline at the end
|
||||
if [[ $curr_col != 0 ]]; then echo; fi
|
@ -2,11 +2,11 @@
|
||||
|
||||
help/distro:
|
||||
@echo '** available distribution targets:'; \
|
||||
echo $(DISTROS) | fmt -sw"$$((COLUMNS>>1))" | column -t
|
||||
bin/columnize $(sort $(DISTROS:distro/%=%))
|
||||
|
||||
help/ve:
|
||||
@echo '** available virtual environment targets:'; \
|
||||
echo $(VES) | fmt -sw"$$((COLUMNS>>1))" | column -t
|
||||
bin/columnize $(sort $(VES))
|
||||
|
||||
help: | help/distro help/space help/ve; @:
|
||||
help/space:; @echo
|
||||
|
Loading…
Reference in New Issue
Block a user