Skip to content

Commit e37db92

Browse files
committed
Added conversion in opposite direction to adjust-markdown.sh
1 parent 7e440a2 commit e37db92

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

adjust-markdown.sh

+21-1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,24 @@ if [ "$deeperpart" != "$newdir" ] && [ "$slashes" != "" ]; then # new dir is dee
6464
fi
6565
fi
6666

67-
just_exit "Destination path is not deeper than original markdown file"
67+
# For completeness, make the conversion work in the opposite direction:
68+
69+
deeperpart="${orgdir#$newdir}"
70+
slashes="${deeperpart//[^\/]}"
71+
72+
if [ "$deeperpart" != "$orgdir" ] && [ "$slashes" != "" ]; then # new dir is *less* deep
73+
frompat='/'; topat='/..'
74+
toadd="${slashes//$frompat/$topat}" # Remove an extra "/.." for each level deeper
75+
# so if slashes="//", toadd will now be "/../.."
76+
77+
exec 9> "$newpath" || just_exit "Cannot open output file ($newpath)"
78+
if cat "$orgpath" | sed -e "s,$toadd/blob/,/blob/,g" -e "s,$toadd/tree/,/tree/,g" >&9; then
79+
echo "New file successfully written at $newpath"
80+
exit 0
81+
else
82+
rm "$newpath"
83+
just_exit "Error while processing with with sed"
84+
fi
85+
fi
86+
87+
just_exit "Source and destination markdown files are at the same level"

0 commit comments

Comments
 (0)