Rewrite the heading script
This commit is contained in:
parent
7eb22341f2
commit
ce5b9c0d82
2 changed files with 11 additions and 29 deletions
|
|
@ -86,7 +86,7 @@ Who is who in **bin** directory:
|
|||
- `c+ SYMBOL` comment selection (python: `|c+` or `|c+ '#'`, erlang: `|c+ %`, js: `|c+ //`)
|
||||
- `c- SYMBOL` uncomment selection
|
||||
- `git+ MESSAGE` git: commit and push to master
|
||||
- `h+` heading
|
||||
- `h+ SYMBOL` draw a pretty heading
|
||||
- `hg+ MESSAGE` hg: commit and push to master
|
||||
- `lc+` to lowercase
|
||||
- `nobs+` taken from plan9 `nobs` (it removes all backspace characters and the characters that precede them)
|
||||
|
|
|
|||
38
bin/h+
38
bin/h+
|
|
@ -1,32 +1,14 @@
|
|||
#!/usr/bin/env perl
|
||||
#!/usr/bin/env bash
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use feature 'say';
|
||||
use utf8;
|
||||
use open qw(:std :utf8);
|
||||
symbols="$1"
|
||||
|
||||
my $symbol = '#';
|
||||
my $line = readline(STDIN) // '';
|
||||
chomp($line);
|
||||
symbol=${symbols:0:1}
|
||||
|
||||
## add more comment symbols?
|
||||
## now supported:
|
||||
## '#' -- default for bash, perl, ...
|
||||
## '%' -- erlang
|
||||
## '/' -- js, c, ...
|
||||
## ';' -- lisp
|
||||
if (
|
||||
$line =~ m{
|
||||
^([#%/;]) # line starts with comment symbol
|
||||
\1* # symbol can be repeated
|
||||
\s # first space separates symbol from content
|
||||
(.+)$ # heading content
|
||||
}x
|
||||
) {
|
||||
$symbol = $1;
|
||||
$line = $2;
|
||||
}
|
||||
if [ ! "$symbol" ]; then
|
||||
symbol='#'
|
||||
fi
|
||||
|
||||
say $symbol x 2, ' ', uc $line;
|
||||
print $symbol x 2, ' ', '-' x 77;
|
||||
line=$(sed 1q | uc+)
|
||||
|
||||
echo "$symbol$symbol $line"
|
||||
echo "$symbol$symbol -----------------------------------------------------------------------------"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue