Skip to content

Commit

Permalink
fix: add missing extension to sed flag seek_and_modify_string_in_file…
Browse files Browse the repository at this point in the history
… for portability (mac OsX)
  • Loading branch information
RedLeader962 committed Jan 24, 2024
1 parent cf72db1 commit a70b6f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/function_library/general_utilities.bash
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ function n2st::seek_and_modify_string_in_file() {

# Note:
# - Character ';' is used as a delimiter
# - Keep -i flag for portability to Mac OsX
sudo sed -i "s;${TMP_SEEK};${TMP_CHANGE_FOR};" "${TMP_FILE_PATH}"
# - Keep -i flag for portability to Mac OsX (it's analogue to --in-place flag)
# - .bak is the backup extension convention and is required by -i
sudo sed -i.bak "s;${TMP_SEEK};${TMP_CHANGE_FOR};" "${TMP_FILE_PATH}" && rm "${TMP_FILE_PATH}.bak"

}

Expand Down
3 changes: 3 additions & 0 deletions tests/test_general_utilities.bats
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ teardown() {

run n2st::seek_and_modify_string_in_file "${LOOKUP_STR}.*" "${MODIFIED_STR}" "$TMP_TEST_FILE"
assert_success

assert_file_exist "${TMP_TEST_FILE}"

run n2st::preview_file_in_promt "$TMP_TEST_FILE"
assert_output --partial "${UNCHANGED_STR}"
refute_output --partial "${ORIGINAL_STR}"
Expand Down

0 comments on commit a70b6f9

Please sign in to comment.