服务器无魔法时手动下载安装Shell美化插件Starship

服务器无魔法时手动下载安装Shell美化插件Starship

Simuoss
2024-08-10 / 0 评论 / 45 阅读 / 正在检测是否收录...

前言

Starship自述:最小化、极速且无限可定制的终端提示符,适用于任何Shell!

  • 兼容性优先
    在最常见的操作系统上的最常见Shell中均可使用。随处可用!
  • Rust驱动
    利用Rust的顶级速度和安全性,使您的提示符尽可能快速和可靠。
  • 可定制
    每一个细节都可以根据您的喜好进行定制,使这个提示符可以是最简约的,也可以是功能丰富的,完全由您决定。

Starship

但是有时当我们想要安装时,会发现一个问题:通常我们的远端服务器并不能访问到Starship官网给出的https://starship.rs/install.sh,因为服务器上没有魔法。那我们能不能在有魔法的设备上下载好文件之后,手动安装呢?
当然可以!


从Github下载文件

打开 Starship的Github仓库 在里面找到合适你系统版本的预编译文件。

如果你不清楚要选哪个,那么对于大多数X86的Linux,starship-x86_64-unknown-linux-gnu.tar.gz更合适。

上传至服务器并安装Starship

下载好之后,通过(s)ftp协议将文件传到远端服务器。推荐使用自带ftp协议的ssh终端,如 MobaXterm

如果你使用 MobaXterm ,那么将文件拖入这里即可传输至远端服务器。

随后,执行以下两条指令来安装Starship
解压文件:

tar xvf starship-x86_64-unknown-linux-gnu.tar.gz

将 starship 可执行文件复制到 /usr/local/bin 目录:

sudo mv starship /usr/local/bin/

至此,就已完成安装。随后按照 官方文档 里面的第二步及随后步骤继续配置即可。

如果Shell的样式没有变化,请重新发起SSH连接以重载Shell。

附:设置开机启动以及自定义样式

注意,以下内容都是官方文档里面的,如果你在官方文档中进行了后续步骤,就不必理会本文的后续内容了

设为开机启动(基于默认的Bash)

打开bash配置文件

vi ~/.bashrc

将光标移动到最底部,另起一行,粘贴以下内容并保存文件:

eval "$(starship init bash)"

自定义样式

创建Starship配置文件目录并编辑配置文件

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

目前博主自用的配置文件如下,可以直接粘贴进去,或者配置自己的样式:

format = """
[](#9A348E)\
$os\
$username\
[](bg:#DA627D fg:#9A348E)\
$directory\
[](fg:#DA627D bg:#FCA17D)\
$git_branch\
$git_status\
[](fg:#FCA17D bg:#86BBD8)\
$c\
$conda\
$elixir\
$elm\
$golang\
$gradle\
$haskell\
$java\
$julia\
$nodejs\
$nim\
$rust\
$scala\
[](fg:#86BBD8 bg:#06969A)\
$docker_context\
[](fg:#06969A bg:#33658A)\
$time\
[ ](fg:#33658A)\
\n$character"""

# Disable the blank line at the start of the prompt
# add_newline = false

# 将提示符中的 '❯' 替换为 '➜'
[character] # 此组件名称为 'character'
success_symbol = '[➜](bold green)' # 将 'success_symbol' 字段设置成颜色为 'bold green' 的 '➜' 


[status]
style = 'bg:blue'
symbol = '🔴 '
success_symbol = '🟢 SUCCESS'
format = '[\[$symbol$common_meaning$signal_name$maybe_int\]]($style) '
map_symbol = true
disabled = false 


# You can also replace your username with a neat symbol like   or disable this
# and use the os module below
[username]
show_always = true
style_user = "bg:#9A348E"
style_root = "bg:#9A348E"
format = '[$user ]($style)'
disabled = false

# An alternative to the username module which displays a symbol that
# represents the current operating system
[os]
style = "bg:#9A348E"
disabled = true # Disabled by default

[directory]
style = "bg:#DA627D"
format = "[ $path ]($style)"
truncation_length = 3
truncation_symbol = "…/"

# Here is how you can shorten some long paths by text replacement
# similar to mapped_locations in Oh My Posh:
[directory.substitutions]
"Documents" = "󰈙 "
"Downloads" = " "
"Music" = " "
"Pictures" = " "
# Keep in mind that the order matters. For example:
# "Important Documents" = " 󰈙 "
# will not be replaced, because "Documents" was already substituted before.
# So either put "Important Documents" before "Documents" or use the substituted version:
# "Important 󰈙 " = " 󰈙 "

[c]
symbol = " "
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[conda]
format = '[$symbol$environment](dimmed green) '

[docker_context]
symbol = " "
style = "bg:#06969A"
format = '[ $symbol $context ]($style)'

[elixir]
symbol = " "
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[elm]
symbol = " "
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[git_branch]
symbol = ""
style = "bg:#FCA17D"
format = '[ $symbol $branch ]($style)'

[git_status]
style = "bg:#FCA17D"
format = '[$all_status$ahead_behind ]($style)'

[golang]
symbol = " "
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[gradle]
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[haskell]
symbol = " "
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[java]
symbol = " "
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[julia]
symbol = " "
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[nodejs]
symbol = ""
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[nim]
symbol = "󰆥 "
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[rust]
symbol = ""
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[scala]
symbol = " "
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[time]
disabled = false
time_format = "%R" # Hour:Minute Format
style = "bg:#33658A"
format = '[ ♥ $time ]($style)'

效果如下:

更详细的配置方法可以参见:Starship 配置⸺在终端上显示 Git 状态、Python 虚拟环境、命令运行时间等

参考链接:
Starship 官方教程
如何在 Linux 中安装 Fish Shell(带 Starship)

3

评论 (0)

取消