Update scripts
This commit is contained in:
parent
191a62616d
commit
eb828202e2
3 changed files with 18 additions and 19 deletions
|
|
@ -72,12 +72,12 @@ I spawn Acme by running `a` script.
|
|||
Who is who in **bin** directory:
|
||||
|
||||
- `a` start Acme
|
||||
- `b` create an indented C-like block `{ ... }`
|
||||
- `c SYMBOL`/`uc SYMBOL` comment/uncomment selection
|
||||
- `commit MESSAGE` commit and push to master
|
||||
- `hd SYMBOL` draw a pretty heading
|
||||
- `i`/`ui` indent/unindent selection
|
||||
- `lstrip` remove leading whitespace
|
||||
- `nobs` from Plan9
|
||||
- `search` search with The Silver Searcher
|
||||
- `t2s N_SPACES`/`s2t N_SPACES` tabs <=> spaces
|
||||
- `upper`/`lower` convert selection to uppercase/lowercase
|
||||
|
|
|
|||
32
bin/b
32
bin/b
|
|
@ -1,20 +1,22 @@
|
|||
#!/usr/bin/env perl
|
||||
#!/usr/bin/env bash
|
||||
|
||||
my $winid = $ENV{winid};
|
||||
# Select `b` (or before it, or after) and assign Acme `addr` to selection
|
||||
echo addr=dot | 9p write acme/$winid/ctl
|
||||
|
||||
system "echo addr=dot | 9p write acme/$winid/ctl";
|
||||
# Mark the current line and change `addr` to it
|
||||
echo -n '__MARKER__' | 9p write acme/$winid/data
|
||||
echo -n '/^.*__MARKER__/' | 9p write acme/$winid/addr
|
||||
|
||||
system qq(bash -c 'echo -n "__MARKER__"' | 9p write acme/$winid/data);
|
||||
# Process the line
|
||||
line=$(9p read acme/$winid/data | sed 1q)
|
||||
indentation=$(echo "$line" | sed -E 's/^( *).*$/\1/')
|
||||
before_marker=$(echo "$line" | sed -E 's/b?__MARKER__.*$/{/')
|
||||
after_marker=$(echo "$line" | awk -F'__MARKER__' '{print $2}')
|
||||
[ "$after_marker" == "b" ] && after_marker=""
|
||||
|
||||
system qq(bash -c "echo -n '/^.*__MARKER__/'" | 9p write acme/$winid/addr);
|
||||
# Compose the final block
|
||||
block="$before_marker"$'\n'"$indentation "$'\n'"$indentation}$after_marker"
|
||||
|
||||
my $data = `9p read acme/$winid/data`;
|
||||
|
||||
my ($line) = $data =~ /^(.*) b__MARKER__/;
|
||||
|
||||
my ($whitespace) = $line =~ /^(\s*)/;
|
||||
|
||||
$line = "$line {\n$whitespace\t\n$whitespace}";
|
||||
|
||||
system qq(bash -c "echo -n '/^.*__MARKER__/'" | 9p write acme/$winid/addr);
|
||||
system qq(bash -c "echo -n '$line'" | 9p write acme/$winid/data);
|
||||
# Change `addr` one more time and replace original line with my block
|
||||
echo -n '/^.*__MARKER__.*\n?/' | 9p write acme/$winid/addr
|
||||
echo "$block" | 9p write acme/$winid/data
|
||||
|
|
|
|||
3
bin/nobs
3
bin/nobs
|
|
@ -1,3 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
sed 's/.//g' "$@"
|
||||
Loading…
Add table
Add a link
Reference in a new issue