2022-08-05 19:19:57 +00:00
|
|
|
# execline-state
|
|
|
|
|
|
|
|
> in spite of skarnet's "execline maintains no state"
|
|
|
|
|
|
|
|
a simple shift register built on piperw(1)
|
|
|
|
|
2022-08-05 20:40:01 +00:00
|
|
|
requirements:
|
|
|
|
- execline (obviously)
|
|
|
|
- s6-portable-utils (s6-expr, s6-ls, s6-tail)
|
|
|
|
|
2022-08-05 19:19:57 +00:00
|
|
|
### usage
|
|
|
|
|
|
|
|
```
|
|
|
|
init-state <name>
|
|
|
|
load-state <name> <target>
|
|
|
|
save-state <name> <value>
|
2022-08-05 20:36:46 +00:00
|
|
|
nuke-state <name>
|
2022-08-05 19:19:57 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
```sh
|
|
|
|
#!/bin/execlineb
|
|
|
|
|
|
|
|
init-state flip
|
|
|
|
save-state flip "up"
|
2022-08-05 20:36:46 +00:00
|
|
|
foreground {
|
|
|
|
forstdin -E line
|
|
|
|
load-state flip current
|
|
|
|
println "! state: $current"
|
|
|
|
ifelse { s6-test "$line" = "flip" } {
|
|
|
|
println "! flipping state"
|
|
|
|
ifelse { s6-test "$current" = "up" } {
|
|
|
|
save-state flip "down"
|
|
|
|
}
|
|
|
|
save-state flip "up"
|
2022-08-05 19:19:57 +00:00
|
|
|
}
|
2022-08-05 20:36:46 +00:00
|
|
|
save-state flip "$current"
|
|
|
|
}
|
|
|
|
nuke-state flip
|
2022-08-05 19:19:57 +00:00
|
|
|
```
|