summaryrefslogtreecommitdiff
path: root/docs/typ/scripting.typ
diff options
context:
space:
mode:
Diffstat (limited to 'docs/typ/scripting.typ')
-rw-r--r--docs/typ/scripting.typ61
1 files changed, 35 insertions, 26 deletions
diff --git a/docs/typ/scripting.typ b/docs/typ/scripting.typ
index 9d65f8de..590d71ac 100644
--- a/docs/typ/scripting.typ
+++ b/docs/typ/scripting.typ
@@ -3,21 +3,31 @@
// reference.
#import "style.typ": key, keys, btn, chord, word, tag, addr, file, cmd, doc, pairs
-Every session is a virtual filesystem, served over 9P, as acme's is: its
-panes, columns and tags are files. `cat`, `echo >` and `ls` are the whole
-interface, and a program that opens
-files is an extension. The reference (#doc("fs")) has every file.
+Every session is a virtual filesystem, served over 9P and modelled on
+acme's (#doc("reference", section: "from-acme")), so a program that opens
+files is an extension:
+
+```
+$ ls $m
+README col commands ctl exec focus index layout listeners log
+look os pager pane recent screen status tag tagexec
+$ cat $m/index
+1 term 0 /home/me/src 1
+2 text 0 /home/me/src/+New 1
+```
+
+The reference (#doc("fs")) has every file.
= Finding the session <find-the-session>
-Shells and command panes in a session get `PARDES_9P` (its socket) and
-`PARDES_PANE` (their own pane's serial). A command run from a pane's tag
-or text also gets `$winid`, the serial of the pane it was clicked in, as
-acme's commands do (unset from a column's or the workspace's tag).
+#pairs(
+ [`PARDES_9P`], [the session's socket, in every shell and command pane],
+ [`PARDES_PANE`], [the serial of the pane the shell runs in],
+ [`$winid`], [the serial of the pane a command was clicked in, as in acme (unset from a column's or the workspace's tag)],
+ [`PARDES_MOUNT`], [the session as a directory, under `9ns --mntgen` (#doc("setup", section: "ninens"))],
+)
-Under `9ns --mntgen` (see setup) every pane also gets `PARDES_MOUNT`, the
-session as a directory. That is the session line every recipe here starts
-from:
+Every recipe here starts from this line:
#cmd("m=${PARDES_MOUNT:-}\ncat \"$m/index\"")
When it is empty (no mount), plan9port's `9p` talks to the socket instead:
`cat $m/x` is `9p -a "unix!$PARDES_9P" read x`, and `echo y > $m/x` is
@@ -25,10 +35,8 @@ When it is empty (no mount), plan9port's `9p` talks to the socket instead:
= Your first tag word <first-tag-word>
-A script on `PATH` is a word you can click: command panes inherit pardes's
-environment. This `Fmt` runs `gofmt` on the Go file whose tag it was
-clicked in and reloads the pane. It finds the pane through `$winid`, not
-`PARDES_PANE`, which is the command pane it runs in:
+A script on `PATH` is a word you can click. This `Fmt` finds its pane
+through `$winid` (`PARDES_PANE` is the command pane it runs in):
```sh
#!/bin/sh
@@ -43,11 +51,9 @@ else
fi
f=$(rd pane/$n/name) # the file it shows
case $f in *.go) ;; *) echo "Fmt: $f is not Go" >&2; exit 1 ;; esac
-echo Save | wr pane/$n/ctl && gofmt -w "$f" && echo get | wr pane/$n/ctl
+echo Save | wr pane/$n/ctl && gofmt -w "$f" && echo get | wr pane/$n/ctl # get: reload
```
-`get` on a pane's ctl reloads its text from the file on disk.
-
Type `Fmt` into a Go pane's tag and #word("Exec") it (middle-click: run
the builtin a word names, or else run it as a shell line); its output
shows in a command pane. To have `Fmt` in every Go file's tag, follow the
@@ -99,10 +105,8 @@ the text names, or else find it): they arrive as acme's records instead of actin
record back has pardes do it. A record is a line, `MX31 36 1 5 Upper`: who
(`M` mouse, `K` keyboard, `E` or `F` a write to a file), what (`X` #word("Exec") or `L` #word("Look")
in the body, `x` `l` in the tag), the range, a flag, the text's length and
-the text (#doc("fs", section: "event")). This helper
-gives pane `$1` the tag words `Upper` (upper-case the selection) and
-`Done`; every other click is written back, and when it ends the pane's
-clicks are pardes's again:
+the text (#doc("fs", section: "event")). This helper owns the tag words
+`Upper` and `Done` in pane `$1` and writes every other click back:
```bash
#!/bin/bash
@@ -147,7 +151,12 @@ exec 3<&- # let event go: clicks act again
= An isolated session
-Never experiment on a session someone is using. Strip every `PARDES_*`
-variable first, then `pardes --detach=NAME &` with its own `HOME` and
-`XDG_*` directories, and mount it with `9ns --mntgen` (it is
-`$NINE_MOUNT/pardes/NAME`). Kill it when done.
+Never experiment on a session someone is using. Under `9ns --mntgen`,
+start one with an empty environment and home, and quit it when done:
+
+```
+env -i PATH="$PATH" HOME="$(mktemp -d)" XDG_RUNTIME_DIR="$XDG_RUNTIME_DIR" pardes --detach=try &
+m=$NINE_MOUNT/pardes/try
+cat $m/index
+echo Exit > $m/exec
+```