[ Content contribution] Starship介绍: cross shell prompt
Tofloor
poster avatar
Equationzhao
deepin
2023-09-08 10:45
Author

Starship

an alternative to omp

starship 是一个使用 rust 编写的 cross-shell prompt

官网描述如下

轻量、迅速、可无限定制的高颜值终端!

  • 快: 很快 —— 真的真的非常快! 🚀
  • 定制化: 可定制各种各样的提示符。
  • 通用: 适用于任何 Shell、任何操作系统。
  • 智能: 一目了然地显示相关信息。
  • 功能丰富: 支持所有你喜欢的工具。
  • 易用: 安装快速 —— 几分钟就可上手。

原本使用的是 oh-my-posh, 但是有点慢,所以试一下这个(好像也没快多少)

btw 如果有rust语言洁癖的话也可以用这个

安装

任选一种方式进行安装

Windows 🪟

# scoop
scoop install starship

# cargo
cargo install starship --locked

# Chocolatey
choco install starship

# winget
winget install --id Starship.Starship

macOS 🍎

# homebrew
brew install starship

# MacPorts
port install starship

# cargo
cargo install starship --locked

# curl
curl -sS https://starship.rs/install.sh | sh

Linux 🐧

curl -sS https://starship.rs/install.sh | sh

# 或任意包管理器

配置

Windows/PWSH 🪟

打开 ​PROFILE 并添加下列语句

Invoke-Expression (&starship init powershell)

Bash/Zsh 🐚

添加到对应的 .zshrc/.bashrc 或 profile 文件

# zsh
eval "$(starship init zsh)"
# bash
eval "$(starship init bash)"

fish 🐟

向 ~/.config/fish/config.fish 添加以下内容

starship init fish | source

nushell

在您的 Nushell 环境文件的最后(使用 $nu.env-path 来获取它的路径),添加以下内容:

mkdir ~/.cache/starship starship init nu | save -f ~/.cache/starship/init.nu

然后将以下内容添加到您 Nushell 配置文件的末尾(使用 $nu.config-path 来获取它的路径)

use ~/.cache/starship/init.nu

效果

官网效果图

official

对比原来的 omp 主题有点简陋,所以准备做一个主题迁移

omp 定制主题:

omp 定制主题

主题定制

starship 提供了几个 preset,可以通过以下语句设置

starship preset nerd-font-symbols -o ~/.config/starship.toml

访问 https://starship.rs/zh-CN/presets 查看对应效果

推荐 JetBrains Mono Nerd Font

主题自定义

主题文件位置为 .config/starship.toml

不需要自定义主题的可以跳过

prompt 格式设置

format = ...

eg:

​os username 等 为组件,详见下文

format = """
[╭──](fg:#9097AE)\
$os(fg:#9198AF)\
$username\
$sudo\
$hostname\
$directory\
\n[╰── λ](fg:#9097AE) \
$git_branch\
$git_state\
$git_status\
$git_commit\
$nodejs\
$rust\
$python\
$golang\
$php\
$java\
$package\
"""

右侧 prompt

Reply Favorite View the author
All Replies
yanjuner
Super Moderator
2023-09-08 21:26
#1

厉害啊~

知乎是链接发发啊

还能去知乎给你点赞!

Reply View the author