Skip to content

Commit

Permalink
Fix multi-line commands handling
Browse files Browse the repository at this point in the history
Define `LC_ALL` variable with value `C` to avoid "Invalid byte sequence"
error with `tr` and `sort` commands on macOS.
  • Loading branch information
Andrei authored and wulfgarpro committed Oct 4, 2022
1 parent e66cc5a commit 611988b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions history-sync.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ function _squash_multiline_commands_in_files() {
# Generate random character sequences to replace \n and anchor the first
# line of a command (use global variable for new-line-replacement to use it
# in the restore-multi-line commands function)
NL_REPLACEMENT=$(tr -dc 'a-zA-Z0-9' < /dev/urandom |
NL_REPLACEMENT=$(LC_ALL=C tr -dc 'a-zA-Z0-9' < /dev/urandom |
fold -w 32 | head -n 1)
local FIRST_LINE_ANCHOR=$(tr -dc 'a-zA-Z0-9' < /dev/urandom |
local FIRST_LINE_ANCHOR=$(LC_ALL=C tr -dc 'a-zA-Z0-9' < /dev/urandom |
fold -w 32 | head -n 1)

for i in "$ZSH_HISTORY_FILE" "$ZSH_HISTORY_FILE_DECRYPT_NAME"; do
Expand Down Expand Up @@ -99,7 +99,7 @@ function _squash_multiline_commands_in_files() {
cat "${TMP_FILE_1}" >> "${i}"

# Sort history file
sort -n < "${i}" > "${TMP_FILE_1}" && mv "${TMP_FILE_1}" "${i}"
LC_ALL=C sort -n < "${i}" > "${TMP_FILE_1}" && mv "${TMP_FILE_1}" "${i}"
done
}

Expand Down

0 comments on commit 611988b

Please sign in to comment.