feat: add elevate, where, iscmd

This commit is contained in:
ptrcnull 2022-08-05 19:06:16 +02:00
parent f90359b028
commit 55b9261cfd
4 changed files with 54 additions and 3 deletions

View file

@ -2,7 +2,7 @@
> fun execline scripts to try at home
### println
#### println
like echo, but chainable
@ -11,7 +11,7 @@ println "test"
echo test1
```
### eprintln
#### eprintln
println but to stderr :)
@ -20,7 +20,7 @@ eprintln "test"
echo test1
```
### tdefine
#### tdefine
ternary define: `$1 = if ($4) { $2 } { $3 } cmd...`
@ -30,3 +30,28 @@ tdefine sucmd "doas" "exec" { s6-test $uid != 0 }
$sucmd s6-linux-init-shutdown
```
#### elevate
the same thing from above but just one command (and with sudo fallback)
```sh
elevate s6-linux-init-shutdown
```
#### where
which(1) but in execline
```sh
backtick -E sh { where sh }
echo "shell full path: $sh"
```
#### iscmd
exits with 0 if command exists
```sh
tdefine shell "zsh" "sh" { iscmd zsh }
```

8
elevate Executable file
View file

@ -0,0 +1,8 @@
#!/bin/execlineb
backtick -E uid { id -u }
tdefine lift "doas" "sudo" { iscmd doas }
tdefine sucmd "$lift" "exec" { s6-test $uid != 0 }
elgetpositionals
$sucmd
$@

5
iscmd Executable file
View file

@ -0,0 +1,5 @@
#!/bin/execlineb
elgetpositionals
redirfd -w 1 /dev/null
where $1

13
where Executable file
View file

@ -0,0 +1,13 @@
#!/bin/execlineb
elgetpositionals
importas -isd ":" path PATH
backtick -E result {
forx -E -x 0 dir { $path }
if { s6-test -x ${dir}/$1 }
echo ${dir}/$1
}
if { s6-test -n "$result" }
echo "$result"