feat: initial commit
This commit is contained in:
commit
02ec07cef2
5 changed files with 96 additions and 0 deletions
22
LICENSE
Normal file
22
LICENSE
Normal file
|
@ -0,0 +1,22 @@
|
|||
Copyright (c) 2022 ptrcnull
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
README.md
Normal file
31
README.md
Normal file
|
@ -0,0 +1,31 @@
|
|||
# execline-state
|
||||
|
||||
> in spite of skarnet's "execline maintains no state"
|
||||
|
||||
a simple shift register built on piperw(1)
|
||||
|
||||
### usage
|
||||
|
||||
```
|
||||
init-state <name>
|
||||
load-state <name> <target>
|
||||
save-state <name> <value>
|
||||
```
|
||||
|
||||
```sh
|
||||
#!/bin/execlineb
|
||||
|
||||
init-state flip
|
||||
save-state flip "up"
|
||||
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"
|
||||
}
|
||||
save-state flip "$current"
|
||||
```
|
16
init-state
Executable file
16
init-state
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/execlineb
|
||||
|
||||
backtick -E top_fd {
|
||||
pipeline { s6-ls /proc/self/fd }
|
||||
s6-tail -n 1
|
||||
}
|
||||
backtick -E rdfd { s6-expr ${top_fd} + 1 }
|
||||
backtick -E wrfd { s6-expr ${top_fd} + 2 }
|
||||
piperw $rdfd $wrfd
|
||||
|
||||
importas -ui name 1
|
||||
shift
|
||||
export ELSTATE_${name} $rdfd
|
||||
|
||||
elgetpositionals
|
||||
$@
|
12
load-state
Executable file
12
load-state
Executable file
|
@ -0,0 +1,12 @@
|
|||
#!/bin/execlineb
|
||||
|
||||
importas -ui name 1
|
||||
importas -ui target 2
|
||||
importas -i rdfd ELSTATE_${name}
|
||||
|
||||
fdswap 0 ${rdfd}
|
||||
shift -n 2
|
||||
elgetpositionals
|
||||
forstdin -E -o 100 ${target} # chosen by fair dice roll
|
||||
fdswap 0 ${rdfd}
|
||||
$@
|
15
save-state
Executable file
15
save-state
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/execlineb
|
||||
|
||||
importas -ui name 1
|
||||
importas -ui value 2
|
||||
importas -i rdfd ELSTATE_${name}
|
||||
backtick -E wrfd { s6-expr "$rdfd" + 1 }
|
||||
|
||||
foreground {
|
||||
fdmove -c 1 ${wrfd}
|
||||
echo "$value"
|
||||
}
|
||||
shift -n 2
|
||||
|
||||
elgetpositionals
|
||||
$@
|
Loading…
Reference in a new issue