Skip to content

fix(startup): read ~/.bashrc then ~/.niubashrc for interactive non-login shells (#1158) - #1187

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/1158-bashrc-compat
Oct 23, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/1158-bashrc-compat

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1158 — owner decision: compatible reading (兼容读).

Problem

niu -i ignored ~/.bashrc and read only ~/.niubashrc, so every .bashrc-based setup was silently dead under niu. Root cause in the engine (per the issue's own triage): run_startup_files (GNU shell.c:722 → :1833-1880) was #[cfg(not(windows))]-gated, so on Windows rubash.exe -i sourced no startup files at all, and .niubashrc was not an engine name.

Changes

  • src/main.rs::run_startup_files — the non-login interactive branch (else if (interactive) in shell.c:1833) now runs on every platform. The login profile chain stays not(windows) (no real login concept; [bug] Login+interactive shells skip the rc file #1159 was closed NOT-A-BUG — a .bash_profile that wants .bashrc sources it itself). --noprofile/--norc gate their respective branches as before.
  • src/invocation.rs::nonlogin_interactive_files — the personal-rc slot is now ~/.bashrc then ~/.niubashrc: GNU's own file first (the migration path), niu's own config last so it overrides. Each candidate enters only when it exists. --rcfile replaces the whole personal slot (GNU bashrc_file semantics) — it suppresses both candidates.
  • src/main.rs::run_init_file — a syntax error in a startup file no longer aborts startup. GNU evalstring.c:585-606 (parse_and_execute) returns EX_BADUSAGE as an ordinary value: the diagnostic prints and startup continues. The reader-discard jump is consumed via the same take_parse_error() gate the source builtin uses; a real exit carries no parse flag and still terminates (rubash#297).

GNU oracle verification (WSL /usr/local/bin/bash 5.3.20, script-file probes)

case GNU 5.3.20 rubash after
~/.bashrc only, -i -c BASHRC + AFTER, rc 0 same
~/.niubashrc only, -i -c AFTER only NIURC + AFTER (extension)
both present (bashrc only — GNU has no .niubashrc) BASHRC → NIURC, niu var wins
--norc -i -c AFTER only same
--rcfile f -i -c, both defaults present only f same
non-interactive -c no rc same
--login -i -c (Windows) n/a AFTER only (unchanged)
syntax error in rc diagnostic + AFTER, rc 0 same (was: abort rc 2)
exit 7 in rc terminates before -c same (rc 7, rubash#297)

HOME-unset caveat: probed — env -u HOME bash -i on GNU still sources .bashrc via getpwuid (there is no HOME-independent way to disable it). On Windows the engine has no passwd fallback, so HOME + all Windows fallbacks unset → no rc; the test documents this rather than faking parity.

Scope note: niu.exe runs its own startup chain in the niubash host (niubash-runtime::shell::run_startup_files, which reads only ~/.niubashrc) — this PR ships the engine-side contract; a niubash-side follow-up can delegate to invocation::nonlogin_interactive_files to activate it in the product.

Tests

  • New tests/issue1158_bashrc_compat.rs — 12 tests covering the full matrix above (isolated fake HOME; all green on Windows).
  • New unit test nonlogin_interactive_chain_runs_bashrc_then_niubashrc in src/invocation.rs.
  • cargo test --test issue1158_bashrc_compat: 12/12 ok
  • cargo test --lib invocation: 21/21 ok
  • cargo test --test issue297_300_interactive_init_regressions --test issue312_interactive_noedit_defaults_regressions: 19/19 ok
  • cargo test --test cli_tests: 471 passed; the only failures are pre-existing on unmodified master (verified by rebuilding master without this diff): background_redirected_job_releases_stdout_pipe_at_exit and examples::* (missing third_party/bash submodule checkout in the worktree — green after extraction). The version test is green post-commit.
  • cargo test --test regression: 78/78 ok

Generated with Devin

…gin shells (rubash#1158)

Owner decision: compatible reading. Two changes:

1. run_startup_files (src/main.rs, GNU shell.c:722 -> :1833-1880) was
   #[cfg(not(windows))]-gated, so on Windows `niu -i` sourced no rc at
   all and ~/.bashrc was silently dead. The non-login interactive
   branch now runs on every platform; the login profile chain stays
   not(windows) (no real login concept; #1159 closed NOT-A-BUG).

2. nonlogin_interactive_files (src/invocation.rs, shell.c:1863-1880):
   the personal-rc slot is now ~/.bashrc then ~/.niubashrc — GNU's own
   file first as the migration path, niu's config last so it
   overrides. --rcfile still replaces the whole personal slot
   (bashrc_file); --norc skips both; empty HOME sources nothing.

Also consume the reader-discard jump on a startup-file parse error
(run_init_file): GNU evalstring.c:585-606 returns EX_BADUSAGE as an
ordinary value, so a broken rc prints its diagnostic and startup
continues — verified WSL GNU 5.3.20 (`bash --rcfile bad.rc -i -c
'echo AFTER'` -> error + AFTER, rc 0). A real `exit` carries no
parse flag and still terminates (rubash#297).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[question] niu ignores ~/.bashrc, reads ~/.niubashrc — migration path?

1 participant