forked from p7zip-project/p7zip
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61c9f0c
commit 4063a8e
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |