From 6a4169fc035737345b70949543af5013ea9f9295 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 30 Sep 2021 01:57:28 +0800 Subject: [PATCH] Make the init tool compatible with BSD --- tools/init.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/init.sh b/tools/init.sh index 5035ff2..f10d8b4 100755 --- a/tools/init.sh +++ b/tools/init.sh @@ -6,6 +6,8 @@ set -eu ACTIONS_WORKFLOW=pages-deploy.yml +TEMP_SUFFIX="to-delete" # temporary file suffixes that make `sed -i` compatible with BSD and Linux + help() { echo "Usage:" echo @@ -61,12 +63,15 @@ init_files() { _workflow=".github/workflows/${ACTIONS_WORKFLOW}" _default_branch="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')" _lineno="$(sed -n "/branches:/=" "$_workflow")" - sed -i "$((_lineno + 1))s/- .*/- ${_default_branch}/" "$_workflow" + + sed -i.$TEMP_SUFFIX "$((_lineno + 1))s/- .*/- ${_default_branch}/" "$_workflow" + rm -f "$_workflow.$TEMP_SUFFIX" fi # trace the gem lockfile on user-end - sed -i "/Gemfile.lock/d" .gitignore + sed -i.$TEMP_SUFFIX "/Gemfile.lock/d" .gitignore + rm -f ".gitignore.$TEMP_SUFFIX" # remove the other fies rm -f .travis.yml