about summary refs log tree commit diff stats
path: root/wrap
diff options
context:
space:
mode:
Diffstat (limited to 'wrap')
-rwxr-xr-xwrap31
1 files changed, 31 insertions, 0 deletions
diff --git a/wrap b/wrap new file mode 100755 index 0000000..011aa58 --- /dev/null +++ b/wrap
@@ -0,0 +1,31 @@
1#!/usr/bin/env bash
2
3wrap() {
4 local width="$1"
5 local len=0
6
7 while read -r -a line; do
8 for word in "${line[@]}"; do
9 ((len += "${#word}" + 1))
10 #printf '%s' "$len"
11 if ((len >= width)); then
12 printf '\n'
13 # ruler "$width"
14 len=${#word}
15 fi
16 printf '%s ' "$word"
17 done
18 done
19 printf '\n'
20}
21
22ruler() {
23 for ((i = 0; i < $1; i++)); do
24 printf '%s' "${2:--}"
25 done
26 printf '\n'
27}
28
29if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
30 wrap "$@"
31fi