Fix export + auto git commit - dossier - console collection manager
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 808c788972b30f8ff7a23fc7f329086b727e26fe
 (DIR) parent d1471e2efbeb610d78c126894210e2afd1351e30
 (HTM) Author: Solene Rapenne <solene@perso.pw>
       Date:   Sun, 15 Jul 2018 01:32:01 +0200
       
       Fix export + auto git commit
       
       Diffstat:
         M cdb                                 |      33 +++++++++++++++----------------
       
       1 file changed, 16 insertions(+), 17 deletions(-)
       ---
 (DIR) diff --git a/cdb b/cdb
       @@ -2,6 +2,11 @@
        
        : ${REPO:=/home/solene/dev/cbd/games/}
        mkdir -p "${REPO}" || exit 1
       +if [ ! -d "${REPO}/.git" ]
       +then
       +        cd "$REPO"
       +        git init
       +fi
        
        # displays the values of an identifier
        # $1 identifier
       @@ -33,32 +38,24 @@ show() {
        # we assume it'll works with the dataset
        export_csv() {
            cd "${REPO}"
       -    IDS=$(find . -type f | cut -d '/' -f 3 | sort | uniq | paste -s -d '\x0' -)
       -    ATTRS=$(find . -type f | cut -d '/' -f 2 | sort | uniq | paste -s -d '\x0' -)
       -
       -    OLDIFS=$IFS
       -    IFS=''\x0
        
            # display header
            printf '"identifier",'
       -    for attr in $ATTRS
       +    find . -name '.git' -prune -o -type f -print | cut -d '/' -f 2 | sort | uniq | while read attr
            do
                printf '"%s",' $attr
            done
            printf '\n'
        
            # print database
       -    for id in $IDS
       +    find . -name '.git' -prune -o -type f -print | cut -d '/' -f 3 | sort | uniq | while read id
            do
                printf '"%s",' "$id"
       -        for attr in $ATTRS
       +        find . -name '.git' -prune -o -type f -print | cut -d '/' -f 2 | sort | uniq | while read attr
                do
       -            if [ -f "${attr}/${id}" ]
       -            then
       -                printf '"%s",' "$(cat "${attr}/${id}")"
       -            else
       -                printf '"",'
       -            fi
       +            # for faster processing, we do not check existence of file before
       +            awk '{ printf "\"%s\",",$0}' "${attr}/${id}" 2>/dev/null  \
       +                || printf '"",'
                done
                printf '\n'
            done
       @@ -75,7 +72,7 @@ delete() {
            do
                if [ -f "${attribute}/${1}" ]
                then
       -            rm "${attribute}/${1}"
       +            git commit -m "Delete ${ATTRIBUTE} ${ID}" "${ATTRIBUTE}/${ID}"
                    rmdir "${attribute}" 2> /dev/null
                    SEEN=1
                fi
       @@ -94,7 +91,7 @@ delete() {
        # displays list of identifiers
        show_list() {
            cd "${REPO}"
       -    find . -type f | cut -d '/' -f 3 | sort | uniq -c | \
       +    find . -name '.git' -prune -o -type f -print | cut -d '/' -f 3 | sort | uniq -c | \
                awk '{ for(i=2;i<=NF;i=i+1) { printf "%s ", $i }
                       printf "(%i)\n", $1
                }'
       @@ -104,7 +101,7 @@ show_list() {
        # displays attributes used
        show_attributes() {
            cd "${REPO}"
       -    find . -type f | cut -d '/' -f 2 | sort | uniq -c | \
       +    find . -name '.git' -prune -o -type f -print | cut -d '/' -f 2 | sort | uniq -c | \
                awk '{ for(i=2;i<=NF;i=i+1) { printf "%s ", $i }
                           printf "(%i)\n", $1
                }'
       @@ -127,6 +124,8 @@ add_value() {
                
                mkdir -p "$ATTRIBUTE"
                printf '%s' "$VALUE" > "${ATTRIBUTE}/${ID}"
       +        git add "${ATTRIBUTE}/${ID}"
       +        git commit -m "Modify %{ATTRIBUTE} on ${ID}" "${ATTRIBUTE}/${ID}"
            done
            exit 0
        }