Last active
April 18, 2018 04:45
-
-
Save travisperson/f471832f1d519da53e6e8bc89a33a112 to your computer and use it in GitHub Desktop.
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
#!/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 | |
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
#!/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