From f134459bab3a38d387cef440d085f274655d0924 Mon Sep 17 00:00:00 2001 From: KHUDIYEV ALI <ali.khudiyev@etu.unistra.fr> Date: Mon, 31 Mar 2025 23:15:24 +0200 Subject: [PATCH] tag option works, but metadata sucks --- init.sh | 5 +---- loit.sh | 4 +++- lore.sh | 25 ++++++++++++++++------ tree.sh | 21 +++++++++++-------- utils.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- xper.sh | 20 ++++++++++++++---- 6 files changed, 112 insertions(+), 26 deletions(-) diff --git a/init.sh b/init.sh index f7726bb..c953562 100755 --- a/init.sh +++ b/init.sh @@ -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 }; diff --git a/loit.sh b/loit.sh index 4ea6ec3..7e9286a 100755 --- a/loit.sh +++ b/loit.sh @@ -1,13 +1,15 @@ #!/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 }; diff --git a/lore.sh b/lore.sh index 46c724a..b5c15ac 100755 --- a/lore.sh +++ b/lore.sh @@ -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 diff --git a/tree.sh b/tree.sh index 42a0db2..9aae440 100755 --- a/tree.sh +++ b/tree.sh @@ -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 } diff --git a/utils.sh b/utils.sh index 9b6b61b..ab2e1ff 100755 --- a/utils.sh +++ b/utils.sh @@ -1,9 +1,10 @@ #!/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 +}; diff --git a/xper.sh b/xper.sh index d42dc01..ff6a518 100755 --- a/xper.sh +++ b/xper.sh @@ -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 -- GitLab