File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -40,8 +40,25 @@ function main {
4040function replace_old_markers {
4141 local -r file=$1
4242
43- sed -i " s/^${old_insertion_marker_begin} $/${insertion_marker_begin} /" " $file "
44- sed -i " s/^${old_insertion_marker_end} $/${insertion_marker_end} /" " $file "
43+ # Detect sed version, if on MacOS use gsed to support -i parameter
44+ if [[ " $OSTYPE " == " linux-gnu" * ]]; then
45+ SED_COMMAND=" sed"
46+ elif [[ " $OSTYPE " == " darwin" * ]]; then
47+ set +e # next command may fail - allow failure
48+ PRG=" $( command -v " gsed" 2> /dev/null) "
49+ set -e # exit script on any error again
50+ if [ -z " $PRG " ]; then
51+ echo " ERROR: Detected MacOS but no gsed installed - install it via brew (brew install gsed)"
52+ exit 1
53+ fi
54+ SED_COMMAND=" gsed"
55+ else
56+ echo " ERROR: Unsupported OS system - hook supports MacOS and Linux only"
57+ exit 1
58+ fi
59+
60+ ${SED_COMMAND} -i " s/^${old_insertion_marker_begin} $/${insertion_marker_begin} /" " $file "
61+ ${SED_COMMAND} -i " s/^${old_insertion_marker_end} $/${insertion_marker_end} /" " $file "
4562}
4663
4764# ######################################################################
You can’t perform that action at this time.
0 commit comments