diff --git a/README.md b/README.md index 5172d1f..fc8dc4c 100644 --- a/README.md +++ b/README.md @@ -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 } +``` diff --git a/elevate b/elevate new file mode 100755 index 0000000..f67c585 --- /dev/null +++ b/elevate @@ -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 +$@ diff --git a/iscmd b/iscmd new file mode 100755 index 0000000..7f1b921 --- /dev/null +++ b/iscmd @@ -0,0 +1,5 @@ +#!/bin/execlineb + +elgetpositionals +redirfd -w 1 /dev/null +where $1 diff --git a/where b/where new file mode 100755 index 0000000..13d8ee8 --- /dev/null +++ b/where @@ -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"