]> git.giacomolli.uk - onechat/blob - bin/reflow
Name the test files that hold only shared helpers
[onechat] / bin / reflow
1 #!/usr/bin/env bash
2 # Reflows the prose comment on lines FIRST to LAST of FILE. It uses the
3 # Vim from the Nix shell without a user configuration, so the result is
4 # the same on every machine. The filetype plugin of Vim supplies the
5 # comment markers.
6 set -euo pipefail
7
8 if [ $# -ne 3 ]; then
9   echo 'usage: bin/reflow FILE FIRST LAST' >&2
10   exit 2
11 fi
12
13 file=$1
14 first=$2
15 last=$3
16
17 vim -u NONE -i NONE -N -n -es \
18   -c 'filetype plugin on' \
19   -c "edit $file" \
20   -c 'set textwidth=80 nojoinspaces formatoptions=cq' \
21   -c "${first},${last}s/\\S\\zs  \\+/ /ge" \
22   -c "normal! ${first}GV${last}Ggq" \
23   -c 'wq'