Skip to content

Commit

Permalink
Use perl instead of non-GNU sed
Browse files Browse the repository at this point in the history
Fixes: #22
  • Loading branch information
wulfgarpro committed Sep 13, 2023
1 parent 0e4eb1a commit 946306e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions history-sync.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ alias zhsync="history_sync_pull && history_sync_push"

GIT=$(which git)
GPG=$(which gpg)
SED_VERSION=$(sed --version 2>&1)

ZSH_HISTORY_PROJ="${ZSH_HISTORY_PROJ:-${HOME}/.zsh_history_proj}"
ZSH_HISTORY_FILE_NAME="${ZSH_HISTORY_FILE_NAME:-.zsh_history}"
Expand Down Expand Up @@ -92,9 +93,13 @@ function _squash_multiline_commands_in_files() {
&& mv "${TMP_FILE_2}" "${TMP_FILE_1}"

# Replace all \n with a sequence of symbols
SED ':a;N;$!ba;s/\n/'" ${NL_REPLACEMENT} "'/g' \
"${TMP_FILE_1}" > "${TMP_FILE_2}" \
&& mv "${TMP_FILE_2}" "${TMP_FILE_1}"
if [[ "$SED_VERSION" == *"GNU"* ]]; then
SED ':a;N;$!ba;s/\n/'" ${NL_REPLACEMENT} "'/g' \
"${TMP_FILE_1}" > "${TMP_FILE_2}"
else
# Assume BSD `sed`
perl -0777 -pe 's/\n/'"${NL_REPLACEMENT}"'/g' "${TMP_FILE_1}" > "${TMP_FILE_2}"
mv "${TMP_FILE_2}" "${TMP_FILE_1}"

# Replace first line anchor by \n
SED "s/${FIRST_LINE_ANCHOR} \(: [0-9]\{1,10\}:[0-9]\+;\)/\n\1/g" \
Expand Down

0 comments on commit 946306e

Please sign in to comment.