Jump to content

Starship/zh: Difference between revisions

From NixOS Wiki
Ardenet (talk | contribs)
Created page with "安装 Starship 后,你需要在 shell 中执行 source 命令"
Tags: Mobile edit Mobile web edit
Ardenet (talk | contribs)
Created page with "[https://starship.rs/ Starship] 是一个快速、可自定义且极简的 shell 提示符。它使用 Rust 编写,显示当前目录、Git 状态、运行时版本等相关信息,并以极简配置适应上下文。它支持多种 shell,包括 Bash、[https://wiki.nixos.org/wiki/Zsh Zsh]、[https://wiki.nixos.org/wiki/Fish Fish]、PowerShell 以及其他许多 shell,并且您的配置将在所有这些 shell 中保持一致,其设..."
 
Line 1: Line 1:
<languages/>
<languages/>
<div lang="en" dir="ltr" class="mw-content-ltr">
[https://starship.rs/ Starship] 是一个快速、可自定义且极简的 shell 提示符。它使用 Rust 编写,显示当前目录、Git 状态、运行时版本等相关信息,并以极简配置适应上下文。它支持多种 shell,包括 [[Special:MyLanguage/Bash|Bash]][https://wiki.nixos.org/wiki/Zsh Zsh][https://wiki.nixos.org/wiki/Fish Fish]、PowerShell 以及其他许多 shell,并且您的配置将在所有这些 shell 中保持一致,其设计旨在提高速度和效率。
[https://starship.rs/ Starship] is a fast, customizable, and minimal prompt for any shell. It is written in Rust and displays relevant information like the current directory, Git status, runtime versions, and more, adapting to the context with minimal configuration. It supports multiple shells, including [[Bash]], [https://wiki.nixos.org/wiki/Zsh Zsh], [https://wiki.nixos.org/wiki/Fish Fish], PowerShell and a lot of other shells, and your configuration will stay persistent across all these shells and is designed for speed and efficiency.
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<div lang="en" dir="ltr" class="mw-content-ltr">

Latest revision as of 15:07, 10 October 2025

Starship 是一个快速、可自定义且极简的 shell 提示符。它使用 Rust 编写,显示当前目录、Git 状态、运行时版本等相关信息,并以极简配置适应上下文。它支持多种 shell,包括 BashZshFish、PowerShell 以及其他许多 shell,并且您的配置将在所有这些 shell 中保持一致,其设计旨在提高速度和效率。

Installation

Using nix-shell

nix-shell -p starship

Using Global Configuration

environment.systemPackages = [
  pkgs.starship
];

After modifying your configuration, apply the changes by running:

sudo nixos-rebuild switch

使用 Home Manager

home.packages = [ 
  pkgs.starship 
];

After updating your configuration, apply the changes by running:

home-manager switch

Configuration

Basic

programs.starship.enable = true;

安装 Starship 后,你需要在 shell 中执行 source 命令

Bash:

eval "$(starship init bash)"

Zsh:

eval "$(starship init zsh)"

Fish:

starship init fish | source

如果您使用我刚才提到的其他 shell,请前往此 页面

Advanced

你可以使用 Nix 自定义 Starship(这里有一个代码片段以供理解) :

programs.starship = {
  enable = true;
  settings = {
    add_newline = true;
    command_timeout = 1300;
    scan_timeout = 50;
    format = "$all$nix_shell$nodejs$lua$golang$rust$php$git_branch$git_commit$git_state$git_status\n$username$hostname$directory";
    character = {
      success_symbol = "[](bold green) ";
      error_symbol = "[✗](bold red) ";
    };
  };
};

由于我们无法包含 Starship 上的每个选项,因此这里有一个 GitHub 链接 包含每个配置选项 这里有官方文档来解释每个选项, Starship 配置指南

祝你好运 :D