summaryrefslogtreecommitdiff
path: root/.local/bin/b
diff options
context:
space:
mode:
authorJacob McDonnell <jacob@simplelittledream.com>2022-07-14 19:09:06 -0400
committerJacob McDonnell <jacob@simplelittledream.com>2022-07-14 19:09:06 -0400
commited4daf7429bf2580118aad87b8f3e2011efed7ec (patch)
tree82f9d8ed68de119e5777f5ecfae9df4a92fe92b3 /.local/bin/b
Initial commit
Diffstat (limited to '.local/bin/b')
-rwxr-xr-x.local/bin/b22
1 files changed, 22 insertions, 0 deletions
diff --git a/.local/bin/b b/.local/bin/b
new file mode 100755
index 0000000..596b320
--- /dev/null
+++ b/.local/bin/b
@@ -0,0 +1,22 @@
+#!/usr/bin/env bash
+
+# Select `b` (or before it, or after) and assign Acme `addr` to selection
+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
+
+# 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=""
+
+# Compose the final block
+block="$before_marker"$'\n'"$indentation "$'\n'"$indentation}$after_marker"
+
+# 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 \ No newline at end of file