Skip to content

Commit

Permalink
Use awk instead of pr to format columns
Browse files Browse the repository at this point in the history
pr is POSIX but isn't in busybox so let's just use awk instead.

Closes #68.
  • Loading branch information
whiteinge committed Nov 30, 2018
1 parent a68b9c6 commit ff667b4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ok.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,22 @@ crlf=$(printf '\r\n')
# ### Help
# Functions for fetching and formatting help text.

_cols() { sort | pr -t -3; }
_cols() {
sort | awk '
{ w[NR] = $0 }
END {
cols = 3
per_col = sprintf("%.f", NR / cols + 0.5) # Round up if decimal.
for (i = 1; i < per_col + 1; i += 1) {
for (j = 0; j < cols; j += 1) {
printf("%-24s", w[i + per_col * j])
}
printf("\n")
}
}
'
}
_links() { awk '{ print "* [" $0 "](#" $0 ")" }'; }
_funcsfmt() { if [ "$OK_SH_MARKDOWN" -eq 0 ]; then _cols; else _links; fi; }

Expand Down

0 comments on commit ff667b4

Please sign in to comment.