summaryrefslogtreecommitdiffstats
path: root/.local/bin/cmdfmt
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin/cmdfmt')
-rwxr-xr-x.local/bin/cmdfmt34
1 files changed, 34 insertions, 0 deletions
diff --git a/.local/bin/cmdfmt b/.local/bin/cmdfmt
new file mode 100755
index 0000000..37218d7
--- /dev/null
+++ b/.local/bin/cmdfmt
@@ -0,0 +1,34 @@
1#!/usr/bin/env perl
2
3use strict;
4
5my $textwidth = $ARGV[0] // 80;
6# TODO: get tabstop from vim as well <17-11-21, yigit> #
7my $tabstop = ' ' x 4;
8
9my $str = do { local $/; <STDIN> };
10
11my $sofar = "";
12my $buffer = "";
13
14while ($str =~ m/(.*?)\s(-?-\w+)\s+/g) {
15 my $pos = pos $str;
16
17 # TODO: use tabstop here instead of 4 <17-11-21, yigit> #
18 if (length("$buffer $sofar ") + $pos < $textwidth - 4) {
19 if ($sofar eq "") {
20 $sofar = "$buffer";
21 } else {
22 $sofar = "$sofar $buffer ";
23 }
24 $sofar = $sofar . $1;
25 $buffer = $2;
26 } else {
27 print "$sofar \\\n$tabstop$buffer ";
28 $sofar = $1;
29 $buffer = $2;
30 $str = substr $str, $pos;
31 }
32}
33
34print "$sofar $buffer $str";