Starship：跨 shell 的可定制的提示符
提示符
![](/data/attachment/album/202102/25/142817taqq2ahab0t61zss.jpg)



> 
> 如果你很在意你的终端的外观的话，一个跨 shell 的提示符可以让你轻松地定制和配置 Linux 终端提示符。
> 
> 
> 


虽然我已经介绍了一些帮助你 [自定义终端外观](https://itsfoss.com/customize-linux-terminal/) 的技巧，但我也发现了一些有趣的跨 shell 提示符的建议。


### Starship：轻松地调整你的 Linux Shell 提示符


![](/data/attachment/album/202102/25/142443pgvilqoevx0tbp30.png)


[Starship](https://starship.rs/) 是一个用 [Rust](https://www.rust-lang.org/) 编写的开源项目，它可以帮助你建立一个精简、快速、可定制的 shell 提示符。


无论你是使用 bash、fish、还是 Windows 上的 PowerShell，抑或其他 shell，你都可以利用Starship 来定制外观。


请注意，你必须了解它的 [官方文档](https://starship.rs/config/) 才能对所有你喜欢的东西进行高级配置，但在这里，我将包括一个简单的示例配置，以有一个良好的开端，以及一些关于 Startship 的关键信息。


Startship 专注于为你提供一个精简的、快速的、有用的默认 shell 提示符。它甚至会记录并显示执行一个命令所需的时间。例如，这里有一张截图：


![](/data/attachment/album/202102/25/142445g0wcwvvzbnnn31uq.jpg)


不仅如此，根据自己的喜好定制提示符也相当简单。下面是一张官方 GIF，展示了它的操作：


![](/data/attachment/album/202102/25/142504h6rhx7oz4hqq7htq.gif)


让我帮你设置一下。我是在 Ubuntu 上使用 bash shell 来测试的。你可以参考我提到的步骤，或者你可以看看 [官方安装说明](https://starship.rs/guide/#%F0%9F%9A%80-installation)，以获得在你的系统上安装它的更多选择。


### Starship 的亮点


* 跨平台
* 跨 shell 支持
* 能够添加自定义命令
* 定制 git 体验
* 定制使用特定编程语言时的体验
* 轻松定制提示符的每一个方面，而不会对性能造成实质影响


### 在 Linux 上安装 Starship



> 
> 安装 Starship 需要下载一个 bash 脚本，然后用 root 权限运行该脚本。
> 
> 
> 如果你不习惯这样做，你可以使用 snap。
> 
> 
> 
> ```
> sudo snap install starship
> 
> ```
> 
> 


**注意**：你需要安装 [Nerd 字体](https://www.nerdfonts.com) 才能获得完整的体验。


要开始使用，请确保你安装了 [curl](https://curl.se/)。你可以通过键入如下命令来轻松安装它：



```
sudo apt install curl

```

完成后，输入以下内容安装 Starship：



```
curl -fsSL https://starship.rs/install.sh | bash

```

这应该会以 root 身份将 Starship 安装到 `usr/local/bin`。你可能会被提示输入密码。看起来如下：


![](/data/attachment/album/202102/25/142505ltyk3daqktk33fti.png)


### 在 bash 中添加 Starship


如截图所示，你会在终端本身得到设置的指令。在这里，我们需要在 `.bashrc` 用户文件的末尾添加以下一行：



```
eval "$(starship init bash)"

```

要想轻松添加，只需键入：



```
nano .bashrc

```

然后，通过向下滚动导航到文件的末尾，并在文件末尾添加如下图所示的行：


![](/data/attachment/album/202102/25/142506g3qgufqfwq9c3qzc.png)


完成后，只需重启终端或重启会话即可看到一个精简的提示符。对于你的 shell 来说，它可能看起来有点不同，但默认情况下应该是一样的。


![](/data/attachment/album/202102/25/142506gvnl8nvuwpln6vsw.png)


设置好后，你就可以继续自定义和配置提示符了。让我给你看一个我做的配置示例：


### 配置 Starship 提示符：基础


开始你只需要在 `.config` 目录下制作一个配置文件（[TOML文件](https://en.wikipedia.org/wiki/TOML)）。如果你已经有了这个目录，直接导航到该目录并创建配置文件。


下面是创建目录和配置文件时需要输入的内容：



```
mkdir -p ~/.config && touch ~/.config/starship.toml

```

请注意，这是一个隐藏目录。所以，当你试图使用文件管理器从主目录访问它时，请确保在继续之前 [启用查看隐藏文件](https://itsfoss.com/hide-folders-and-show-hidden-files-in-ubuntu-beginner-trick/)。


接下来如果你想探索一些你喜欢的东西，你应该参考配置文档。


举个例子，我配置了一个简单的自定义提示，看起来像这样：


![](/data/attachment/album/202102/25/142507cthitqfp1xfw1o35.png)


为了实现这个目标，我的配置文件是这样的：


![](/data/attachment/album/202102/25/142507tu7j1yzavteebyxk.png)


根据他们的官方文档，这是一个基本的自定义格式。但是，如果你不想要自定义格式，只是想用一种颜色或不同的符号来自定义默认的提示，那就会像这样：


![](/data/attachment/album/202102/25/142507empgqa4v4gm0rzia.png)


上述定制的配置文件是这样的：


![](/data/attachment/album/202102/25/142508en9aala1ndrcnn4a.jpg)


当然，这不是我能做出的最好看的提示符，但我希望你能理解其配置方式。


你可以通过包括图标或表情符来定制目录的外观，你可以调整变量、格式化字符串、显示 git 提交，或者根据使用特定编程语言而调整。


不仅如此，你还可以创建在你的 shell 中使用的自定义命令，让事情变得更简单或舒适。


你可以在他们的 [官方网站](https://starship.rs/) 和它的 [GitHub 页面](https://github.com/starship/starship) 中探索更多的信息。


* [Starship.rs](https://starship.rs/)


### 结论


如果你只是想做一些小的调整，这文档可能会太复杂了。但是，即使如此，它也可以让你用很少的努力实现一个自定义的提示符或精简的提示符，你可以应用于任何普通的 shell 和你正在使用的系统。


总的来说，我不认为它非常有用，但有几个读者建议使用它，看来人们确实喜欢它。我很想看看你是如何 [自定义 Linux 终端](https://itsfoss.com/customize-linux-terminal/) 以适应不同的使用方式。


欢迎在下面的评论中分享你的看法，如果你喜欢的话。




---


via: <https://itsfoss.com/starship/>


作者：[Ankush Das](https://itsfoss.com/author/ankush/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[wxy](https://github.com/wxy) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

While I’ve already covered a few tips to help you [customize the looks of your terminal](https://itsfoss.com/customize-linux-terminal/), I also came across suggestions for an interesting cross-shell prompt.

## Starship: Tweak your Linux Shell Prompt Easily

![starship screenshot](https://itsfoss.com/content/images/wordpress/2021/02/starship-screenshot.png)

[Starship](https://starship.rs/) is an open-source project that’s written in [Rust](https://www.rust-lang.org/) to help you set up a minimal, fast, and customizable shell prompt.

No matter whether you’re using bash, fish, PowerShell on Windows or any other shell, you can utilize Starship to customize the appearance.

Do note that you do have to go through its [official documentation](https://starship.rs/config/) to be able to perform advanced configuration for everything you like but here I will include a simple sample configuration to get a head start along with some key information about Startship.

Starship focuses on giving you a minimal, fast, and useful shell prompt by default. It even records and shows the time taken to perform a command as well. For instance, here’s a screenshot:

![starship time](https://itsfoss.com/content/images/wordpress/2021/02/starship-time.jpg)

Not just limited to that, it is also fairly easy to customize the prompt to your liking. Here’s an official GIF that shows it in action:

![starship demo](https://itsfoss.com/content/images/wordpress/2021/02/starship-demo-800x501.gif)

Let me help you set it up. I am using bash shell on Ubuntu to test this out. You can refer to the steps I mention, or you can take a look at the [official installation instructions](https://starship.rs/guide/#%F0%9F%9A%80-installation) for more options to install it on your system.

## Key Highlights of Starship

- Cross-platform
- Cross-shell support
- Ability to add custom commands
- Customize git experience
- Customize the experience while using specific programming languages
- Easily customize every aspect of the prompt without taking a hit on performance in a meaningful way

## Installing Starship on Linux

`sudo snap install starship`

To get started, ensure that you have [curl](https://curl.se/) installed. You can install it easily by typing in:

`sudo apt install curl`


Once you do that, type in the following to install Starship:

`curl -fsSL https://starship.rs/install.sh | bash`


This should install Starship to **usr/local/bin** as root. You might be prompted for the password. Here’s how it would look:

![install starship](https://itsfoss.com/content/images/wordpress/2021/02/install-starship.png)


*You need to have*[Nerd Font](https://www.nerdfonts.com/)installed to get the complete experience.## Add startship to bash

As the screenshot suggests, you will get the instruction to set it up in the terminal itself. But, in this case, we need to add the following line at the end of our **bashrc **user file:

`eval "$(starship init bash)"`


To add it easily, simply type in:

`nano .bashrc`


Now, navigate to the end of the file by scrolling down and add the line at the end of the file as shown in the image below:

![startship bashrc file](https://itsfoss.com/content/images/wordpress/2021/02/startship-bashrc-file.png)

Once done, simply restart the terminal or restart your session to see the minimal prompt. It might look a bit different for your shell, but more or less it should be the same by default.

![starship prompt](https://itsfoss.com/content/images/wordpress/2021/02/starship-prompt.png)

Once you set it up, you can proceed customizing and configuring the prompt. Let me show you an example configuration that I did.

## Configure Starship Shell Prompt: The Basics

To get started, you just need to make a configuration file ([TOML file](https://en.wikipedia.org/wiki/TOML)) inside a .config directory. If you already have one, you should simply navigate to the directory and just create the configuration file.

Here’s what you have to type to create the directory and the config file:

`mkdir -p ~/.config && touch ~/.config/starship.toml`


Do note that this is a hidden directory. So, when you try to access it from your home directory using the file manager, make sure to [enable viewing hidden files](https://itsfoss.com/hide-folders-and-show-hidden-files-in-ubuntu-beginner-trick/) before proceeding.

From this point onwards, you should refer to the configuration documentation if you want to explore something you like.

For example, I configured a simple custom prompt that looks like:

![starship custom](https://itsfoss.com/content/images/wordpress/2021/02/starship-custom.png)

To achieve this, my configuration file looks like this:

![starship custom config](https://itsfoss.com/content/images/wordpress/2021/02/starship-custom-config.png)

It is a basic custom format as per their official documentation. But, if you do not want a custom format and simply want to customize the default prompt with a color or a different symbol, that would look like:

![starship different symbol](https://itsfoss.com/content/images/wordpress/2021/02/starship-different-symbol.png)

And, the configuration file for the above customization looks like:

![starship symbol change](https://itsfoss.com/content/images/wordpress/2021/02/starship-symbol-change.jpg)

Of course, that’s not the best-looking prompt one can make but I hope you get the idea.

You can customize how the directory looks by including icons/emojis, you can tweak the variables, format strings git commits, or while using specific programming languages.

Not just limited to that, you can also create custom commands to use in your shell to make things easier or more comfortable for yourself.

You should explore more about on their [official website](https://starship.rs/) and its [GitHub page](https://github.com/starship/starship).

## Concluding Thoughts

If you just want minor tweaks, the documentation might be too overwhelming. But, even then, it lets you achieve a custom or minimal prompt with little effort that you can apply on any common shell and any system you’re working on.

Perosnally, I don’t think it’s very useful but several readers suggested it and it seems people do love it. I am eager to see how you [customize the Linux terminal](https://itsfoss.com/customize-linux-terminal/) for different kinds of usage.

Feel free to share what you think about it and if you like it, in the comments down below.