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 16, 2023
1 parent 0e4eb1a commit eede73d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ jobs:
setup_and_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: docker build . --file test/Dockerfile --build-arg ACCESS_KEY=${ACCESS_KEY} --tag test/history-sync:latest
- run: docker run test/history-sync:latest; exit $?
14 changes: 10 additions & 4 deletions history-sync.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
# * James Fraser <[email protected]>
# https://www.wulfgar.pro
# ----------------------------------------------------------------
#
autoload -U colors && colors

alias zhpl=history_sync_pull
Expand All @@ -20,6 +19,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 +92,15 @@ 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}"
fi
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
12 changes: 12 additions & 0 deletions test/test.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function check_env_exists() {
}

function check_history() {
cat ~/.zsh_history
rg -U "$1" ~/.zsh_history >/dev/null
[[ $? -eq 0 ]] || {failure "FAILURE: History did not match '$1'"}
}
Expand Down Expand Up @@ -111,3 +112,14 @@ done" >> ~/.zsh_history
zhps -y -r $UID && zhpl -y
check_history "^1 for i in \{1..3\}; do\necho \\\$i\ndone$"
success "SUCCESS"

info "TEST SYNC HISTORY MULTI-LINE PERL"
setup
alias sed="echo"
echo "1 for i in {1..3}; do
echo \$i
done" >> ~/.zsh_history
zhps -y -r $UID && zhpl -y
check_history "^1 for i in \{1..3\}; do\necho \\\$i\ndone$"
unalias sed
success "SUCCESS"

0 comments on commit eede73d

Please sign in to comment.