Jump to content

Starship/zh: Difference between revisions

From Official NixOS Wiki
Ardenet (talk | contribs)
Created page with "Bash:"
Ardenet (talk | contribs)
Created page with "=== 进阶 ==="
Tags: Mobile edit Mobile web edit
 
(13 intermediate revisions by 2 users not shown)
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">
<span id="Installation"></span>
== Installation ==
== 安装 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Using_nix-shell"></span>
=== Using nix-shell ===
=== 使用 nix-shell ===
</div>


<syntaxhighlight lang="bash" start="3">
<syntaxhighlight lang="bash" start="3">
Line 16: Line 12:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Using_Global_Configuration"></span>
=== Using Global Configuration ===
=== 使用全局配置 ===
</div>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 26: Line 21:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
修改配置后,运行以下命令应用更改:
After modifying your configuration, apply the changes by running:
</div>


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 43: Line 36:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
配置更新完成后,运行以下命令应用更改:
After updating your configuration, apply the changes by running:
</div>


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 51: Line 42:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Configuration"></span>
== Configuration ==
== 配置 ==
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Basic"></span>
=== Basic ===
=== 基础 ===
</div>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 63: Line 52:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
安装 Starship 后,你需要在 shell 中执行 source 命令
after you have installed Starship you need to source it in your shell
</div>


Bash:
Bash:
Line 85: Line 72:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
如果您使用我刚才提到的其他 shell,请前往此 [https://starship.rs/guide/#step-2-set-up-your-shell-to-use-starship 页面]
if you use other shells than what I just mentioned please head to this [https://starship.rs/guide/#step-2-set-up-your-shell-to-use-starship page]
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
<span id="Advanced"></span>
=== Advanced ===
=== 进阶 ===
</div>


<div lang="en" dir="ltr" class="mw-content-ltr">
你可以使用 Nix 自定义 Starship(这里有一个代码片段以供理解)
you can customize Starship with Nix (here's a snippet to understand)
<nowiki>:</nowiki>
<nowiki>:</nowiki>
</div>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
Line 114: Line 96:
</syntaxhighlight>
</syntaxhighlight>


<div lang="en" dir="ltr" class="mw-content-ltr">
由于我们无法包含 Starship 上的每个选项,因此这里有一个 GitHub 链接 <noinclude> [https://gist.github.com/s-a-c/0e44dc7766922308924812d4c019b109#file-starship-nix/ 包含每个配置选项] </noinclude> 这里有官方文档来解释每个选项, [https://starship.rs/config/ Starship 配置指南]
since we can't include every option on Starship here's a GitHub link <noinclude> [https://gist.github.com/s-a-c/0e44dc7766922308924812d4c019b109#file-starship-nix/ containing every configuration option] </noinclude> and here's the official documentation to explain each option [https://starship.rs/config/ Starship configuration guide]
</div>


祝你好运 :D
祝你好运 :D


[[Category:Shell|分类:Shell]]
[[Category:Shell]]

Latest revision as of 10:41, 8 March 2026

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

安装

使用 nix-shell

nix-shell -p starship

使用全局配置

environment.systemPackages = [
  pkgs.starship
];

修改配置后,运行以下命令应用更改:

sudo nixos-rebuild switch

使用 Home Manager

home.packages = [ 
  pkgs.starship 
];

配置更新完成后,运行以下命令应用更改:

home-manager switch

配置

基础

programs.starship.enable = true;

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

Bash:

eval "$(starship init bash)"

Zsh:

eval "$(starship init zsh)"

Fish:

starship init fish | source

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

进阶

你可以使用 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