Improvement: Add deduplication check in bashrc/zshrc 00-init to prevent unbounded PATH growth

未关闭
#1,824 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@mylinuxforwork 已经在做这个了。

开始于 2026年9月5日。

评估

这个 Issue 还没有评估数据。

描述

bug
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 long on new process executions.
  • Compositor shortcuts failing to spawn programs.
    Adding a simple check before appending makes 00-init idempotent 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 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

mylinuxforwork/dotfiles 的其他 Issue

查看 mylinuxforwork/dotfiles 的全部 Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。