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
}