Ubuntu终端美化zsh/fish+starship
zsh
zsh介绍
zsh 是一个兼容 bash 的 shell,相较 bash 具有以下优点:
· Tab 补全功能强大。命令、命令参数、文件路径均可以补全。
· 插件丰富。快速输入以前使用过的命令、快速跳转文件夹、显示系统负载这些都可以通过插件实现。
· 主题丰富。
· 可定制性高。
关于 zsh 的更多的信息,可以访问 zsh.org 查看。
zsh安装与使用
安装zsh
ubuntu:
sudo apt install zsh -y
设置为默认shell
- 查看系统所有的 shell:
cat /etc/shells
- 设置为系统默认 shell
chsh -s /bin/zsh
- 进入zsh
在当前终端中输入zsh
即可进入zsh shell。
zsh
第一次运行 zsh 时会进入如下的配置引导页面:
- 输入
q
会直接退出配置引导,下一次运行 zsh 时会再次进入配置引导。 - 输入
0
,也会退出配置引导,但是会在当前用户目录生成一个空白的文件 .zshrc,下一次运行时就不会再进入配置引导。下一次运行时是否再进入配置引导,取决于用户目录下是否存在.zshrc 文件。 - 输入
1
后,就开始进行配置。
建议使用 oh-my-zsh 或 starship 来修改 zsh 的主题和安装常用的插件。
fish
ubuntu:
sudo apt install fish -y
设置为默认shell
- 查看系统所有的 shell:
cat /etc/shells
- 设置为系统默认 shell
chsh -s /usr/bin/fish
- 进入fish
在当前终端中输入fish
即可进入zsh shell。
fish
更多参考Fish Shell 安装配置指南。
starship
安装
- 国外:
curl -sS https://starship.rs/install.sh | sh
- 国内
curl -o install.sh -sS https://starship.rs/install.sh && sed -i "s/https:\/\/github.com/https:\/\/ghproxy.com\/https:\/\/github.com/g" install.sh && sudo sh install.sh
设置你的终端以使用 Starship
注意普通用户和root
用户需要分别配置。
zsh终端
在 ~/.zshrc
的最后,添加以下内容:
eval "$(starship init zsh)"
启用配置:
source ~/.zshrc
fish终端
在 ~/.config/fish/config.fish
的最后,添加以下内容:
starship init fish | source
配置Starship
打开一个新的 Shell 实例,你应该就能看到漂亮的 Shell 新提示符了。 如果你对默认配置感到满意,就可以开始享用了!
如果你想进一步配置 Starship,查阅下列内容:
普通用户——我的选择
选择Pastel Powerline
配置
starship preset pastel-powerline > ~/.config/starship.toml
root
用户——我的选择
选择纯文本符号
配置
su
starship preset plain-text-symbols > ~/.config/starship.toml
其实我做了一点小改动(改改颜色而已),编辑配置文件
gedit ~/.config/starship.toml
全选删除,粘贴为以下内容:
[character]
success_symbol = "[→](bold yellow)"
error_symbol = "[x](bold red)"
vicmd_symbol = "[←](bold cyan)"
[git_commit]
tag_symbol = " tag "
[git_status]
ahead = ">"
behind = "<"
diverged = "<>"
renamed = "r"
deleted = "x"
[aws]
symbol = "aws "
[bun]
symbol = "bun "
[c]
symbol = "C "
[cobol]
symbol = "cobol "
[conda]
symbol = "conda "
[crystal]
symbol = "cr "
[cmake]
symbol = "cmake "
[daml]
symbol = "daml "
[dart]
symbol = "dart "
[deno]
symbol = "deno "
[dotnet]
symbol = ".NET "
[directory]
read_only = " ro"
[docker_context]
symbol = "docker "
[elixir]
symbol = "exs "
[elm]
symbol = "elm "
[git_branch]
symbol = "git "
[golang]
symbol = "go "
[hg_branch]
symbol = "hg "
[java]
symbol = "java "
[julia]
symbol = "jl "
[kotlin]
symbol = "kt "
[lua]
symbol = "lua "
[nodejs]
symbol = "nodejs "
[memory_usage]
symbol = "memory "
[nim]
symbol = "nim "
[nix_shell]
symbol = "nix "
[ocaml]
symbol = "ml "
[package]
symbol = "pkg "
[perl]
symbol = "pl "
[php]
symbol = "php "
[pulumi]
symbol = "pulumi "
[purescript]
symbol = "purs "
[python]
symbol = "py "
[raku]
symbol = "raku "
[ruby]
symbol = "rb "
[rust]
symbol = "rs "
[scala]
symbol = "scala "
[spack]
symbol = "spack "
[sudo]
symbol = "sudo "
[swift]
symbol = "swift "
[terraform]
symbol = "terraform "
[zig]
symbol = "zig "