简介
Starship是一款轻量、迅速、可无限定制的高颜值终端!
兼容性优先
Starship 可以在各种常见的操作系统和常见的 shell 上运行。
使用 Rust 编写
具有 Rust 独树一帜的速度与安全性,使你的提示符尽可能的快速可靠。
可自定义
每个小细节都可以按您喜欢的自定义,不论是最小化以求速度,还是最大化以获得最完善的功能。
安装
1.安装 starship 二进制文件:
安装最新版本
使用 Shell 命令:
curl -sS https://starship.rs/install.sh | sh
自更新 Starship ,运行下面脚本 将会在不改动 Starship 配置文件的情况下升级版本
实际运行
[root@localhost ~]# curl -sS https://starship.rs/install.sh | shConfiguration
> Bin directory: /usr/local/bin
> Platform: unknown-linux-musl
> Arch: x86_64> Tarball URL: https://github.com/starship/starship/releases/latest/download/starship-x86_64-unknown-linux-musl.tar.gz
? Install Starship latest to /usr/local/bin? [y/N] y
> Installing Starship, please wait…
✓ Starship installed> Please follow the steps for your shell to complete the installation:bashAdd the following to the end of ~/.bashrc:eval "$(starship init bash)"zshAdd the following to the end of ~/.zshrc:eval "$(starship init zsh)"ionAdd the following to the end of ~/.config/ion/initrc:eval $(starship init ion)tcshAdd the following to the end of ~/.tcshrc:eval `starship init tcsh`xonshAdd the following to the end of ~/.xonshrc:execx($(starship init xonsh))fishAdd the following to the end of ~/.config/fish/config.fish:starship init fish | sourceelvishWarning Only elvish v0.17 or higher is supported.And add the following to the end of ~/.elvish/rc.elv:eval (starship init elvish)nushellWarning This will change in the future.Only Nushell v0.61 or higher is supported.Add the following to the end of your Nushell env file (find it by running $nu.env-path in Nushell): "mkdir ~/.cache/starship; starship init nu | save ~/.cache/starship/init.nu"And add the following to the end of your nu config file (find it by running $nu.config-path in Nushell):mkdir ~/.cache/starshipstarship init nu | save ~/.cache/starship/init.nusource ~/.cache/starship/init.nuPowerShellAdd the following to the end of Microsoft.PowerShell_profile.ps1:You can check the location of this file by querying the $PROFILE variable in PowerShell.Typically the path is ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 or ~/.config/powershell/Microsoft.PowerShell_profile.ps1 on -Nix.Invoke-Expression (&starship init powershell)CmdYou need to use Clink (v1.2.30+) with Cmd. Add the following to a file starship.lua and place this file in Clink scripts directory:load(io.popen('starship init cmd'):read("*a"))()[root@localhost ~]#
2.将初始化脚本添加到您的 shell 的配置文件:
Bash
在 ~/.bashhrc
的最后,添加以下内容:
# ~/.bashrceval "$(starship init bash)"
实际操作
vim ~/.bashrc
# .bashrc# User specific aliases and functionsalias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'# Source global definitions
if [ -f /etc/bashrc ]; then. /etc/bashrc
fieval "$(starship init bash)"
~
配置
https://starship.rs/zh-CN/config/#username
您需要创建配置文件 ~/.config/starship.toml
以供 Starship 使用。
mkdir -p ~/.config && touch ~/.config/starship.toml
Starship 的所有配置都在此 TOML 配置文件中完成:
# 设置配置范例,开启编辑器的自动补全
"$schema" = 'https://starship.rs/config-schema.json'# 在命令之间插入空行
add_newline = true# 将提示符的“❯”替换为“➜”
[character] # “character”是我们正在配置的组件
success_symbol = "[➜](bold green)" # 设置“success_symbol” 字段为绿色加粗的“➜”# 禁用 package 组件,完全隐藏它的提示符
[package]
disabled = true
您可以使用 STARSHIP_CONFIG
环境变量更改默认配置文件的位置:
export STARSHIP_CONFIG=~/example/non/default/path/starship.toml
其他模式:
# Use custom format
format = """
[┌───────────────────>](bold green)
[│](bold green)$directory$rust$package
[└─>](bold green) """# Wait 10 milliseconds for starship to check files under the current directory.
scan_timeout = 10# Disable the blank line at the start of the prompt
add_newline = false
效果
┌───────────────────> localhost in root in
│/var/www/html
└─>
日志
默认情况下,Starship 会将警告和错误日志记录到文件 ~/.cache/starship/session_${STARSHIP_SESSION_KEY}.log
. 其中 session key 与您的终端实例相对应。 不过,这也可以使用 STARSHIP_CACHE
环境变量来修改:
export STARSHIP_CACHE=~/.starship/cache
安装字体nerd-fonts
https://www.nerdfonts.com/
https://github.com/ryanoasis/nerd-fonts/
在里面选择一个自己喜欢的字体,我选择下载了JetBrainsMono.zip 字体。
编写脚本安装字体
vim install.sh
# array中换成你要安装的字体的zip压缩包的名称
array=(JetBrainsMono DroidSansMono DejaVuSansMono UbuntuMono CodeNewRoman BitstreamVeraSansMono)
current_dir=`pwd`
for font in ${array[@]}
dosudo unzip ${font} -d /usr/share/fonts/${font}cd /usr/share/fonts/${font}sudo mkfontscale # 生成核心字体信息sudo mkfontdir # 生成字体文件夹sudo fc-cache -fv # 刷新系统字体缓存cd ${current_dir}
done
安装 fish
说明
Fish Shell是一个非常优秀的终端 Shell 工具,拥有许多开箱即用的功能,例如语法自动推荐补全、语法高亮显示或使用快捷键在最近访问的文件夹之间来回切换。
https://fishshell.com/
https://fishshell.com/docs/current/index.html#syntax-overview
yum install fish -y
实际安装
yum install fish
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 7.9 kB 00:00:00 * base: mirrors.ustc.edu.cn* epel: mirrors.bfsu.edu.cn* extras: mirrors.ustc.edu.cn* updates: mirrors.ustc.edu.cn
atomic | 3.0 kB 00:00:00
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
webtatic | 3.6 kB 00:00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 fish.x86_64.0.2.3.1-2.el7 将被 安装
--> 解决依赖关系完成依赖关系解决=====================================================================================================Package 架构 版本 源 大小
============================================================================================================
正在安装:fish x86_64 2.3.1-2.el7 epel 1.5 M事务概要
=============================================================================================
安装 1 软件包总下载量:1.5 M
安装大小:7.4 M
Is this ok [y/d/N]: y
Downloading packages:
fish-2.3.1-2.el7.x86_64.rpm | 1.5 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装 : fish-2.3.1-2.el7.x86_64 1/1 验证中 : fish-2.3.1-2.el7.x86_64 1/1 已安装:fish.x86_64 0:2.3.1-2.el7 完毕!
启动fish
fish