Skip to content

Instantly share code, notes, and snippets.

@bougui505
Last active February 20, 2023 16:56
Show Gist options
  • Select an option

  • Save bougui505/15c7320c00b8a10c2fa42fe4c403e129 to your computer and use it in GitHub Desktop.

Select an option

Save bougui505/15c7320c00b8a10c2fa42fe4c403e129 to your computer and use it in GitHub Desktop.

Revisions

  1. bougui505 revised this gist Jun 20, 2019. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,7 @@ usage ()
    echo "autogit [-i, -a filename, -s, -d filename]"
    echo " • -i: initialize the autogit repository"
    echo " • -a <filename>: add the given file under versioning"
    echo " • -A : add all the files in the current directory, excepted hidden files, under versioning"
    echo " • -s: get the status of the current repository"
    echo " • -l: get the log of the current repository"
    echo " • -d <filename>: show the diff history for the given file"
    @@ -107,6 +108,13 @@ if [ "$1" = "-a" ]; then
    exit
    fi

    if [ "$1" = "-A" ]; then
    for x in $(find . -type f -not -path '*/\.*' -printf '%P\n'); do
    add_file $x
    done
    exit
    fi

    if [ "$1" = "-x" ]; then
    SCRIPTNAME=".$2.incron"
    SCRIPTNAME=".$SCRIPTNAME:t"
  2. bougui505 revised this gist Jun 20, 2019. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -88,19 +88,22 @@ if [ "$1" = "--sync" ]; then
    echo "ssh $HOSTNAME 'cd $HOSTPATH && git pull origin master'" >> .autogit/hooks/post-commit
    fi

    if [ "$1" = "-a" ]; then
    if git --git-dir=.autogit ls-files | grep $2 ; then
    echo "File $2 already under versionning..."
    function add_file () {
    if git --git-dir=.autogit ls-files | grep $1 ; then
    echo "File $1 already under versionning..."
    else
    git --git-dir=.autogit add "$2"
    git --git-dir=.autogit commit $2 -m "Added: $2"
    git --git-dir=.autogit add "$1"
    git --git-dir=.autogit commit $1 -m "Added: $1"
    # Create the script file to be executed by incron:
    SCRIPTNAME=".$(echo $2 | tr '/' '%').incron"
    echo "cd $(pwd) && git --git-dir=.autogit commit $2 -m 'Modified: $2' ; incrontab --reload" > $SCRIPTNAME
    SCRIPTNAME=".$(echo $1 | tr '/' '%').incron"
    echo "cd $(pwd) && git --git-dir=.autogit commit $1 -m 'Modified: $1' ; incrontab --reload" > $SCRIPTNAME
    # Update the incrontab
    INCRONTABENTRY="$2:A IN_CLOSE_WRITE sh $SCRIPTNAME:A"
    INCRONTABENTRY="$1:A IN_CLOSE_WRITE sh $SCRIPTNAME:A"
    incrontab -l | cat - =(echo $INCRONTABENTRY) | incrontab -
    fi
    }
    if [ "$1" = "-a" ]; then
    add_file $2
    exit
    fi

  3. bougui505 revised this gist Jun 20, 2019. 1 changed file with 12 additions and 8 deletions.
    20 changes: 12 additions & 8 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -89,14 +89,18 @@ if [ "$1" = "--sync" ]; then
    fi

    if [ "$1" = "-a" ]; then
    git --git-dir=.autogit add "$2"
    git --git-dir=.autogit commit $2 -m "Added: $2"
    # Create the script file to be executed by incron:
    SCRIPTNAME=".$(echo $2 | tr '/' '%').incron"
    echo "cd $(pwd) && git --git-dir=.autogit commit $2 -m 'Modified: $2' ; incrontab --reload" > $SCRIPTNAME
    # Update the incrontab
    INCRONTABENTRY="$2:A IN_CLOSE_WRITE sh $SCRIPTNAME:A"
    incrontab -l | cat - =(echo $INCRONTABENTRY) | incrontab -
    if git --git-dir=.autogit ls-files | grep $2 ; then
    echo "File $2 already under versionning..."
    else
    git --git-dir=.autogit add "$2"
    git --git-dir=.autogit commit $2 -m "Added: $2"
    # Create the script file to be executed by incron:
    SCRIPTNAME=".$(echo $2 | tr '/' '%').incron"
    echo "cd $(pwd) && git --git-dir=.autogit commit $2 -m 'Modified: $2' ; incrontab --reload" > $SCRIPTNAME
    # Update the incrontab
    INCRONTABENTRY="$2:A IN_CLOSE_WRITE sh $SCRIPTNAME:A"
    incrontab -l | cat - =(echo $INCRONTABENTRY) | incrontab -
    fi
    exit
    fi

  4. bougui505 revised this gist Apr 15, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -73,6 +73,7 @@ if [ "$1" = "-i" ]; then
    chmod +x .autogit/hooks/post-commit
    # Set the GIT_DIR environment variable to .autogit
    echo "#export GIT_DIR=.autogit" >> .envrc
    direnv allow
    fi
    fi

  5. bougui505 revised this gist Apr 15, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autogit.sh
    Original file line number Diff line number Diff line change
    @@ -72,7 +72,7 @@ if [ "$1" = "-i" ]; then
    git --git-dir=.autogit push origin master" > .autogit/hooks/post-commit
    chmod +x .autogit/hooks/post-commit
    # Set the GIT_DIR environment variable to .autogit
    echo "export GIT_DIR=.autogit" >> .envrc
    echo "#export GIT_DIR=.autogit" >> .envrc
    fi
    fi

  6. bougui505 revised this gist Apr 15, 2019. 1 changed file with 11 additions and 1 deletion.
    12 changes: 11 additions & 1 deletion autogit.sh
    Original file line number Diff line number Diff line change
    @@ -91,7 +91,7 @@ if [ "$1" = "-a" ]; then
    git --git-dir=.autogit add "$2"
    git --git-dir=.autogit commit $2 -m "Added: $2"
    # Create the script file to be executed by incron:
    SCRIPTNAME=".$(echo $2 | tr '/' '_').incron"
    SCRIPTNAME=".$(echo $2 | tr '/' '%').incron"
    echo "cd $(pwd) && git --git-dir=.autogit commit $2 -m 'Modified: $2' ; incrontab --reload" > $SCRIPTNAME
    # Update the incrontab
    INCRONTABENTRY="$2:A IN_CLOSE_WRITE sh $SCRIPTNAME:A"
    @@ -166,6 +166,16 @@ fi

    if [ "$1" = "-f" ]; then
    git --git-dir=.autogit commit -a -m "Backup forced!"
    for SCRIPTNAME in .*.incron; do
    if $(incrontab -l | grep -q "$SCRIPTNAME"); then
    echo "$SCRIPTNAME already presents in incrontab"
    else
    TRACKEDFILE=$(echo "$SCRIPTNAME:t" | sed 's/.//' | sed 's/.incron//' | sed 's,%,/,g')
    INCRONTABENTRY="$TRACKEDFILE:A IN_CLOSE_WRITE sh $SCRIPTNAME:A"
    echo "Adding:\n$INCRONTABENTRY to incrontab"
    incrontab -l | cat - =(echo $INCRONTABENTRY) | incrontab -
    fi
    done
    incrontab --reload
    exit
    fi
  7. bougui505 revised this gist Apr 15, 2019. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -91,8 +91,7 @@ if [ "$1" = "-a" ]; then
    git --git-dir=.autogit add "$2"
    git --git-dir=.autogit commit $2 -m "Added: $2"
    # Create the script file to be executed by incron:
    SCRIPTNAME=".$2.incron"
    SCRIPTNAME=".$SCRIPTNAME:t"
    SCRIPTNAME=".$(echo $2 | tr '/' '_').incron"
    echo "cd $(pwd) && git --git-dir=.autogit commit $2 -m 'Modified: $2' ; incrontab --reload" > $SCRIPTNAME
    # Update the incrontab
    INCRONTABENTRY="$2:A IN_CLOSE_WRITE sh $SCRIPTNAME:A"
  8. bougui505 revised this gist Apr 9, 2019. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -71,6 +71,8 @@ if [ "$1" = "-i" ]; then
    echo "#!/bin/sh
    git --git-dir=.autogit push origin master" > .autogit/hooks/post-commit
    chmod +x .autogit/hooks/post-commit
    # Set the GIT_DIR environment variable to .autogit
    echo "export GIT_DIR=.autogit" >> .envrc
    fi
    fi

  9. bougui505 revised this gist Apr 9, 2019. 1 changed file with 25 additions and 0 deletions.
    25 changes: 25 additions & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -25,6 +25,7 @@ usage ()
    echo " • -x <filename>: remove the given filename from versionning"
    echo " • -X: clean the current repository from any versionning"
    echo " • --prompt: get the system status as a prompt status"
    echo " • --sync hostname:/path/to/dir/: synchronize the given host"
    exit
    }

    @@ -49,6 +50,11 @@ if [ "$1" = "-i" ]; then
    echo "AUTOGIT repository"
    exit
    else
    # create bare repository for distant access
    mkdir .bare
    cd .bare
    git --bare init
    cd -
    if [ -d ".git" ]; then # Already a git repo. Preserve the .git file
    TMPDIR=$(mktemp -d)
    mv .git $TMPDIR/.
    @@ -59,9 +65,26 @@ if [ "$1" = "-i" ]; then
    git init
    mv .git .autogit
    fi
    CWD=$(pwd)
    git --git-dir=.autogit remote add origin $CWD/.bare
    # Create post-commit hook
    echo "#!/bin/sh
    git --git-dir=.autogit push origin master" > .autogit/hooks/post-commit
    chmod +x .autogit/hooks/post-commit
    fi
    fi

    if [ "$1" = "--sync" ]; then
    ADDR=$2
    A=("${(@s/:/)ADDR}")
    HOSTNAME=$A[1]
    HOSTPATH=$A[2]
    CWD=$(pwd)
    MYHOSTNAME=$(hostname)
    ssh $HOSTNAME "mkdir -p $HOSTPATH && cd $HOSTPATH && git init && git remote add origin $MYHOSTNAME:$CWD/.bare && git pull origin master"
    echo "ssh $HOSTNAME 'cd $HOSTPATH && git pull origin master'" >> .autogit/hooks/post-commit
    fi

    if [ "$1" = "-a" ]; then
    git --git-dir=.autogit add "$2"
    git --git-dir=.autogit commit $2 -m "Added: $2"
    @@ -98,6 +121,8 @@ if [ "$1" = "-X" ]; then
    rm -v .*.incron
    print "Remove Git files..."
    rm -rf .autogit
    print "Remove bare repo..."
    rm -rf .bare
    print "Reloading incrontab"
    incrontab --reload
    exit
  10. bougui505 revised this gist Jan 22, 2019. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -67,6 +67,7 @@ if [ "$1" = "-a" ]; then
    git --git-dir=.autogit commit $2 -m "Added: $2"
    # Create the script file to be executed by incron:
    SCRIPTNAME=".$2.incron"
    SCRIPTNAME=".$SCRIPTNAME:t"
    echo "cd $(pwd) && git --git-dir=.autogit commit $2 -m 'Modified: $2' ; incrontab --reload" > $SCRIPTNAME
    # Update the incrontab
    INCRONTABENTRY="$2:A IN_CLOSE_WRITE sh $SCRIPTNAME:A"
    @@ -75,10 +76,12 @@ if [ "$1" = "-a" ]; then
    fi

    if [ "$1" = "-x" ]; then
    SCRIPTNAME=".$2.incron"
    SCRIPTNAME=".$SCRIPTNAME:t"
    print "Remove incrontab entry for $2"
    incrontab -l | grep -v .$2.incron | incrontab -
    incrontab -l | grep -v $SCRIPTNAME | incrontab -
    print "Remove Incron script for $2"
    rm -v .$2.incron
    rm -v $SCRIPTNAME
    print "Remove $2 from the git index"
    git --git-dir=.autogit rm --cached $2
    print "Commit changes..."
  11. bougui505 revised this gist Sep 21, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,7 @@ usage ()
    echo " • -s: get the status of the current repository"
    echo " • -l: get the log of the current repository"
    echo " • -d <filename>: show the diff history for the given file"
    echo " • -d --word-diff: show the diff history with a word based diff"
    echo " • --diff <commit hash or tag name> <filename>: show the differences between the current version of the file and the given commit hash"
    echo " • --ls: list all the file under versioning"
    echo " • -f: force to backup all files under versioning"
  12. bougui505 revised this gist Aug 29, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ usage ()
    echo " • --ls: list all the file under versioning"
    echo " • -f: force to backup all files under versioning"
    echo " • -v <commit hash or tag name> <filename>: show the version given by the <commit hash> for the given file"
    echo " • -t tagname message: create a tag with the given tagname and message"
    echo " • -t message: create a tag with as tagname the date in format +%Y%m%d_%H%M (e.g.: 20180829_1643) and the given message"
    echo " • --lt list tags"
    echo " • -r <filename>: restore (git-checkout) deleted file"
    echo " • -x <filename>: remove the given filename from versionning"
    @@ -141,7 +141,7 @@ if [ "$1" = "-f" ]; then
    fi

    if [ "$1" = "-t" ]; then
    git --git-dir=.autogit tag -a $2 -m $3
    git --git-dir=.autogit tag -a $(date +%Y%m%d_%H%M) -m $2
    git tag
    exit
    fi
  13. bougui505 revised this gist Jul 19, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autogit.sh
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ usage ()
    echo " • --diff <commit hash or tag name> <filename>: show the differences between the current version of the file and the given commit hash"
    echo " • --ls: list all the file under versioning"
    echo " • -f: force to backup all files under versioning"
    echo " • -v <commit hash> <filename>: show the version given by the <commit hash> for the given file"
    echo " • -v <commit hash or tag name> <filename>: show the version given by the <commit hash> for the given file"
    echo " • -t tagname message: create a tag with the given tagname and message"
    echo " • --lt list tags"
    echo " • -r <filename>: restore (git-checkout) deleted file"
  14. bougui505 revised this gist Jul 19, 2018. 1 changed file with 14 additions and 1 deletion.
    15 changes: 14 additions & 1 deletion autogit.sh
    Original file line number Diff line number Diff line change
    @@ -14,10 +14,12 @@ usage ()
    echo " • -s: get the status of the current repository"
    echo " • -l: get the log of the current repository"
    echo " • -d <filename>: show the diff history for the given file"
    echo " • --diff <commit hash> <filename>: show the differences between the current version of the file and the given commit hash"
    echo " • --diff <commit hash or tag name> <filename>: show the differences between the current version of the file and the given commit hash"
    echo " • --ls: list all the file under versioning"
    echo " • -f: force to backup all files under versioning"
    echo " • -v <commit hash> <filename>: show the version given by the <commit hash> for the given file"
    echo " • -t tagname message: create a tag with the given tagname and message"
    echo " • --lt list tags"
    echo " • -r <filename>: restore (git-checkout) deleted file"
    echo " • -x <filename>: remove the given filename from versionning"
    echo " • -X: clean the current repository from any versionning"
    @@ -137,3 +139,14 @@ if [ "$1" = "-f" ]; then
    incrontab --reload
    exit
    fi

    if [ "$1" = "-t" ]; then
    git --git-dir=.autogit tag -a $2 -m $3
    git tag
    exit
    fi

    if [ "$1" = "--lt" ]; then
    git --git-dir=.autogit tag -n
    exit
    fi
  15. bougui505 revised this gist Dec 4, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autogit.sh
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ usage ()
    function autogit_prompt () {
    if [ -d ".autogit" ]; then
    git --git-dir=.autogit status -s |
    awk 'BEGIN{var=1};{if ($1=="M"){var=0}};END{if (var){printf "\033[1;32m•\033[0m "}else{printf "\033[1;31m•\033[0m "}}'
    awk 'BEGIN{var=1};{if ($1=="M" || $1=="D"){var=0}};END{if (var){printf "\033[1;32m•\033[0m "}else{printf "\033[1;31m•\033[0m "}}'
    fi
    }

  16. bougui505 revised this gist Dec 4, 2017. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,7 @@ usage ()
    echo " • --ls: list all the file under versioning"
    echo " • -f: force to backup all files under versioning"
    echo " • -v <commit hash> <filename>: show the version given by the <commit hash> for the given file"
    echo " • -r <filename>: restore (git-checkout) deleted file"
    echo " • -x <filename>: remove the given filename from versionning"
    echo " • -X: clean the current repository from any versionning"
    echo " • --prompt: get the system status as a prompt status"
    @@ -126,6 +127,11 @@ if [ "$1" = "-v" ]; then
    exit
    fi

    if [ "$1" = "-r" ]; then
    git --git-dir=.autogit checkout $2
    exit
    fi

    if [ "$1" = "-f" ]; then
    git --git-dir=.autogit commit -a -m "Backup forced!"
    incrontab --reload
  17. bougui505 revised this gist Dec 4, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autogit.sh
    Original file line number Diff line number Diff line change
    @@ -97,7 +97,7 @@ if [ "$1" = "-X" ]; then
    fi

    if [ "$1" = "-s" ]; then
    git --git-dir=.autogit status
    git --git-dir=.autogit status -uno
    exit
    fi

  18. bougui505 revised this gist Aug 30, 2017. 1 changed file with 22 additions and 4 deletions.
    26 changes: 22 additions & 4 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -10,14 +10,15 @@ usage ()
    echo "Usage"
    echo "autogit [-i, -a filename, -s, -d filename]"
    echo " • -i: initialize the autogit repository"
    echo " • -a filename: add the given file under versioning"
    echo " • -a <filename>: add the given file under versioning"
    echo " • -s: get the status of the current repository"
    echo " • -l: get the log of the current repository"
    echo " • -d filename: show the diff history for the given file"
    echo " • -d <filename>: show the diff history for the given file"
    echo " • --diff <commit hash> <filename>: show the differences between the current version of the file and the given commit hash"
    echo " • --ls: list all the file under versioning"
    echo " • -f: force to backup all files under versioning"
    echo " • -v <commit hash> <filename>: show the version given by the <commit hash> for the given file"
    echo " • -x <filename>: remove the given filename from versionning"
    echo " • -X: clean the current repository from any versionning"
    echo " • --prompt: get the system status as a prompt status"
    exit
    @@ -69,13 +70,30 @@ if [ "$1" = "-a" ]; then
    exit
    fi

    if [ "$1" = "-x" ]; then
    print "Remove incrontab entry for $2"
    incrontab -l | grep -v .$2.incron | incrontab -
    print "Remove Incron script for $2"
    rm -v .$2.incron
    print "Remove $2 from the git index"
    git --git-dir=.autogit rm --cached $2
    print "Commit changes..."
    git --git-dir=.autogit commit -a -m "$2 removed from the git index"
    print "Reloading incrontab"
    incrontab --reload
    exit
    fi

    if [ "$1" = "-X" ]; then
    print "Remove incrontab entry ..."
    print "Remove incrontab entries ..."
    incrontab -l | grep -v -f =(ls .*.incron) | incrontab -
    print "Remove Incron scripts..."
    rm .*.incron
    rm -v .*.incron
    print "Remove Git files..."
    rm -rf .autogit
    print "Reloading incrontab"
    incrontab --reload
    exit
    fi

    if [ "$1" = "-s" ]; then
  19. bougui505 revised this gist Aug 30, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -110,5 +110,6 @@ fi

    if [ "$1" = "-f" ]; then
    git --git-dir=.autogit commit -a -m "Backup forced!"
    incrontab --reload
    exit
    fi
  20. bougui505 revised this gist Aug 30, 2017. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,7 @@ usage ()
    echo " • -s: get the status of the current repository"
    echo " • -l: get the log of the current repository"
    echo " • -d filename: show the diff history for the given file"
    echo " • --diff <commit hash> <filename>: show the differences between the current version of the file and the given commit hash"
    echo " • --ls: list all the file under versioning"
    echo " • -f: force to backup all files under versioning"
    echo " • -v <commit hash> <filename>: show the version given by the <commit hash> for the given file"
    @@ -92,6 +93,11 @@ if [ "$1" = "-d" ]; then
    exit
    fi

    if [ "$1" = "--diff" ]; then
    git --git-dir=.autogit diff $2 $3
    exit
    fi

    if [ "$1" = "--ls" ]; then
    git --git-dir=.autogit ls-files
    exit
  21. bougui505 revised this gist Aug 28, 2017. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -18,13 +18,26 @@ usage ()
    echo " • -f: force to backup all files under versioning"
    echo " • -v <commit hash> <filename>: show the version given by the <commit hash> for the given file"
    echo " • -X: clean the current repository from any versionning"
    echo " • --prompt: get the system status as a prompt status"
    exit
    }

    function autogit_prompt () {
    if [ -d ".autogit" ]; then
    git --git-dir=.autogit status -s |
    awk 'BEGIN{var=1};{if ($1=="M"){var=0}};END{if (var){printf "\033[1;32m•\033[0m "}else{printf "\033[1;31m•\033[0m "}}'
    fi
    }

    if [ $# -lt 1 ]; then
    usage
    fi

    if [ "$1" = "--prompt" ]; then
    autogit_prompt
    exit
    fi

    if [ "$1" = "-i" ]; then
    if [ -d ".autogit" ]; then
    echo "AUTOGIT repository"
  22. bougui505 revised this gist Aug 28, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autogit.sh
    Original file line number Diff line number Diff line change
    @@ -48,7 +48,7 @@ if [ "$1" = "-a" ]; then
    git --git-dir=.autogit commit $2 -m "Added: $2"
    # Create the script file to be executed by incron:
    SCRIPTNAME=".$2.incron"
    echo "cd $(pwd) && git --git-dir=.autogit commit $2 -m 'Modified: $2'" > $SCRIPTNAME
    echo "cd $(pwd) && git --git-dir=.autogit commit $2 -m 'Modified: $2' ; incrontab --reload" > $SCRIPTNAME
    # Update the incrontab
    INCRONTABENTRY="$2:A IN_CLOSE_WRITE sh $SCRIPTNAME:A"
    incrontab -l | cat - =(echo $INCRONTABENTRY) | incrontab -
  23. bougui505 revised this gist Aug 28, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autogit.sh
    Original file line number Diff line number Diff line change
    @@ -50,7 +50,7 @@ if [ "$1" = "-a" ]; then
    SCRIPTNAME=".$2.incron"
    echo "cd $(pwd) && git --git-dir=.autogit commit $2 -m 'Modified: $2'" > $SCRIPTNAME
    # Update the incrontab
    INCRONTABENTRY="$2:A IN_MODIFY sh $SCRIPTNAME:A"
    INCRONTABENTRY="$2:A IN_CLOSE_WRITE sh $SCRIPTNAME:A"
    incrontab -l | cat - =(echo $INCRONTABENTRY) | incrontab -
    exit
    fi
  24. bougui505 revised this gist Aug 28, 2017. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,7 @@ usage ()
    echo " • -l: get the log of the current repository"
    echo " • -d filename: show the diff history for the given file"
    echo " • --ls: list all the file under versioning"
    echo " • -f: force to backup all files under versioning"
    echo " • -v <commit hash> <filename>: show the version given by the <commit hash> for the given file"
    echo " • -X: clean the current repository from any versionning"
    exit
    @@ -87,3 +88,8 @@ if [ "$1" = "-v" ]; then
    git --git-dir=.autogit show $2:$3
    exit
    fi

    if [ "$1" = "-f" ]; then
    git --git-dir=.autogit commit -a -m "Backup forced!"
    exit
    fi
  25. bougui505 revised this gist Aug 28, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autogit.sh
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    usage ()
    {
    echo "Usage"
    echo "$0 [-i, -a filename, -s, -d filename]"
    echo "autogit [-i, -a filename, -s, -d filename]"
    echo " • -i: initialize the autogit repository"
    echo " • -a filename: add the given file under versioning"
    echo " • -s: get the status of the current repository"
  26. bougui505 revised this gist Aug 25, 2017. 1 changed file with 20 additions and 2 deletions.
    22 changes: 20 additions & 2 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,7 @@ usage ()
    echo " • -d filename: show the diff history for the given file"
    echo " • --ls: list all the file under versioning"
    echo " • -v <commit hash> <filename>: show the version given by the <commit hash> for the given file"
    echo " • -X: clean the current repository from any versionning"
    exit
    }

    @@ -28,8 +29,16 @@ if [ "$1" = "-i" ]; then
    echo "AUTOGIT repository"
    exit
    else
    git init
    mv .git .autogit
    if [ -d ".git" ]; then # Already a git repo. Preserve the .git file
    TMPDIR=$(mktemp -d)
    mv .git $TMPDIR/.
    git init
    mv .git .autogit
    mv $TMPDIR/.git .
    else
    git init
    mv .git .autogit
    fi
    fi
    fi

    @@ -45,6 +54,15 @@ if [ "$1" = "-a" ]; then
    exit
    fi

    if [ "$1" = "-X" ]; then
    print "Remove incrontab entry ..."
    incrontab -l | grep -v -f =(ls .*.incron) | incrontab -
    print "Remove Incron scripts..."
    rm .*.incron
    print "Remove Git files..."
    rm -rf .autogit
    fi

    if [ "$1" = "-s" ]; then
    git --git-dir=.autogit status
    exit
  27. bougui505 revised this gist Aug 25, 2017. 1 changed file with 0 additions and 0 deletions.
    Empty file modified autogit.sh
    100644 → 100755
    Empty file.
  28. bougui505 created this gist Aug 25, 2017.
    71 changes: 71 additions & 0 deletions autogit.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    #!/usr/bin/env zsh
    # -*- coding: UTF8 -*-

    # Author: Guillaume Bouvier -- [email protected]
    # https://research.pasteur.fr/en/member/guillaume-bouvier/
    # 2017-08-25 14:59:30 (UTC+0200)

    usage ()
    {
    echo "Usage"
    echo "$0 [-i, -a filename, -s, -d filename]"
    echo " • -i: initialize the autogit repository"
    echo " • -a filename: add the given file under versioning"
    echo " • -s: get the status of the current repository"
    echo " • -l: get the log of the current repository"
    echo " • -d filename: show the diff history for the given file"
    echo " • --ls: list all the file under versioning"
    echo " • -v <commit hash> <filename>: show the version given by the <commit hash> for the given file"
    exit
    }

    if [ $# -lt 1 ]; then
    usage
    fi

    if [ "$1" = "-i" ]; then
    if [ -d ".autogit" ]; then
    echo "AUTOGIT repository"
    exit
    else
    git init
    mv .git .autogit
    fi
    fi

    if [ "$1" = "-a" ]; then
    git --git-dir=.autogit add "$2"
    git --git-dir=.autogit commit $2 -m "Added: $2"
    # Create the script file to be executed by incron:
    SCRIPTNAME=".$2.incron"
    echo "cd $(pwd) && git --git-dir=.autogit commit $2 -m 'Modified: $2'" > $SCRIPTNAME
    # Update the incrontab
    INCRONTABENTRY="$2:A IN_MODIFY sh $SCRIPTNAME:A"
    incrontab -l | cat - =(echo $INCRONTABENTRY) | incrontab -
    exit
    fi

    if [ "$1" = "-s" ]; then
    git --git-dir=.autogit status
    exit
    fi

    if [ "$1" = "-l" ]; then
    git --git-dir=.autogit log --reverse
    exit
    fi

    if [ "$1" = "-d" ]; then
    git --git-dir=.autogit log --reverse -p $2
    exit
    fi

    if [ "$1" = "--ls" ]; then
    git --git-dir=.autogit ls-files
    exit
    fi

    if [ "$1" = "-v" ]; then
    git --git-dir=.autogit show $2:$3
    exit
    fi