Skip to content

Instantly share code, notes, and snippets.

@travisperson
Last active April 18, 2018 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travisperson/f471832f1d519da53e6e8bc89a33a112 to your computer and use it in GitHub Desktop.
Save travisperson/f471832f1d519da53e6e8bc89a33a112 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
files=$(find $HOME -maxdepth 1 -type f -not -name ".*")
function sort_into_directories {
local path="$1"
local filename=$(basename $path)
local extension="${filename##*.}"
if [ "$extension" = "$filename" ]; then
echo "Has no extension", $path
return
fi
case $extension in
md | markdown)
echo "Is markdown", $path
;;
log)
echo "Is log", $path
;;
txt)
echo "Is txt", $path
;;
esac
}
for path in $files; do
sort_into_directories $path
done
#!/usr/bin/env bash
# required: inotify-tools
function sort_into_directories {
local path="$1"
local filename=$(basename $path)
local extension="${filename##*.}"
if [ "$extension" = "$filename" ]; then
echo "Has no extension", $path
return
fi
case $extension in
md | markdown)
echo "Is markdown", $path
;;
log)
echo "Is log", $path
;;
txt)
echo "Is txt", $path
;;
esac
}
inotifywait -me CLOSE --format '%e %f' -q $HOME |
while IFS= read -r change; do
if [[ ! $change = *"ISDIR"* ]]; then
files=$(find $HOME -maxdepth 1 -type f -not -name ".*")
for path in $files; do
sort_into_directories $path
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment