This commit is contained in:
Ev Bogdanov 2017-01-26 19:29:57 +03:00
commit c2271ba672
43 changed files with 886 additions and 0 deletions

33
bin/+ Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
sub do_calc {
my ($op, $acc, @args) = @_;
for my $arg (@args) {
$acc += $arg if $op eq '+';
$acc -= $arg if $op eq '-';
$acc *= $arg if $op eq '*';
$acc /= $arg if $op eq '/';
}
return $acc;
}
sub calc {
my $exp = shift;
die 'oops!' unless $exp =~ m/\(([\+-\/\*])([0-9 \.-]+)\)/;
return do_calc($1, split ' ', $2);
}
sub pn {
my $exp = shift;
my $old = $exp;
$exp =~ s/(\([\+-\/\*] [0-9 \.-]+\))/calc($1)/eg;
die "oops! i'm stuck" if $exp eq $old;
return $exp if $exp =~ m/^[0-9 \.-]+$/;
return pn($exp);
}
say pn($ARGV[0]);

15
bin/F Executable file
View file

@ -0,0 +1,15 @@
#!/usr/bin/env bash
if [[ $# -eq 1 ]]; then
perl -C -Mutf8 -lanE "$1"
elif [[ $# -eq 2 ]]; then
if [[ -f "$2" ]]; then
perl -C -Mutf8 -lanE "$1" "$2"
else
perl -C -Mutf8 -F''"$1"'' -lanE "$2"
fi
elif [[ $# -eq 3 && -f "$3" ]]; then
perl -C -Mutf8 -F''"$1"'' -lanE "$2" "$3"
fi

18
bin/a Executable file
View file

@ -0,0 +1,18 @@
#!/usr/bin/env bash
export SHELL="$PLAN9/bin/rc"
export acmeshell="$PLAN9/bin/rc"
export BROWSER=safari
export tabstop=4
export TERM=dumb
export PAGER=nobs
if [ "$(pgrep plumber)" ]; then
echo plumber is running
else
echo starting plumber
plumber
cat "$HOME/acme/plumbing" "$PLAN9/plumb/basic" | 9p write plumb/rules
fi
acme -a -f /mnt/font/Menlo-Regular/12a/font $1

38
bin/a+ Executable file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use open qw(:std :utf8);
my ($d) = @ARGV;
$d = "=>" unless $d;
my $max = 0;
my @ls = ();
my @rs = ();
my $i = 1;
my $t = "";
while (<STDIN>) {
if ($i == 1) {
$t = $1 if /^(\s+)/;
$i += 1;
}
$_ =~ s/^\s+|\s+$//g;
my @ls_rs = split $d, $_, 2;
my $len = length $ls_rs[0];
$max = $len if $len > $max;
push @ls, $ls_rs[0];
push @rs, $ls_rs[1];
}
for (my $i = 0; $i < @ls; $i += 1) {
my $l = $ls[$i];
my $r = $rs[$i];
my $n = $max - length $l;
my $s = " " x $n;
$l .= $s;
print $t, $l, $d, $r;
print "\n" unless $i + 1 == @ls;
}

10
bin/c+ Executable file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env perl
my ($symbol) = @ARGV;
# default: | c+ '#'
$symbol = '#' unless $symbol;
while (<STDIN>) {
print "$symbol$_";
}

12
bin/c- Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env perl
# default: 1 symbol comment: #, %
# need ARGV for comments like this: //
my ($symbol) = @ARGV;
my $offset = $symbol ? length $symbol : 1;
while (<STDIN>) {
print substr $_, $offset;
}

5
bin/cc+ Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env perl
while (<STDIN>) {
print join "", map { ucfirst $_ } (split "_", $_);
}

7
bin/cc- Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env perl
while (<STDIN>) {
s/([A-Z]+)([A-Z][a-z])/$1_$2/g;
s/([a-z\d])([A-Z])/$1_$2/g;
print lc;
}

5
bin/d Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env perl
open FH, "| 9p write acme/$ENV{winid}/addr";
print FH ",";
system "9p write acme/$ENV{winid}/data </dev/null";

9
bin/eman Executable file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env bash
if [ $# -ne 1 ]
then
echo 'gimme erlang module, pls'
exit 1
fi
erl -man "$1" | nobs+

21
bin/g+ Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env perl
## VERY NICE: USE `g+` IN COMBO WITH MOUSE CHORD
## -----------------------------------------------------------------------------
## To search for literal text in the current directory:
## 1. point at text with button 1 in any window
## 2. release button 1
## 3. execute `g+`, clicking button 1 while 2 is held down
use strict;
use warnings;
use Cwd;
die "don't know what to grep" unless @ARGV;
my $what = join ' ', @ARGV;
my $cwd = getcwd();
my $result = `grep -nR '$what' $cwd`;
print $result;

11
bin/git+ Executable file
View file

@ -0,0 +1,11 @@
#!/usr/bin/env bash
if [ $# -eq 0 ]
then
echo where is my commit message, bro?
exit 1
fi
git add -A
git commit -m ''"$*"''
git push -u origin master

32
bin/h+ Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use utf8;
use open qw(:std :utf8);
my $symbol = '#';
my $line = readline(STDIN) // '';
chomp($line);
## 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;
}
say $symbol x 2, ' ', uc $line;
print $symbol x 2, ' ', '-' x 77;

36
bin/hg+ Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Cwd;
die 'please enter commit message' unless @ARGV;
my $msg = join ' ', @ARGV;
my $dir = getcwd();
system "hg --cwd $dir addremove";
system "hg --cwd $dir commit -m '$msg'";
system "hg --cwd $dir push";
my $hgrc = "$dir/.hg/hgrc";
open my $fh, '<', $hgrc
or die "cannot open $hgrc: $!\n";
my $repository;
while (my $line = readline($fh)) {
if ($line =~ m/^bb\.prefix = (.+)$/) {
$repository = $1;
last;
}
}
close $fh;
if ($repository) {
print "\nview commits:\n";
print "$repository/commits/all\n";
}

16
bin/html+ Executable file
View file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
cat << 'HTML'
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>title</title>
<!-- <link rel="shortcut icon" href="/favicon.ico"> -->
<!-- <link rel="stylesheet" href="style.css"> -->
</head>
<body>
</body>
</html>
HTML

8
bin/lc+ Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env perl
use utf8;
use open qw(:std :utf8);
while (<>) {
print lc $_;
}

3
bin/lne Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
perl -C -Mutf8 -lnE "$@"

3
bin/lpe Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
perl -C -Mutf8 -lpE "$@"

3
bin/ne Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
perl -C -Mutf8 -nE "$@"

3
bin/nobs+ Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
sed 's/.//g' "$@"

3
bin/pe Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
perl -C -Mutf8 -pE "$@"

19
bin/perl+ Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env perl
$template = <<'TMP';
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use experimental 'signatures';
sub main {
}
main();
TMP
print $template;

72
bin/put+ Executable file
View file

@ -0,0 +1,72 @@
#!/usr/bin/env perl
use strict;
use warnings;
## USAGE
## -----------------------------------------------------------------------------
## firefox:
## put+ ff
## chrome:
## put+ ch
## safari:
## put+ sa
## DATA
## -----------------------------------------------------------------------------
use constant FIREFOX => 'ff';
use constant CHROME => 'ch';
use constant SAFARI => 'sa';
my $browser = $ARGV[0] || CHROME;
my $osascript;
## ACME 'Put'
## -----------------------------------------------------------------------------
open my $fh, "| 9p write acme/$ENV{winid}/ctl";
print $fh "put\n";
close $fh;
## FIREFOX SCRIPT (SADLY, IT'S FULL OF BUGS)
## -----------------------------------------------------------------------------
if ($browser eq FIREFOX) {
$osascript = 'tell application "Firefox"
activate
delay 2
tell application "System Events"
keystroke "r" using command down
end tell
end tell';
}
## CHROME SCRIPT
## -----------------------------------------------------------------------------
if ($browser eq CHROME) {
## wait for server update
sleep 2;
$osascript = 'tell application "Google Chrome" to reload active tab of window 1';
}
## SAFARI SCRIPT
## -----------------------------------------------------------------------------
if ($browser eq SAFARI) {
## also wait for server update
sleep 2;
$osascript = 'tell application "Safari"
set docUrl to URL of document 1
set URL of document 1 to docUrl
end tell';
}
## RUN SCRIPT
## -----------------------------------------------------------------------------
system "osascript -e '$osascript'";

10
bin/s- Executable file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env perl
while (<>) {
if ($_ =~ m/^\s+$/) {
print "\n";
} else {
$_ =~ s/^\s+//;
print $_;
}
}

19
bin/s2t Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env perl
use strict;
use warnings;
my $N_SPACES = $ARGV[0] || 4;
while (my $line = <STDIN>) {
# Skip empty lines
print "\n" and next if $line !~ m/\S/;
$line =~ m/^(\s*)(.+)$/;
my $n_spaces = length($1);
my $n_tabs = ($n_spaces > 0 and $n_spaces < $N_SPACES)
? 1
: int($n_spaces / $N_SPACES);
print "\t" x $n_tabs . "$2\n";
}

5
bin/t+ Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env perl
while (<>) {
print "\t$_";
}

6
bin/t- Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env perl
while (<>) {
$_ =~ s/^\t//;
print $_;
}

17
bin/t2s Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env perl
use strict;
use warnings;
my $N_SPACES = $ARGV[0] || 4;
while (my $line = <STDIN>) {
# Skip empty lines
print "\n" and next if $line !~ m/\S/;
$line =~ m/^(\t*)(.+)$/;
my $n_tabs = length($1);
my $n_spaces = $n_tabs * $N_SPACES;
print ' ' x $n_spaces . "$2\n";
}

8
bin/uc+ Executable file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env perl
use utf8;
use open qw(:std :utf8);
while (<>) {
print uc $_;
}

63
bin/w+ Executable file
View file

@ -0,0 +1,63 @@
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use utf8;
use open qw(:std :utf8);
my $WIDTH_DEFAULT = 80;
my $WIDTH = $ARGV[0] || $WIDTH_DEFAULT;
sub main {
my $buf = '';
while (my $line = <STDIN>) {
if ($line =~ /^\s+$/) {
say $buf;
say '' if ($buf);
$buf = '';
next;
}
if ($buf) {
$line = $buf . $line;
}
my ($head, $tail) = handle_str($line);
say $head;
$buf = handle_buf($tail);
}
say $buf if $buf;
}
sub handle_buf {
my $buf = shift;
my $len = length($buf);
if ($len == $WIDTH) {
say $buf;
return '';
}
if ($len < $WIDTH) {
return $buf;
}
## $len > $WIDTH
my ($head, $tail) = handle_str($buf);
say $head;
handle_buf($tail);
}
sub handle_str {
my $str = shift;
if ($str =~ m/^(.{0,$WIDTH})\s(.*)$/) {
return ($1, $2);
}
## no spaces here: 0..$WIDTH
if ($str =~ m/^(\S*)\s(.*)$/) {
return ($1, $2);
}
## no whitespace at all
if ($str =~ m/^(\S+)$/) {
return ($1, '');
}
die "ooops!";
}
main();