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)'
相关推荐
yzkkdhh37 分钟前
【Windows 同时安装 MySQL5 和 MySQL8 - 详细图文教程】
windows·mysql·idea
奇点 ♡1 小时前
【线程】线程的控制
linux·运维·c语言·开发语言·c++·visual studio code
学习3人组2 小时前
CentOS安装Hadoop系列
linux·hadoop·centos
Length-vision2 小时前
Linux入门学习:Linux调试器gdb使用
linux·学习
技术不支持2 小时前
WSL2+Ubuntu 22.04搭建Qt开发环境+中文输入法
linux·运维·服务器·qt·ubuntu
木人舟2 小时前
以root用户登陆ubuntu的桌面环境
linux·运维·ubuntu
几度热忱2 小时前
【Ubuntu】Ubuntu双网卡配置 实现内外网互不影响同时可用
linux·运维·ubuntu
打工人0072 小时前
ubuntu 执行定时任务crontab -e 无法输入的问题
linux·运维·ubuntu
IOT.FIVE.NO.12 小时前
ubuntu个人实用配置问题
linux·运维·ubuntu
_infinite_2 小时前
Ubuntu 与Uboot网络共享资源
linux·服务器·ubuntu