summaryrefslogtreecommitdiff
path: root/scripts/.local/bin
diff options
context:
space:
mode:
authorIvan K. Boikov <mail@ikboikov.net>2025-01-25 15:51:56 +0100
committerIvan K. Boikov <mail@ikboikov.net>2025-01-25 19:35:11 +0100
commit3525ade66ff9e4cd6dd325d0dd099695d33eb2c0 (patch)
tree4356c7df03c740fe197681f6db0cf40d4e427176 /scripts/.local/bin
parent5c298b6a3e59820b98b6de22240696c6aca2d20d (diff)
New flattening script
Diffstat (limited to 'scripts/.local/bin')
-rwxr-xr-xscripts/.local/bin/flatdir-do2
-rwxr-xr-xscripts/.local/bin/flatdir-try2
-rwxr-xr-xscripts/.local/bin/flatten38
3 files changed, 38 insertions, 4 deletions
diff --git a/scripts/.local/bin/flatdir-do b/scripts/.local/bin/flatdir-do
deleted file mode 100755
index 23bfbf0..0000000
--- a/scripts/.local/bin/flatdir-do
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-find */ -type f -exec bash -c 'file=${1#./}; mv "$file" "${file//\//_}"' _ '{}' \;
diff --git a/scripts/.local/bin/flatdir-try b/scripts/.local/bin/flatdir-try
deleted file mode 100755
index 06cdbd7..0000000
--- a/scripts/.local/bin/flatdir-try
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/sh
-find */ -type f -exec bash -c 'file=${1#./}; echo mv "$file" "${file//\//_}"' _ '{}' \;
diff --git a/scripts/.local/bin/flatten b/scripts/.local/bin/flatten
new file mode 100755
index 0000000..a4b833f
--- /dev/null
+++ b/scripts/.local/bin/flatten
@@ -0,0 +1,38 @@
+#!/bin/sh
+
+# flatten the directory tree
+# example: dir1/dir2/file1 -> dir1_dir2_file1
+
+DIR="${1:-.}"
+
+_flatten(){
+ cmd="$1"
+ find "$DIR" -mindepth 2 -type f -exec bash -c 'file=${1#./}; '"$cmd"' "$file" "${file//\//_}"' _ '{}' \;
+}
+
+toflat=$(_flatten "echo mv")
+if [ -z "$toflat" ]; then
+ echo "Abort: nothing to do"; exit
+fi
+
+echo "Flattening will do:"
+echo "$toflat"
+printf "Proceed? [y/N] "
+read -r yn
+case $yn in
+ [Yy]* ) ;;
+ * ) echo "Abort" ; exit;;
+esac
+_flatten "mv"
+
+
+todel="$(find . -type d -empty -print)"
+[ -z "$todel" ] && exit
+echo "Empty subdirectories:"
+echo "$todel"
+printf "Remove subdirectories? [y/N]"
+read -r yn
+case $yn in
+ [Yy]* ) find . -type d -empty -delete;;
+ * ) echo "Abort" ; exit;;
+esac