diff --git a/bin/nuxfs b/bin/nuxfs index 6ba33cf..8979934 100755 --- a/bin/nuxfs +++ b/bin/nuxfs @@ -26,7 +26,7 @@ function task.verify { local cdir=$(dirname "$1") MAT_TARGET=$(realpath "$cdir/$TARGET") if test "$MAT_REAL" = "$MAT_TARGET"; then - nuxfs.warning "$1" "links to target '$2', but is using different definition." + nuxfs.warning "$1" "is using different definition for target '$2'" else nuxfs.error "$1" "links to $REAL_LINK instead of $TARGET" return @@ -51,7 +51,8 @@ function task.verify { def.notexists() { nuxfs.error "$1" "does not exists". } - nuxfs.dsl.execute .nuxfs + nuxfs.initcfg + nuxfs.dsl.execute "$NUXFS_DEF" "$NUXFS_DEF_DIR" "$WORKDIR_ABSOLUTE" } ## create - Creates missing files as described in nuxfs definition. @@ -75,7 +76,8 @@ function task.create { popd > /dev/null; } - nuxfs.dsl.execute $SUFFIX + nuxfs.initcfg + nuxfs.dsl.execute "$NUXFS_DEF" "$NUXFS_DEF_DIR" "$WORKDIR_ABSOLUTE" } ## init - Initializes a directory using template @@ -129,3 +131,18 @@ function nuxfs.template.list { done; popd > /dev/null; } + + +function nuxfs.initcfg { + + WORKDIR=$(pwd); + NUXFS_DEF=$(nuxfs.closest $SUFFIX); + + if [ "$NUXFS_DEF" = "" ]; then + nuxfs.error $(pwd) "No nuxfs configuration found." + exit 1; + fi; + NUXFS_DEF_DIR=$(dirname $NUXFS_DEF); + WORKDIR_RELATIVE=$(realpath "$WORKDIR" --relative-to "$NUXFS_DEF_DIR") + WORKDIR_ABSOLUTE=$(realpath "$WORKDIR") +} diff --git a/inc/nuxfs.dsl.inc.sh b/inc/nuxfs.dsl.inc.sh index ca047ed..700b24d 100644 --- a/inc/nuxfs.dsl.inc.sh +++ b/inc/nuxfs.dsl.inc.sh @@ -21,20 +21,24 @@ function exec.if.function { function nuxfs.dsl.command { CMD=$1; localFile=$(nuxfs.relative "$2"); - shift; shift; - nux.log debug Processing $CMD "$localFile" $@; + + shift; shift; + nux.log trace Processing $CMD "$localFile" $@; exec.if.function $CMD.pre def.pre "$localFile" "$@"; - nux.log debug Working file: $NC_White$localFile; + if [[ "$NESTED_DIR" = "$localFile"* || "$localFile" = "$NESTED_DIR"* ]]; then + nux.log debug $localFile is affected by $NESTED_DIR; + if nuxfs.file.exists "$localFile"; then - nux.log debug "File $localFile exits"; + nux.log debug "File $NC_White$localFile$NC_No exits"; exec.if.function $CMD.exists def.exists "$localFile" "$@"; else - nux.log debug "File $localFile does not exists"; + nux.log debug "File $NC_White$localFile$NC_No does not exists"; exec.if.function $CMD.notexists def.notexists "$localFile" "$@"; fi + fi exec.if.function $CMD.post def.post "$localFile" "$@"; } @@ -91,11 +95,15 @@ function nuxfs.dsl.keywords { function nuxfs.dsl.execute { nuxfs.dsl.keywords + local DEF="$1"; + local DIR="$2"; + NESTED_DIR="$(realpath "$3")/"; + nux.log debug "Working Directory: $DIR , Nested Directory: $NESTED_DIR" declare -a DIR_ARRAY - DIR_ARRAY[0]=. - if test -e "$1"; then - source $1; + DIR_ARRAY[0]=$DIR + if test -e "$DEF"; then + source "$DEF"; else - nuxfs.error "$1" Definition file does not exists. + nuxfs.error "$DEF" Definition file does not exists. fi } diff --git a/inc/nuxfs.inc.sh b/inc/nuxfs.inc.sh index 47920ea..bb357dc 100644 --- a/inc/nuxfs.inc.sh +++ b/inc/nuxfs.inc.sh @@ -33,3 +33,16 @@ function nuxfs.dir.push { function nuxfs.file.exists { test -e "$1" -o -h "$1"; } + +function nuxfs.closest { + cmd=$1; + cdir=$(pwd); + nux.log trace "Searching in: " $cdir; + until [ -e "$cdir/$1" -o "$cdir" == "/" ]; do + cdir=$(dirname "$cdir"); + nux.log trace "Searching in: " $cdir; + done; + if [ -e "$cdir/$1" ]; then + echo "$cdir/$1"; + fi +}