summaryrefslogtreecommitdiffstats
path: root/.local
diff options
context:
space:
mode:
authorYigit Sever2021-11-17 12:17:17 +0300
committerYigit Sever2021-11-17 12:17:17 +0300
commita0d26185d3b78862f1f8399392122a3df08c631d (patch)
tree1bc82199bd700f8f8544740f6975bc45c775e9b9 /.local
parent5be72a005ec23eedde080731060f5b1bbbf1bc74 (diff)
downloaddotfiles-a0d26185d3b78862f1f8399392122a3df08c631d.tar.gz
dotfiles-a0d26185d3b78862f1f8399392122a3df08c631d.tar.bz2
dotfiles-a0d26185d3b78862f1f8399392122a3df08c631d.zip
bin: tracking command formatter
diffstat (limited to '.local')
-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";