1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-11 13:24:28 +01:00

nuxfs: Added cathegorize keyword.

Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
Tony Tkáčik 2017-06-14 12:38:41 +02:00
parent c412900a21
commit 429a0d3258
6 changed files with 126 additions and 2 deletions

View file

@ -11,3 +11,8 @@ link.check.recover() {
git.check.recover() {
$GIT_BIN clone "$origin" "$abs_path"
}
cathegorize.process.dir() {
mkdir -p "$cat_dir"
nux.dsl.info "$cat_dir" Created directory
}

View file

@ -36,3 +36,25 @@ git.entered() {
return;
fi
}
cathegorize.cathegories() {
nux.dsl.error Proposed cathegories: $NC_White$cathegories$NC_No
for cat in $cathegories; do
cat_dir=$parent_dir/$cat;
if [ ! -d "$cat_dir" ]; then
nux.dsl.error $cat_dir Does not exits. Required by $NC_White$@$NC_No
fi
done
}
cathegorize.files() {
(cd "$parent_dir"; find -maxdepth 1 -iname "$match") \
| while read file
do
file=$(basename "$file")
cathegory=$(echo $file | cathegorize.cathegory)
if [[ $cathegories =~ "$cathegory" ]];then
nux.dsl.error "$parent_dir/$file" Should be in $cathegory
fi
done
}

View file

@ -66,6 +66,61 @@
##
.keyword should-not-exists
.keyword cathegorize match min delimiter
cathegorize.check() {
test $(find "$(dirname "$abs_path")" -maxdepth 1 -iname "$match" | wc -l) -gt 0
}
cathegorize.cathegory() {
sed -r -e "s/$delimiter/:/g" | cut -d: -f1
}
cathegorize.entered() {
local parent_dir=$(dirname "$rel_path");
local cathegories=$((cd "$parent_dir"; find -maxdepth 1 -iname "$match") \
| cut -d"/" -f2 \
| cathegorize.cathegory | sort | uniq -c \
| while IFS=" " read count cathegory
do
if [ $count -ge $min ]; then
echo $theme $cathegory
fi
done
)
for cat in $cathegories; do
cat_dir=$parent_dir/$cat;
if [ ! -d "$cat_dir" ]; then
cathegorize.process.dir "$@"
fi
done
(cd "$parent_dir"; find -maxdepth 1 -iname "$match") \
| while read file
do
file=$(basename "$file")
cathegory=$(echo $file | cathegorize.cathegory)
if [[ $cathegories =~ "$cathegory" ]];then
rel_file=$parent_dir/$file
cat_dir=$parent_dir/$cathegory
cathegorize.process.file "$@"
fi
done
}
cathegorize.process.dir() {
nux.dsl.error "$cat_dir" Does not exits. Required by cathegorize
}
cathegorize.process.file() {
nux.dsl.error "$rel_file" Should be in $NC_White$cat_dir$NC_No
}
cathegorize.check.failed() {
nux.log debug Noop, no files to cathegorize
}
directory() {
dir
}

13
inc/dsl/nuxfs.fix.dsl Normal file
View file

@ -0,0 +1,13 @@
.use-dsl nuxfs.apply
should-not-exists.check.failed() {
for f in "$rel_path"; do
rm -r "$f"
nux.dsl.info $f Deleted.
done
}
cathegorize.process.file() {
mv "$rel_file" "$cat_dir"
nux.dsl.info "$rel_file" Moved to $NC_White$cat_dir$NC_No
}

View file

@ -47,6 +47,7 @@ readonly NC_LightPurple='\033[1;35m'
readonly NC_LightCyan='\033[1;36m'
readonly NC_White=$nc_white
readonly NC_error=$NC_Red
## #Public functions:
##
## ##Logging
@ -103,11 +104,11 @@ function nux.log.level {
}
function nux.echo.error {
echo -e "${NC_error}$* ${NC_No}";
echo "${NC_error}$* ${NC_No}";
}
function nux.echo.warning {
echo -e "${NC_warning}$* ${NC_No}";
echo -e "${NC_warning}"$@" ${NC_No}";
}
## nux.use <library>
@ -117,6 +118,23 @@ function nux.use {
source "$NUX_INC_DIR/$incfile"
}
function nux.fatal {
echo "$@";
exit -1;
}
## nux.require <binary> [<common-package>]
function nux.require {
local binary=$1;
local package=${2:-$1}
if nux.check.exec "$binary" ; then
:
else
nux.fatal $1 is not present. Please check if $package is installed.
fi
}
function nux.include {
local incfile="$1.inc.sh"
source "$NUX_INC_DIR/$incfile"
@ -129,6 +147,11 @@ function nux.check.function {
return 1
}
function nux.check.exec {
local binary=$1;
test -n "$(which "$binary")"
}
## nux.check.file.exists <name>
##
function nux.check.file.exists {
@ -172,3 +195,7 @@ function nux.help.shelldoc {
-e "s/\*([^*]*)\*/${NC_White}\1${NC_No}/gI" \
}
NUX_ENV_MACHINE=/usr/
NUX_ENV_MACHINE_LOCAL=/usr/local/
NUX_ENV_USER_LOCAL=$HOME/.local

View file

@ -1,3 +1,5 @@
## nux.dsl - NUX Script DSL Support Library
function nux.dsl.block.type {
echo ${DSL_BLOCK_TYPE[${#DSL_BLOCK_TYPE[@]}-1]}
}