fish-shell/fish-shell
GitHub: fish-shell/fish-shell
Fish 是一款开箱即用的智能命令行 shell,通过内置的语法高亮、自动建议和强大的 Tab 补全功能,让终端操作更加直观高效。
Stars: 32783 | Forks: 2230
.. |Cirrus CI| image:: https://api.cirrus-ci.com/github/fish-shell/fish-shell.svg?branch=master
:target: https://cirrus-ci.com/github/fish-shell/fish-shell
:alt: Cirrus CI 构建状态
# `fish `__ - 友好的交互式 shell |Build Status| |Cirrus CI|
fish 是一个智能且用户友好的命令行 shell,适用于 macOS、Linux 以及其他同类系统。fish 包含语法高亮、即时自动建议以及开箱即用的精美 Tab 补全等功能,无需任何配置即可使用。
欲下载、查看截图及了解更多信息,请访问 https://fishshell.com/。
## 快速入门
fish 的工作方式通常与 bash 或 zsh 等其他 shell 类似。您可以在 https://fishshell.com/docs/current/tutorial.html 搜索关键词“unlike other shells”,找到一些重要的差异说明。
详细的用户文档可以在 fish 中运行 ``help`` 查看,也可访问 https://fishshell.com/docs/current/index.html
## 获取 fish
### macOS
fish 可以通过以下方式安装:
- 使用 `Homebrew `__:``brew install fish``
- 使用 `MacPorts `__:
``sudo port install fish``
- 使用 `fishshell.com 提供的安装程序 `__
- 作为 `fishshell.com 提供的独立应用程序 `__
注意:支持的最低 macOS 版本为 10.12。
### Linux 软件包
适用于 Debian、Fedora、openSUSE 和 Red Hat Enterprise Linux/CentOS 的软件包可从 `openSUSE Build Service `__ 获取。
适用于 Ubuntu 的软件包可从 `fish PPA `__ 获取,并可使用以下命令进行安装:
::
sudo apt-add-repository ppa:fish-shell/release-4
sudo apt update
sudo apt install fish
其他发行版的说明可在 `fishshell.com `__ 找到。
### Windows
- 在 Windows 10/11 上,fish 可以在 WSL (Windows Subsystem for Linux) 下安装,请按照上方“Linux 软件包”中列出的相应发行版说明操作,或者按照下方的说明从源代码构建。
- Fish 也可以使用 `Cygwin `__ 或 `MSYS2 `__ 在所有版本的 Windows 上安装。
### 从源代码构建
如果您的平台没有可用的软件包,可以从 `fishshell.com `__ 和 `GitHub 上的 fish-shell `__ 获取 GPG 签名的压缩包。有关说明,请参阅 `构建 <#building>`_ 章节。
## 运行 fish
安装完成后,在当前 shell 中运行 ``fish`` 即可试用 fish!
### 依赖项
运行 fish 需要:
- 一些常见的 \*nix 系统工具(目前需要 ``mktemp``),以及基本的 POSIX 工具(至少包括 ``cat``、``cut``、``dirname``、``ls``、``mkdir``、``mkfifo``、``rm``、``sh``、``sort``、``tee``、``tr``、``uname`` 和 ``sed``,但建议安装完整的 coreutils 以及 ``find`` 和 ``awk``)
以下可选功能也有特定要求:
- 具有 ``--help`` 选项或打印用法消息的内置命令需要 ``man`` 进行显示
- 从手册页自动生成补全需要 Python 3.5+
- ``fish_config`` Web 配置工具需要 Python 3.5+ 和 Web 浏览器
- :ref:`alt-o ` 绑定需要 ``file`` 程序。
- 系统剪贴板集成(使用默认的 Ctrl-V 和 Ctrl-X 绑定)需要 ``xsel``、``xclip``、``wl-copy``/``wl-paste`` 或 ``pbcopy``/``pbpaste`` 工具
- ``yarn`` 和 ``npm`` 的完整补全需要 ``all-the-package-names`` NPM 模块
- 如果安装了 ``colorls``,在不支持颜色功能的平台(如 OpenBSD)上运行 ``ls`` 时会使用它来添加颜色
## 构建
### 依赖项
编译 fish 需要:
- Rust(1.85 或更高版本),包括 cargo
- CMake(3.15 或更高版本)
- C 编译器(用于系统功能检测和测试辅助二进制文件)
- PCRE2(头文件和库)- 可选,如果缺失将自动下载
- gettext(仅需 msgfmt 工具)- 可选,用于翻译支持
- Internet 连接,因为其他依赖项将自动下载
如果要从克隆的 git 仓库构建文档,则可选需要 Sphinx。
此外,运行完整的测试套件需要 diff、git、Python 3.5+、pexpect、less、tmux 和 wget。
### 使用 CMake 从源代码构建
建议考虑使用您平台的预打包构建版本,而不是从源代码构建。使用以下步骤会导致 fish 难以卸载或升级。上方链接提供了发布包,并且 `许多平台都有最新的 fish 开发构建 `__
要安装到 ``/usr/local``,请运行:
.. code:: shell
mkdir build; cd build
cmake ..
cmake --build .
sudo cmake --install .
可以使用 ``cmake`` 的 ``-DCMAKE_INSTALL_PREFIX`` 参数更改安装目录。
### CMake 构建选项
除了常规的 CMake 构建选项(如 ``CMAKE_INSTALL_PREFIX``)外,fish 的 CMake 构建还提供了一些其他自定义选项。
- Rust_COMPILER=path - rustc 的路径。如果未设置,cmake 将检查 $PATH 和 ~/.cargo/bin
- Rust_CARGO=path - cargo 的路径。如果未设置,cmake 将检查 $PATH 和 ~/.cargo/bin
- Rust_CARGO_TARGET=target - 传递给 cargo 的目标。设置此项以进行交叉编译。
- WITH_DOCS=ON|OFF - 是否构建文档。默认情况下,安装 Sphinx 时为 ON。
- FISH_INDENT_FOR_BUILDING_DOCS - 对交叉编译很有用。
将此设置为用于构建 HTML 文档的 ``fish_indent`` 可执行文件的路径。
默认情况下,将使用 ``${CMAKE_BINARY_DIR}/fish_indent``。
如果该文件无法在编译主机上运行,
您可以使用 ``cargo build --bin fish_indent`` 构建一个原生版本,并将此设置为 ``$PWD/target/debug/fish_indent``。
- FISH_USE_SYSTEM_PCRE2=ON|OFF - 是否使用已安装的 pcre2。通常会自动检测。
- WITH_MESSAGE_LOCALIZATION=ON|OFF - 是否包含翻译。
- extra_functionsdir、extra_completionsdir 和 extra_confdir - 编译入用于搜索函数、补全和配置片段的额外目录
### 使用 Cargo 构建 fish
您也可以使用 Cargo 构建 fish。
此示例使用 `uv `__ 安装 Sphinx(用于手册页和 ``--help`` 选项)。
您也可以通过其他方式安装 Sphinx,并去掉 ``uv run --no-managed-python`` 前缀。
.. code:: shell
```
git clone https://github.com/fish-shell/fish-shell
cd fish-shell
# Optional: check out a specific version rather than building the latest
# development version.
git checkout "$(git for-each-ref refs/tags/ | awk '$2 == "tag" { print $3 }' | tail -1)"
uv run --no-managed-python \
cargo install --path .
```
这会将独立二进制文件放置在 ``~/.cargo/bin/`` 中,但您可以将它们移动到任何您想要的位置。
要禁用翻译,请通过向 cargo 传递 ``--no-default-features --features=embed-manpages`` 来禁用 ``localize-messages`` 功能。
您也可以静态链接此构建(但不能针对 glibc)并将其移动到其他计算机。
以下是完整安装(如 CMake 目前所做的那样)的其余优势:
- 手册页(如 ``fish(1)``)安装在标准位置,可从 fish 外部轻松访问。
- 内置命令的独立文件(例如 ``$PREFIX/share/fish/man/man1/abbr.1``)。
- HTML 文档的本地副本,通常通过 ``help`` fish 函数访问。
在 Cargo 构建中,``help`` 将重定向到 ` `__
- 能够使用我们的 CMake 选项 extra_functionsdir、extra_completionsdir 和 extra_confdir,
(也记录在 ``$PREFIX/share/pkgconfig/fish.pc`` 中)
这些选项被某些包管理器用来存放第三方补全。
无论构建系统如何,fish 都使用 ``$XDG_DATA_DIRS/{vendor_completion.d,vendor_conf.d,vendor_functions.d}``。
## 贡献代码更改
请参阅 `开发者指南 `__。
## 联系我们
如有问题、评论、吐槽或建议,可以发送到官方 fish 邮件列表 https://lists.sourceforge.net/lists/listinfo/fish-users,或者加入我们的 `Matrix 频道 `__。也可以使用 `Unix & Linux Stackexchange 上的 fish 标签 `__。
Stackoverflow 上也有一个 fish 标签,但通常不太合适。
发现了错误?有一个绝妙的想法?请 `提出 issue `__。
.. |Build Status| image:: https://github.com/fish-shell/fish-shell/workflows/make%20test/badge.svg
:target: https://github.com/fish-shell/fish-shell/actions
标签:Awesome, bash替代, Bash脚本, CLI, fish-shell, Shell, Unix, WiFi技术, zsh替代, 交互式Shell, 可视化界面, 命令行界面, 威胁情报, 开发者工具, 数字足迹, 系统管理, 终端, 网络调试, 脚本语言, 自动化, 自动补全, 语法高亮, 运维工具, 逆向工具, 通知系统, 通知系统