[Assorted-commits] SF.net SVN: assorted: [524] shell-tools/trunk/src/bash-commons/common.bash
Brought to you by:
yangzhang
From: <yan...@us...> - 2008-02-29 03:31:41
|
Revision: 524 http://assorted.svn.sourceforge.net/assorted/?rev=524&view=rev Author: yangzhang Date: 2008-02-28 19:31:47 -0800 (Thu, 28 Feb 2008) Log Message: ----------- added named, parent-dir (for assorted.bash) Modified Paths: -------------- shell-tools/trunk/src/bash-commons/common.bash Modified: shell-tools/trunk/src/bash-commons/common.bash =================================================================== --- shell-tools/trunk/src/bash-commons/common.bash 2008-02-29 03:31:33 UTC (rev 523) +++ shell-tools/trunk/src/bash-commons/common.bash 2008-02-29 03:31:47 UTC (rev 524) @@ -350,6 +350,24 @@ fi } +# For use with parent-dir. +named() { + [[ "$( basename "$( realpath "$2" )" )" == "$1" ]] && return 0 || return 1 +} + +# Recursively search parent directories until a directory is found that +# satisfies the given predicate. The predicate is the command formed from the +# arguments passed in. +parent-dir() { + local dir=. + while true ; do + if "$@" "$dir" ; then break ; fi + if [[ "$( realpath "$dir" )" == / ]] ; then return 1 ; fi + dir="$dir/.." + done + echo "$dir" +} + is-empty() { [[ -f "$1" && "$( stat -c%s "$1" )" == 0 ]] } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |