windows下powershell与linux下bash美化教程(使用starship)

starship美化教程

Win11 + Powershell

安装

在命令行使用下面命令安装

cmd 复制代码
# 安装starship
winget install starship

将以下内容添加到 Microsoft.PowerShell_profile.ps1,可以在 PowerShell 通过 $PROFILE 变量来查询文件的位置

复制代码
Invoke-Expression (&starship init powershell)

配置

C:\用户\{user}\.config目录下新建starship.toml文件,可以在starship官网查看官方预设配置,点击主题即可查看配置文件代码,复制到toml配置文件中即可。

需要注意的是,基本上所有的主题都包含了Nerd Font字体中的一些符号支持,因此当符号显示异常的话,先检查是否安装了最新版的Nerd Font字体族。

在排除字体问题后,某些符号显示异常很可能是使用了过时的符号编码,具体可见oh-my-posh美化教程中的Nerd Font部分。

启动终端后第一行空白

因为默认配置中add_newline = true,意味着每次执行完命令会空出一行,防止命令与输出结果之间缺少空行而降低可读性。根据个人喜好,可以将其设置为false以去除终端最上方的空行。

Linux(无root权限) + bash

安装Nerd Font

在linux终端中,可以使用fc-list查看已安装的字体。

若linux上没有可用的Nerd Font字体,而你又恰好没有root权限,则可以在本地主机上下载字体包(.ttf文件即可)后上传至~/.local/share/fonts目录下,若没有此路径,新建即可。

需要注意的是,在上传Nerd Font字体文件时,最好把某个字体的所有格式文件均上传,如light、bold、italic等多个文件。

然后在linux上执行以下命令来刷新字体缓存,检测字体是否可用。

bash 复制代码
fc-cache -vf
fc-list | grep "JetBrainsMonoNLNerdFontMono"

安装starship

starship的github官网上下载最新的starship压缩包,上传到linux用户目录下,解压即可得到starship的可执行文件,将该目录添加到环境变量中,再在~/.bashrc文件的最后添加一行命令即可。

bash 复制代码
# 将starship所在路径添加到环境变量
export PATH=/home/{user}/{starship所在目录}:$PATH
# 使用starship初始化bash
eval "$(starship init bash)"

配置

~/.config路径下新建starship.toml配置文件即可。

我的配置

基于Tokyo Night主题修改,增加了对conda环境的显示支持与命令执行时长的显示支持。

大部分符号均需要在NerdFont下查看。

toml 复制代码
add_newline = true

format = """
[░▒▓](#a3aed2)\
[  ](fg:#090c0c bg:#a3aed2)\
[](fg:#a3aed2 bg:#769ff0)\
$directory\
[](fg:#769ff0 bg:#596db0)\
$git_branch\
$git_status\
[](fg:#596db0 bg:#394260)\
$conda\
$nodejs\
$rust\
$golang\
$php\
[](fg:#394260 bg:#212736)\
$time\
[ ](fg:#212736 bg:#1d2230)\
$cmd_duration\
[](fg:#1d2230)\
\n$character"""

[directory]
style = "fg:#e3e5e5 bg:#769ff0"
format = "[ $path ]($style)"
truncation_length = 7
truncation_symbol = ".../"

[directory.substitutions]
"Documents" = "󰈙 "
"Downloads" = " "
"Music" = " "
"Pictures" = " "

[git_branch]
symbol = ""
style = "bg:#394260"
format = '[[ $symbol $branch ](fg:#769ff0 bg:#596db0)]($style)'

[git_status]
style = "bg:#394260"
format = '[[($all_status$ahead_behind )](fg:#769ff0 bg:#596db0)]($style)'

[conda]
symbol = " "
style = "bg:#394260"
format = '[[ $symbol ($environment) ](fg:#769ff0 bg:#394260)]($style)'

[nodejs]
symbol = ""
style = "bg:#394260"
format = '[[ $symbol ($version) ](fg:#769ff0 bg:#394260)]($style)'

[rust]
symbol = ""
style = "bg:#394260"
format = '[[ $symbol ($version) ](fg:#769ff0 bg:#394260)]($style)'

[golang]
symbol = ""
style = "bg:#394260"
format = '[[ $symbol ($version) ](fg:#769ff0 bg:#394260)]($style)'

[php]
symbol = ""
style = "bg:#394260"
format = '[[ $symbol ($version) ](fg:#769ff0 bg:#394260)]($style)'

[time]
disabled = false
time_format = "%R" # Hour:Minute Format
style = "bg:#212736"
format = '[[  $time ](fg:#a0a9cb bg:#212736)]($style)'

[cmd_duration]
disabled = false
min_time = 500
show_milliseconds = true
style = "bg:#1d2230"
format = '[[ 󰔟 $duration ](fg:#a0a9cb bg:#1d2230)]($style)'
相关推荐
Dying.Light16 分钟前
Linux部署问题
linux·运维·服务器
S190118 分钟前
Linux的常用指令
linux·运维·服务器
小义_39 分钟前
【RH134知识点问答题】第7章 管理基本存储
linux·运维·服务器
小天源1 小时前
Error 1053 Error 1067 服务“启动后立即停止” Java / Python 程序无法后台运行 windows nssm注册器下载与报错处理
开发语言·windows·python·nssm·error 1053·error 1067
梁洪飞1 小时前
内核的schedule和SMP多核处理器启动协议
linux·arm开发·嵌入式硬件·arm
_运维那些事儿2 小时前
VM环境的CI/CD
linux·运维·网络·阿里云·ci/cd·docker·云计算
Y1rong2 小时前
linux之文件IO
linux
Trouvaille ~3 小时前
【Linux】UDP Socket编程实战(一):Echo Server从零到一
linux·运维·服务器·网络·c++·websocket·udp
十五年专注C++开发3 小时前
MinHook:Windows 平台下轻量级、高性能的钩子库
c++·windows·钩子技术·minhook
嵌入小生0073 小时前
Shell | 命令、编程及Linux操作系统的基本概念
linux·运维·服务器