misc/bin/find-parent
2022-05-20 12:44:13 +02:00

32 lines
694 B
Text
Executable file

#!/usr/bin/env execlineb
elgetopt d
elgetpositionals
importas -D "" dironly ELGETOPT_d
if -nt { test $# -eq 0 }
define FOUND 69
foreground {
# look for each pattern (in cwd)
forx -E -x$FOUND pat { $@ }
# if a file exists, exit with $FOUND, which breaks the loop
elglob -0 files $pat
forx -E -x$FOUND file { $files }
ifthenelse { test -n $dironly } { pwd } { readlink -f $file }
exit $FOUND
}
importas result ?
# if the loop exited with $FOUND then we're done
if -nt { test $result -eq $FOUND }
# if we're at / give up
if -n -x1 {
getcwd -E cwd
test $cwd = /
}
cd ..
ifelse { test -n $dironly } { find-parent -d $@ } find-parent $@
# vim: set ft=execline :