flatten script

This commit is contained in:
2025-02-20 15:10:28 +01:00
parent fc41e56407
commit 5b16582597
2 changed files with 27 additions and 0 deletions

View File

@ -18,3 +18,7 @@ returns a matrix access token
### convert_md_to_pdf.sh
(need to be used with listings-setup.tex in the same folder, xelatex and pandoc are required)
convert infile.md in the current folder to a pdf file (outfile.pdf) with code blocks in red boxes.
### flatten.sh
move all the files in $1 subdirectories to $1.
**Careful**, this operation is irreversible and manually moving back all the files to where they were supposed to be will be a pain if you flatten your home folder.

23
flatten.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
src_dir=$1
cd "$src_dir" || { echo "Directory not found: $src_dir"; exit 1; }
# Find all files and move them to the root directory
find . -type f -exec sh -c '
for file_path do
file_name=$(basename "$file_path")
target_file="./$file_name"
if [[ "$file_path" != "$target_file" ]]; then
if [ -e "$target_file" ]; then
count=1
while [ -e "./$file_name.$count" ]; do
count=$((count + 1))
done
target_file="./$file_name.$count"
fi
mv "$file_path" "$target_file"
fi
done
' sh {} +
echo "Flattening completed."