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` comment selection (python: `|c+` or `|c+ '#'`, erlang: `|c+ %`, js: `|c+ //`)
|
||||||
- `c- SYMBOL` uncomment selection
|
- `c- SYMBOL` uncomment selection
|
||||||
- `git+ MESSAGE` git: commit and push to master
|
- `git+ MESSAGE` git: commit and push to master
|
||||||
- `h+` heading
|
- `h+ SYMBOL` draw a pretty heading
|
||||||
- `hg+ MESSAGE` hg: commit and push to master
|
- `hg+ MESSAGE` hg: commit and push to master
|
||||||
- `lc+` to lowercase
|
- `lc+` to lowercase
|
||||||
- `nobs+` taken from plan9 `nobs` (it removes all backspace characters and the characters that precede them)
|
- `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;
|
symbols="$1"
|
||||||
use warnings;
|
|
||||||
use feature 'say';
|
|
||||||
use utf8;
|
|
||||||
use open qw(:std :utf8);
|
|
||||||
|
|
||||||
my $symbol = '#';
|
symbol=${symbols:0:1}
|
||||||
my $line = readline(STDIN) // '';
|
|
||||||
chomp($line);
|
|
||||||
|
|
||||||
## add more comment symbols?
|
if [ ! "$symbol" ]; then
|
||||||
## now supported:
|
symbol='#'
|
||||||
## '#' -- default for bash, perl, ...
|
fi
|
||||||
## '%' -- 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
say $symbol x 2, ' ', uc $line;
|
line=$(sed 1q | uc+)
|
||||||
print $symbol x 2, ' ', '-' x 77;
|
|
||||||
|
echo "$symbol$symbol $line"
|
||||||
|
echo "$symbol$symbol -----------------------------------------------------------------------------"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue