From eb828202e2abf2b2f2509eac9bb198a3fa55d3e7 Mon Sep 17 00:00:00 2001 From: Ev Bogdanov Date: Wed, 17 Jan 2018 14:00:11 +0300 Subject: [PATCH] Update scripts --- README.md | 2 +- bin/b | 32 +++++++++++++++++--------------- bin/nobs | 3 --- 3 files changed, 18 insertions(+), 19 deletions(-) delete mode 100755 bin/nobs diff --git a/README.md b/README.md index 2447fc6..4dd2bd8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bin/b b/bin/b index 496b25a..56e5da9 100755 --- a/bin/b +++ b/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 diff --git a/bin/nobs b/bin/nobs deleted file mode 100755 index 241a964..0000000 --- a/bin/nobs +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -sed 's/.//g' "$@"