diff options
author | Case Duckworth | 2020-05-30 13:35:32 -0500 |
---|---|---|
committer | Case Duckworth | 2020-05-30 13:35:32 -0500 |
commit | 482e2659aef19691fd0196e6744bc7448e908757 (patch) | |
tree | 14e88b05951eae859130ff971a65de0e2e0d1b04 /fold.sh | |
parent | Start testing transform_uri (diff) | |
download | bollux-482e2659aef19691fd0196e6744bc7448e908757.tar.gz bollux-482e2659aef19691fd0196e6744bc7448e908757.zip |
Backup
Diffstat (limited to 'fold.sh')
-rw-r--r-- | fold.sh | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/fold.sh b/fold.sh new file mode 100644 index 0000000..ee88c6e --- /dev/null +++ b/fold.sh | |||
@@ -0,0 +1,26 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | fold() { | ||
4 | shopt -s checkwinsize | ||
5 | ( | ||
6 | : | ||
7 | : | ||
8 | ) | ||
9 | width="${1:-$COLUMNS}" | ||
10 | while read -r line; do | ||
11 | : "${line// / }" | ||
12 | IFS=$'\n' read -d "" -ra words <<<"${line// /$'\n'}" | ||
13 | ll=0 | ||
14 | for word in "${words[@]}"; do | ||
15 | wl="${#word}" | ||
16 | if ((ll + wl > width)); then | ||
17 | printf '\n' | ||
18 | else | ||
19 | ((ll += wl)) | ||
20 | printf '%s ' "$word" | ||
21 | fi | ||
22 | done | ||
23 | done | ||
24 | } | ||
25 | |||
26 | fold "$@" | ||