Last active
June 22, 2024 22:50
-
-
Save farynaio/cb1f83ff74f3dbc2a203954ed5872c8b to your computer and use it in GitHub Desktop.
Scan folder for changes in files by checking mod timestamp. If change is detacted, the changed files is touched. It's handy for sync systems which doesn't notify on file changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Scan folder for changes in files by checking mod timestamp. If change is detacted, the changed files is touched | |
if [ -z $1 ]; then | |
echo "folder has to be provided" | |
exit | |
fi | |
FOLDER=$1 | |
declare -A RECENT | |
declare -A CURRENT | |
get_files () { | |
local files | |
local -n result=$1 | |
readarray -d '' files < <(find "${FOLDER}" -type f -not -path "*/node_modules/*" -not -path "*/.nvm/*" -not -path "*/.expo/*" -not -path "*/.git/*" -not -path "*/.gradle/*" -not -path "*/.idea/*" -print0) | |
for key in "${files[@]}" | |
do | |
result["${key}"]=`date +%s -r ${key}` | |
done | |
} | |
get_files RECENT | |
while true; do | |
sleep 1 | |
get_files CURRENT | |
for key in "${!CURRENT[@]}"; do | |
if [ -z ${RECENT["${key}"]} ] || [[ ${RECENT["${key}"]} < ${CURRENT["${key}"]} ]]; then | |
echo "touch ${key}" | |
touch "${key}" | |
RECENT["${key}"]=`date +%s -r ${key}` | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment