侧边栏壁纸
博主头像
GabrielxD

列車は必ず次の駅へ。では舞台は?私たちは?

  • 累计撰写 675 篇文章
  • 累计创建 128 个标签
  • 累计收到 22 条评论

目 录CONTENT

文章目录

【小技巧】Fish Shell + Starship:定制一个实用好看的终端(附配置)

GabrielxD
2022-08-06 / 0 评论 / 0 点赞 / 658 阅读 / 1,022 字
温馨提示:
本文最后更新于 2022-10-02,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

介绍

Fish Shell

Fish 是一个功能完备的命令行 shell (类似 bash 或 zsh),它是智能的且用户友好的。Fish 支持强大的功能,如语法高亮自动提示选项卡补全,这些功能都可以直接使用,不需要学习或配置。

如果你想让你的命令行更有效率、更有用、更有趣,而不需要学习一堆神秘的语法和配置选项,那么 Fish 可能正是你正在寻找的东西。(以上翻译自官网介绍

Starship

使用 iTerm 和 Snazz 主题的 Starship

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

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

(以上摘自官网介绍

展示

image-20220806233524018

终端应用:Tabby

环境

可用环境

  • Fish Shell:Linux, macOS
  • Starship:
    • 系统:Android, BSD, Linux, macOS, Windows
    • 终端:Bash, CMD, Elvish, Fish, Lon, Nushell, PowerShell, Tcsh, Xonsh, Zsh

演示环境

  • 系统:Windows 10 21H2 - WSL 1 - Ubuntu 20.04.4 LTS
  • Fish Shell:fish, version 3.1.0
  • Starship:starship 1.9.1
  • 终端应用:Tabby α 1.0.183

安装

Final Shell

安装:

sudo apt install fish -y

使用:

fish

退出:

exit

Starship

安装:

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

设置终端初始化 Starship

~/.config/fish/config.fish 的最后,添加以下内容(若没有文件/文件夹则新建):

starship init fish | source

官网安装指南

配置

Final Shell

先拷贝一份 Fish 的默认配置文件到用户目录:

cp -r /usr/share/fish/config.fish ~/.config/fish

修改配置文件:

vim ~/.config/fish/config.fish

在末尾添加以下配置以移除默认欢迎信息:

set -g -x fish_greeting ''

设置 Fish Shell 为默认 shell:

chsh -s /usr/bin/fish

重新登录即可默认使用 Fish Shell。

如果想重新设置默认为 bash,可以使用下面命令:

chsh -s /usr/bin/bash

Starship

Starship 默认使用 ~/.config/starship.toml 作为配置文件,新建该文件:

mkdir -p ~/.config && touch ~/.config/starship.toml

官方给出的具体配置项解释:配置 | Starship

我自己的配置文件(展示图见上方展示):

# 设置配置范例,开启编辑器的自动补全
"$schema" = 'https://starship.rs/config-schema.json'

# 在命令之间插入空行
add_newline = true
format = """
$username\
$hostname\
$localip\
$shlvl\
$singularity\
$kubernetes\
$directory\
$vcsh\
$git_branch\
$git_commit\
$git_state\
$git_metrics\
$git_status\
$hg_branch\
$docker_context\
$package\
$buf\
$c\
$cmake\
$cobol\
$container\
$daml\
$dart\
$deno\
$dotnet\
$elixir\
$elm\
$erlang\
$golang\
$haskell\
$helm\
$java\
$julia\
$kotlin\
$lua\
$nim\
$nodejs\
$ocaml\
$perl\
$php\
$pulumi\
$purescript\
$python\
$rlang\
$red\
$ruby\
$rust\
$scala\
$swift\
$terraform\
$vlang\
$vagrant\
$zig\
$nix_shell\
$conda\
$spack\
$memory_usage\
$aws\
$gcloud\
$openstack\
$azure\
$env_var\
$crystal\
$custom\
$sudo\
$fill\
$cmd_duration\
$time\
$line_break\
$jobs\
$battery\
$status\
$shell\
$character"""

[username]
show_always = true
format = "[$user]($style)"

[hostname]
ssh_only = false
format = "[@$hostname]($style)"

[directory]
format = "[:$path]($style)[$read_only]($read_only_style) "
read_only = " "

[fill]
symbol = " "

[cmd_duration]
style = "#87875f"
format = "[ $duration]($style) "

[time]
disabled = false
style = "#5f8787"
format = "[ $time]($style) "

[aws]
symbol = "  "

[buf]
symbol = " "

[c]
symbol = " "

[conda]
symbol = " "

[dart]
symbol = " "


[docker_context]
symbol = " "

[elixir]
symbol = " "

[elm]
symbol = " "

[git_branch]
symbol = " "

[golang]
symbol = " "

[haskell]
symbol = " "

[hg_branch]
symbol = " "

[java]
symbol = " "

[julia]
symbol = " "

[memory_usage]
symbol = " "

[nim]
symbol = " "

[nix_shell]
symbol = " "

[nodejs]
symbol = " "

[package]
symbol = " "

[python]
symbol = " "

[spack]
symbol = "🅢 "

[rust]
symbol = " "

字体推荐:Caskaydia Cove Nerd Font

Nerd Fonts - Iconic font aggregator, glyphs/icons collection, & fonts patcher

参考

0

评论区