summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xautomv.sh24
-rw-r--r--readme.txt16
2 files changed, 35 insertions, 5 deletions
diff --git a/automv.sh b/automv.sh
index 16d7683..fae371e 100755
--- a/automv.sh
+++ b/automv.sh
@@ -1,10 +1,15 @@
#!/usr/bin/env bash
-set -e
if [[ -n "$AUTOMV_DIR" ]]; then
automvdir=$AUTOMV_DIR
else
- automvdir=$(dirname "$0")/automv.d
+ if [[ -d "/usr/local/etc/automv.d" ]]; then
+ automvdir=/usr/local/etc/automv.d
+ else
+ echo 'Missing automv.d location: please create confs in /usr/local/etc/automv.d
+ or supply a directory in $AUTOMV_DIR'
+ exit 1
+ fi
fi
function extract {
@@ -13,12 +18,23 @@ function extract {
grep "^${prop}=.*$" $file | cut -d '=' -f2
}
+function fn_find {
+ find $1 -type f \( -regex "${2}" ! -iname ".*" \)
+}
+
function automv {
local query=$1
local source=$2
local target=$3
- echo "Moving files in $source that match '$query' to $target"
- find $source -type f \( -regex "${query}" ! -iname ".*" \) | xargs -I '{}' mv {} $target/
+
+ file_cnt=$(fn_find $source $query | wc -l)
+ if [[ $file_cnt > 0 ]]; then
+ echo "Moving $file_cnt files in $source that match '$query' to $target"
+ fn_find $source $query
+ fn_find $source $query | xargs -I '{}' mv {} $target/
+ else
+ echo "No files matching '$query' in $source"
+ fi
}
echo "Executing automv functions from $automvdir"
diff --git a/readme.txt b/readme.txt
index 05922ef..c2f5cfa 100644
--- a/readme.txt
+++ b/readme.txt
@@ -12,7 +12,7 @@ Prereqs:
Setup:
the script searches the directory:
- ./automv.d/
+ /usr/local/etc/automv.d/
for any .conf files
Overriding the automv.d location:
@@ -20,6 +20,10 @@ Overriding the automv.d location:
AUTOMV_DIR
environment variable
+How it works:
+ it basically automates the finding of non-hidden files in the source dir
+ and will move them to an existing directory
+
automv.d/ conf syntax
=====================
@@ -46,3 +50,13 @@ query=.*\.jp[e]?g
source=/home/user/Downloads/
target=/home/user/Pictures/
+Nice to haves / Tasks to be done
+================================
+
+[ ] Better logging (timestamps n such) - we repeat the find like 3 times to be
+ able to get better logs / printing
+[ ] More flexibility / configurability
+[ ] Fault tolerance
+[ ] Auto mkdir -p if the target dir doesn't exist?
+[ ] Multiple queries per file? What if you have diverging regexes? does find support ORs?
+