Skip to content
Snippets Groups Projects
Commit f134459b authored by KHUDIYEV ALI's avatar KHUDIYEV ALI :cooking:
Browse files

tag option works, but metadata sucks

parent 274ef7bc
Branches main
No related merge requests found
......@@ -10,10 +10,7 @@ init(){
fi
printf "cd into the 001/\n"
TAG="main"
if [ $# -gt 0 ]; then
TAG=$1
fi
if [ ${#TAG} -eq 0 ]; then TAG="main" fi
printf "TAG=$TAG\n" >> .meta
};
......
#!/bin/bash
loit(){
TAG=$1
mkdir 001 2>/dev/null
if [ $? -eq 1 ]; then
printf "extension already exists; cd to 001/\n"
else
mv $(find . -d 1 -not -iname "001") 001/ 2>/dev/null
printf "extension created at 001/\n"
cd 001 && xper.sh exp
cd 001 && xper.sh lore && cd ..
printf "TAG=$TAG\n" >> .meta
fi
};
......
......@@ -3,15 +3,28 @@
. utils.sh --import
lore(){
TAGGED_PATH=$1
REAL_PATH=".."
if [ $(pwd) = $XPER_ROOT ]; then
printf "cannot expand from the root folder\n"
else
maxnum=$(get_next_max_num)
# echo $maxnum
mkdir ../$maxnum
cp -r ./ ../$maxnum/ 2>/dev/null
printf "copied_from=$(pwd)\n" > ../$maxnum/.meta
return 1
elif [ ${#TAGGED_PATH} -gt 0 ]; then
echo tagged_path=$TAGGED_PATH
path_from_tagged_path $TAGGED_PATH
# REAL_PATH="$(path_from_tagged_path $TAGGED_PATH)"
if [ $? -eq 1 ]; then
printf "tagged path doens't exist :(\n"
return 1
fi
fi
# echo "got it=$REAL_PATH"
MAXNUM=$(get_next_max_num $REAL_PATH)
mkdir $REAL_PATH/$MAXNUM
cp -r ./ $REAL_PATH/$MAXNUM 2>/dev/null
printf "copied_from=$(pwd)\n" > $REAL_PATH/$MAXNUM/.meta
return 0
};
if [ $# -eq 0 ] || [ $1 != "--import" ]; then
......
......@@ -3,6 +3,8 @@
print_tree_from(){
local dir=$1
local depth=$2
local HIGHLIGHTED_PATH=$3
# echo dir=$dir $0
local folders=($(find $dir -type d -d 1))
folders=($(echo $folders | xargs -n1 | sort | xargs))
# echo sorted folders are... $folders
......@@ -15,28 +17,29 @@ print_tree_from(){
do
local dirname=$(echo $folder | sed -E "s/.*(\/[0-9][0-9][0-9])/\1/g")
# echo dirname=$dirname
if [[ $dirname =~ "[0-9][0-9][0-9]$" ]]
then
if [[ $dirname =~ "[0-9][0-9][0-9]$" ]]; then
local spaces=0
while [ $spaces -lt $depth ]
do
printf " "
spaces=$((spaces+1))
done
printf "$dirname\n"
print_tree_from $folder $((depth+1))
if [ $folder = $HIGHLIGHTED_PATH ]; then
printf "\033[32m"
fi
printf "$dirname\033[0m\n"
print_tree_from $folder $((depth+1)) $2
fi
done
};
tree(){
if [ $# -eq 0 ]; then
echo print all tree
cd $XPER_ROOT && ./xper.sh tree .
echo "print all tree from=$CURR_DIR"
print_tree_from $XPER_ROOT 1 $CURR_DIR
else
echo print tree from $1
cd $1
print_tree_from . 1
echo print tree root=$1 from=$CURR_DIR
print_tree_from $1 1 $CURR_DIR
printf "\n"
fi
}
......
#!/bin/zsh
get_next_max_num(){
local folders=($(find .. -type d -d 1))
# echo "[find dir=$1]"
local folders=($(find $1 -type d -d 1))
local maxnum=0
# echo folders $folders
# echo "[folders=$folders]"
for folder in $folders
do
......@@ -34,3 +35,61 @@ get_next_max_num(){
done
echo "$maxnum"
};
dirpath_from_dirtag(){
REAL_PATH=$1
DIR_TAG=$2
DIR_PATH=""
# echo "[real_path=$REAL_PATH]"
DIRS=($(find $REAL_PATH -type d -d 1))
# echo "[DIRS=$DIRS]"
for folder in $DIRS; do
TAG=$(grep "TAG=" $folder/.meta 2>/dev/null | sed -E "s/TAG=(.*)/\1/g" 2>/dev/null)
# echo "[found tag=$TAG]"
if [[ $TAG = $DIR_TAG ]]; then
DIR_PATH=$folder
break
fi
done
echo $DIR_PATH
if [ ${#DIR_PATH} -eq 0 ]; then
return 1
else
return 0
fi
};
path_from_tagged_path(){
TAGGED_PATH=$1
REAL_PATH=""
dirtag=""
firsttime=1
# echo "[tag_size=${#TAGGED_PATH}]"
for i in {1..${#TAGGED_PATH}}; do
if [[ ${TAGGED_PATH[i]} = "/" ]] || [[ $i -eq ${#TAGGED_PATH} ]]; then
if [[ ${TAGGED_PATH[i]} != "/" ]]; then dirtag+=${TAGGED_PATH[i]}; fi
# echo "[working with dirtag=$dirtag]"
if [[ $dirtag != "." ]] && [[ $dirtag != ".." ]]; then
if [[ $firsttime -eq 1 ]]; then
# echo "[xper_root=$XPER_ROOT and dirtag=$dirtag]"
if [[ $(grep "TAG=" $XPER_ROOT/.meta 2>/dev/null | sed -E "s/TAG=(.*)/\1/g" 2>/dev/null) = $dirtag ]]; then
REAL_PATH=$XPER_ROOT
fi
# REAL_PATH=$(dirpath_from_dirtag $XPER_ROOT $dirtag)
# echo what we doin $REAL_PATH
else
REAL_PATH=$(dirpath_from_dirtag $REAL_PATH $dirtag)
fi
if [ $? -eq 1 ]; then echo $REAL_PATH; return 1; fi
else
REAL_PATH+="$dirtag/"
fi
dirtag=""
firsttime=0
# echo "updating [REAL_PATH=$REAL_PATH]"
continue
fi
dirtag+=${TAGGED_PATH[i]}
done
echo $REAL_PATH
};
......@@ -29,6 +29,9 @@ shift
ARGS=()
TAG=""
TAGGED_PATH=""
CURR_DIR=$(pwd)
# DIR_PATH=""
while [[ $# -gt 0 ]]; do
case $1 in
......@@ -37,6 +40,11 @@ while [[ $# -gt 0 ]]; do
shift
shift
;;
-T|--Tag)
TAGGED_PATH="$2"
shift
shift
;;
*)
ARGS+=("$1")
shift
......@@ -48,15 +56,19 @@ main(){
if [ $CMD = "init" ]; then
init $TAG
elif [ $CMD = "new" ]; then
new ${ARGS:2}
new $ARGS
elif [ $CMD = "lore" ]; then
lore ${ARGS:2}
lore $TAGGED_PATH $ARGS
elif [ $CMD = "loit" ]; then
loit ${ARGS:2}
loit $TAG $ARGS
elif [ $CMD = "tree" ]; then
tree ${ARGS:2}
tree $ARGS
elif [ $CMD = "search" ]; then
echo search
elif [ $CMD = "run" ]; then
echo run
elif [ $CMD = "set" ]; then
echo set
else
echo hi there
fi
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment