diff options
| author | Yigit Sever | 2021-11-17 12:17:17 +0300 |
|---|---|---|
| committer | Yigit Sever | 2021-11-17 12:17:17 +0300 |
| commit | a0d26185d3b78862f1f8399392122a3df08c631d (patch) | |
| tree | 1bc82199bd700f8f8544740f6975bc45c775e9b9 /.local/bin | |
| parent | 5be72a005ec23eedde080731060f5b1bbbf1bc74 (diff) | |
| download | dotfiles-a0d26185d3b78862f1f8399392122a3df08c631d.tar.gz dotfiles-a0d26185d3b78862f1f8399392122a3df08c631d.tar.bz2 dotfiles-a0d26185d3b78862f1f8399392122a3df08c631d.zip | |
bin: tracking command formatter
Diffstat (limited to '.local/bin')
| -rwxr-xr-x | .local/bin/cmdfmt | 34 |
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 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | my $textwidth = $ARGV[0] // 80; | ||
| 6 | # TODO: get tabstop from vim as well <17-11-21, yigit> # | ||
| 7 | my $tabstop = ' ' x 4; | ||
| 8 | |||
| 9 | my $str = do { local $/; <STDIN> }; | ||
| 10 | |||
| 11 | my $sofar = ""; | ||
| 12 | my $buffer = ""; | ||
| 13 | |||
| 14 | while ($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 | |||
| 34 | print "$sofar $buffer $str"; | ||
