summaryrefslogtreecommitdiff
path: root/automv.sh
diff options
context:
space:
mode:
Diffstat (limited to 'automv.sh')
-rwxr-xr-xautomv.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/automv.sh b/automv.sh
index c5d496a..2c71375 100755
--- a/automv.sh
+++ b/automv.sh
@@ -1,5 +1,8 @@
#!/usr/bin/env bash
+TMPDIR=$(mktemp -d)
+CSPLIT_PREFIX=$TMPDIR/split
+
if [[ -n "$AUTOMV_DIR" ]]; then
automvdir=$AUTOMV_DIR
else
@@ -28,9 +31,25 @@ function automv {
| xargs -I '{}' mv -v {} $target/
}
+function split {
+ file=$1
+ filename=$(basename --suffix=.conf $file)
+ csplit $1 \
+ --prefix="${CSPLIT_PREFIX}-${filename}" \
+ --suffix-format='_%04d.conf' \
+ --elide-empty-files \
+ --suppress-matched \
+ --keep-files \
+ /---/ '{*}'
+}
+
echo "Executing automv functions from $automvdir"
for file in $automvdir/*.conf
do
+ split $file
+done
+for file in $TMPDIR/*.conf
+do
echo "found $file"
if [[ -f $file ]]; then
# Extract file configs
@@ -41,3 +60,7 @@ do
automv $query $sourced $target
fi
done
+echo "Automoved files"
+echo "Removing tmp dir: $TMPDIR"
+rm -r $TMPDIR
+echo "Done"