diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rwxr-xr-x | automv.sh | 23 | ||||
-rwxr-xr-x | test.sh | 36 | ||||
-rw-r--r-- | test/confs/double.conf | 8 | ||||
-rw-r--r-- | test/confs/empty.conf | 0 | ||||
-rw-r--r-- | test/confs/single.conf | 3 | ||||
-rw-r--r-- | test/confs/triple.conf | 11 |
7 files changed, 83 insertions, 0 deletions
@@ -1 +1,3 @@ automv.d +test/src +test/dest @@ -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" @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -e +function prep { + mkdir -p test/src + + touch ./test/src/a.txt + touch ./test/src/b.txt + touch ./test/src/c.txt + touch ./test/src/d.txt + touch ./test/src/e.txt + touch ./test/src/f.txt + + export TARGET_CNT=$(ls -1 ./test/src/ | wc -l) + + mkdir -p ./test/dest + rm -f ./test/dest/*.txt +} + +function verify { + CNT=$(ls -1 ./test/dest/ | wc -l) + if [[ ${CNT} -ne ${TARGET_CNT} ]]; then + echo "Test failed: expected ${TARGET_CNT} actual: ${CNT}" + exit 1 + fi +} + +function run { + export AUTOMV_DIR=$PWD/test/confs + ./automv.sh +} + +prep +run +verify + +echo "Tests succeeded" diff --git a/test/confs/double.conf b/test/confs/double.conf new file mode 100644 index 0000000..df1551c --- /dev/null +++ b/test/confs/double.conf @@ -0,0 +1,8 @@ +query=.*/b.txt +source=./test/src/ +target=./test/dest/ +--- +query=.*/c.txt +source=./test/src/ +target=./test/dest/ + diff --git a/test/confs/empty.conf b/test/confs/empty.conf new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test/confs/empty.conf diff --git a/test/confs/single.conf b/test/confs/single.conf new file mode 100644 index 0000000..33a98d7 --- /dev/null +++ b/test/confs/single.conf @@ -0,0 +1,3 @@ +query=.*/a.txt +source=./test/src/ +target=./test/dest/ diff --git a/test/confs/triple.conf b/test/confs/triple.conf new file mode 100644 index 0000000..4d5c384 --- /dev/null +++ b/test/confs/triple.conf @@ -0,0 +1,11 @@ +query=.*/d.txt +source=./test/src/ +target=./test/dest/ +--- +query=.*/e.txt +source=./test/src/ +target=./test/dest/ +--- +query=.*/f.txt +source=./test/src/ +target=./test/dest/ |