diff --git a/nu/tests.nu b/nu/tests.nu index 0c6c8216e..2cadf4c5e 100644 --- a/nu/tests.nu +++ b/nu/tests.nu @@ -72,9 +72,13 @@ def run_test [test: record]: nothing -> record> /etc/shells + let content = open /etc/shells + const nu_bin = '/usr/bin/nu' + if ($content | str contains $nu_bin) { + return } + mut $new_line = $"($nu_bin)\n" + # Handle edge case when the content doesn't have ending newline, + # blindly appending the $new_line will end up writing to the same line. + if not ($content | str ends-with "\n") { + $new_line = "\n" ++ $new_line + } + echo $new_line o>> /etc/shells } def main [] { diff --git a/scripts/pre-remove.nu b/scripts/pre-remove.nu index 862469d56..24c32a7d5 100755 --- a/scripts/pre-remove.nu +++ b/scripts/pre-remove.nu @@ -5,11 +5,13 @@ # Remove /usr/bin/nu from /etc/shells def 'remove-nu-from-shells' [] { - open /etc/shells + let new_content = open /etc/shells | lines | where $it !~ '/usr/bin/nu' | str join "\n" - | save -rf /etc/shells + # Keep a new line at the end of file to prevent other packages from making mistake + # when modifying this file. + $new_content ++ "\n" | save -rf /etc/shells } def main [] {