Skip to content

Commit

Permalink
add d2u-dir.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
cielavenir committed Oct 25, 2022
1 parent 61c9f0c commit 4063a8e
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions d2u-dir.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/sh

# https://gist.github.com/tansy/c4a1f7ea1019915b4263c024757d3ac4
# https://github.com/jinfeihan57/p7zip/pull/186#issuecomment-1223976885

if [ $# -eq 0 ]; then
echo "d2u-dir <directory1/dos> <directory2/ux>"
echo "will copy contents of <dir1> to <dir2> changing new lines from dos to unix."
echo "It ignores binary files by their extension,"
echo "so you may want to copy whole dir1 to dir2 first and then apply d2u-dir."
exit 0
fi

# reference dir:
DIR0="${1}"
# new dir:
DIR1="${2}"
if [ -d "${DIR1}" ]; then
echo "directory ${DIR1} exists, do you want to continue? [y/N]"
read ANS
if [ "${ANS}" == "y" ] || [ "${ANS}" == "Y" ]; then
continue
else
exit 0
fi
fi

IFS="
"

if [ -n "${DIR1}" ]; then

for line in `find "${DIR0}" -type d`; do
mkdir -p "${DIR1}/${line#$DIR0}"
done
# every `.' denoting extension has to escaped, every extension terminated with $
for line in `find "${DIR0}" -type f | grep -Ev '\.git|\.BMP$|\.bmp$|\.BIN$|\.bin$|\.CUR$|\.cur$|\.DSP$|\.dsp$|\.DSW$|\.dsw$|\.EXE$|\.exe$|\.GIF$|\.gif$|\.icns$|\.ICO$|\.ico$|\.JAR$|\.jar$|\.JPG$|\.jpg$|\.jpeg$|\.PCX$|\.pcx$|\.PNG$|\.png$|\.RES$|\.res$|\.SFX$|\.sfx$|\.WAV$|\.wav$'`; do
dos2unix < "${line}" > "${DIR1}/${line#$DIR0}"
touch -r "${line}" "${DIR1}/${line#$DIR0}"
done
for line in `find "${DIR0}" -type d`; do
touch -r "${line}" "${DIR1}/${line#$DIR0}"
done

else

for line in `find "${DIR0}" -type f | grep -Ev '\.git|\.BMP$|\.bmp$|\.BIN$|\.bin$|\.CUR$|\.cur$|\.DSP$|\.dsp$|\.DSW$|\.dsw$|\.EXE$|\.exe$|\.GIF$|\.gif$|\.icns$|\.ICO$|\.ico$|\.JAR$|\.jar$|\.JPG$|\.jpg$|\.jpeg$|\.PCX$|\.pcx$|\.PNG$|\.png$|\.RES$|\.res$|\.SFX$|\.sfx$|\.WAV$|\.wav$'`; do
dos2unix "${line}"
done

fi

0 comments on commit 4063a8e

Please sign in to comment.