Jump to content

Starship/zh

From NixOS Wiki
This page is a translated version of the page Starship and the translation is 55% complete.

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