first
This commit is contained in:
commit
8f688f4105
5 changed files with 314 additions and 0 deletions
32
bin/find-parent
Executable file
32
bin/find-parent
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env execlineb
|
||||
|
||||
elgetopt d
|
||||
elgetpositionals
|
||||
importas -D "" dironly ELGETOPT_d
|
||||
|
||||
if -nt { test $# -eq 0 }
|
||||
|
||||
define FOUND 69
|
||||
foreground {
|
||||
# look for each file (in cwd)
|
||||
forx -E -x$FOUND pat { $@ }
|
||||
# if 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 :
|
Loading…
Add table
Add a link
Reference in a new issue