diff --git a/bin/nuxfs b/bin/nuxfs index 9978eee..eb70f17 100755 --- a/bin/nuxfs +++ b/bin/nuxfs @@ -11,6 +11,7 @@ nux.include nuxfs nux.include nuxfs.dsl GIT_BIN=$(which git) + ## check - Verifies that directory matches nuxfs specification function task.check { link.exists() { @@ -137,6 +138,64 @@ function task.info { fi; } +function nuxfs.dsl.capture.dir { + local CDIR=$1; + local LEVEL=$2; + nux.log debug "Inspecting directory $CDIR"; + + if [ -e "$RELATIVE/$SUFFIX" ]; then + return; + fi; + + pushd "$CDIR" > /dev/null; + for file in ./* ; do + nuxfs.dsl.capture.file "$file" "."; + done; + popd > /dev/null; +} + +function nuxfs.dsl.capture.file { + local file=$1; + local pdir=$2; + local RELATIVE=$(realpath -ms "$file" --relative-to "$pdir"); + local ADDARGS=""; + local TYPE=""; + nux.log debug "Inspecting $file , Relative path is $RELATIVE"; + if [ -h "$RELATIVE" ]; then + TYPE="link"; + ADDARGS="\"$(readlink "$RELATIVE")\"" + elif [ -d "$RELATIVE" -a -d "$RELATIVE/.git" ]; then + TYPE=git; + pushd "$RELATIVE" > /dev/null; + ADDARGS="\"$($GIT_BIN remote get-url origin)\"" + popd > /dev/null; + elif [ -d "$RELATIVE" ]; then + TYPE="dir"; + fi; + + if [ "$TYPE" ]; then + echo -e "${LEVEL}$TYPE \"$RELATIVE\" $ADDARGS"; + fi; + + if [ "$TYPE" = "dir" -a "$LEVEL" != " " ]; then + nuxfs.dsl.capture.dir "$RELATIVE" "${LEVEL} " + echo "${LEVEL}enddir"; + fi; +} + +## capture - Captures current directory to nuxfs syntax +function task.capture { + if [ $# -eq 0 ]; then + nuxfs.dsl.capture.dir . + + else + for file in "$@" ; do + nuxfs.dsl.capture.file "$file" .; + done; + fi + +} + function nuxfs.template.list { echo "Available templates:"; pushd $TEMPLATE_DIR > /dev/null; diff --git a/inc/nuxfs.dsl.inc.sh b/inc/nuxfs.dsl.inc.sh index bcbd0e2..6e9357b 100644 --- a/inc/nuxfs.dsl.inc.sh +++ b/inc/nuxfs.dsl.inc.sh @@ -101,7 +101,7 @@ function nuxfs.dsl.execute { nuxfs.dsl.keywords local DEF="$1"; local DIR="$2"; - NESTED_DIR="$(realpath "$3")/"; + NESTED_DIR="$(realpath -s "$3")/"; nux.log debug "Working Directory: $DIR , Nested Directory: $NESTED_DIR" declare -a DIR_ARRAY DIR_ARRAY[0]=$DIR