Improvement: Add deduplication check in bashrc/zshrc 00-init to prevent unbounded PATH growth
维护者通常 1 天内回复
@mylinuxforwork 已经在做这个了。
开始于 2026年9月5日。
评估
这个 Issue 还没有评估数据。
描述
Describe the bug
In ~/.config/bashrc/00-init and ~/.config/zshrc/00-init, the cargo and local bin directories are appended directly to $PATH without checking if they are already present:
export PATH=$PATH:~/.cargo/bin/
export PATH=$PATH:~/.local/bin/
In standard daily terminal usage, this goes unnoticed because a fresh terminal only sources .bashrc once.
However, in more advanced setups (e.g. running background widgets like Quickshell, custom toolchains, nested subshells invoking bash -c, or scripts that re-source the shell environment), 00-init can be executed multiple times within the same session hierarchy.
Because there is no duplicate check, the exact same paths are appended over and over again. Eventually, $PATH can grow to hundreds of kilobytes and hit the Linux kernel limit (ARG_MAX), resulting in:
E2BIG: Argument list too longon new process executions.- Compositor shortcuts failing to spawn programs.
Adding a simple check before appending makes00-initidempotent and bulletproof against repeated sourcing.
Steps to reproduce
1. Open a terminal and check the length of `$PATH`:
`echo $PATH | wc -c`
2. Simulate repeated subshell invocations or run the desktop session across multiple sleep/wake cycles:
`for i in {1..50}; do bash -c 'true'; done`
3. Inspect `$PATH`:
`echo $PATH`
4. Notice dozens of duplicated `~/.cargo/bin` and `~/.local/bin` entries inflating the environment size.
### Expected behavior
Pads should only be added to `$PATH` if they are not already present, preventing duplicate entries and buffer overflows regardless of how often subshells are spawned.
**Proposed fix for `00-init`:**
```bash
# Add ~/.cargo/bin if not already in PATH
case ":$PATH:" in
*":$HOME/.cargo/bin:"*) ;;
*) export PATH="$PATH:$HOME/.cargo/bin" ;;
esac
# Add ~/.local/bin if not already in PATH
case ":$PATH:" in
*":$HOME/.local/bin:"*) ;;
*) export PATH="$PATH:$HOME/.local/bin" ;;
esac
### Screenshots
_No response_
### Distribution
Other (please specify below)
### If Other, specify
CachyOS
### Additional context
_No response_
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct
- 主要语言
- QML
- 星标
- 5.1k
- 派生
- 386
- 平均合并
- 16 小时 45 分钟
- 30 天内合并 PR
- 14
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
mylinuxforwork/dotfiles 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
mylinuxforwork/dotfiles#1904 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 82/100
mylinuxforwork/dotfiles#1829 ·
维护者通常 1 天内回复
-
enhancement solved
难度 2/5 1-3 小时 新手友好度 74/100
mylinuxforwork/dotfiles#1807 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 78/100
mylinuxforwork/dotfiles#1765 · 1 条评论 ·
维护者通常 1 天内回复
-
[FEATURE] add keycap 1 app window over all windows可能已有人在做 @mylinuxforwork 于 1 天前认领。 未关闭enhancement
mylinuxforwork/dotfiles#1902 · 已指派 1 人 ·
维护者通常 1 天内回复