diff options
author | Case Duckworth | 2020-05-22 08:38:40 -0500 |
---|---|---|
committer | Case Duckworth | 2020-05-22 08:38:40 -0500 |
commit | 6cce4bd5e7e89406c0ca5942076c95c458bba2dc (patch) | |
tree | 89e5a9393b5c99aa2a6eb0fc87e9e97e7ec84e57 /wrap | |
download | bollux-6cce4bd5e7e89406c0ca5942076c95c458bba2dc.tar.gz bollux-6cce4bd5e7e89406c0ca5942076c95c458bba2dc.zip |
Ready to upload
Diffstat (limited to 'wrap')
-rwxr-xr-x | wrap | 31 |
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 | |||
3 | wrap() { | ||
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 | |||
22 | ruler() { | ||
23 | for ((i = 0; i < $1; i++)); do | ||
24 | printf '%s' "${2:--}" | ||
25 | done | ||
26 | printf '\n' | ||
27 | } | ||
28 | |||
29 | if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then | ||
30 | wrap "$@" | ||
31 | fi | ||