# Ubuntu 安装配置 Oh My Zsh 终端美化

## 概述

[Oh-My-Zsh](https://github.com/robbyrussell/oh-my-zsh) 是一个强大的Zsh配置管理框架，能够大幅提升终端使用体验。本文将详细介绍在Ubuntu 18.04 LTS系统上安装和配置Oh-My-Zsh的完整过程。

## 前置依赖安装

安装前确保系统已安装以下必要组件:

### 安装Zsh shell

```bash
sudo apt-get install zsh
```

### 安装Git（用于克隆仓库）

```bash
sudo apt-get install git
```

### 确认curl或wget工具

Ubuntu系统通常默认已安装这些工具，用于下载安装脚本。

## Oh-My-Zsh安装步骤

选择以下任一方式安装:

### 通过curl安装

```bash
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
```

### 通过wget安装

```bash
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
```

安装完成后，退出并重启终端以查看变化。如果未生效，可尝试注销或重启系统。

## 配置主题和插件

### 启用Agnoster主题

[Agnoster](https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/agnoster.zsh-theme)是一个流行的Oh-My-Zsh主题，提供丰富的视觉提示。

1. 编辑配置文件:

```bash
vim ~/.zshrc
```

2. 找到`ZSH_THEME="robbyrussell"`行
3. 将其修改为`ZSH_THEME="agnoster"`
4. 保存并退出
5. 重启终端应用更改

## 解决字体显示问题

Agnoster主题需要特殊字体支持，否则会出现乱码。

### 安装Powerline字体

官方推荐方式:

```bash
sudo apt-get install fonts-powerline
```

如果上述方法不生效，可使用手动安装方式:

```bash
# 克隆字体仓库
git clone https://github.com/powerline/fonts.git --depth=1
# 安装字体
cd fonts
./install.sh
# 清理安装文件
cd ..
rm -rf fonts
```

### 配置终端字体

安装字体后，需在终端设置中选择合适的字体:

1. 打开终端首选项
2. 选择字体为 `Ubuntu Mono derivative Powerline Regular`

![终端字体设置](https://ws1.sinaimg.cn/large/ecb0a9c3gy1ft1om5s8l0j20nr0l676q.jpg)

## 个性化定制

### 移除用户名和主机名显示

如果觉得终端提示符中的`user@hostname`显示过长:

1. 编辑主题文件:

```bash
vim ~/.oh-my-zsh/themes/agnoster.zsh-theme
```

2. 找到`prompt_context`函数并注释该部分

![去除用户名主机名显示](https://ws1.sinaimg.cn/large/ecb0a9c3gy1ft1omfaq3oj20mh09uwf4.jpg)

## 成果展示

完成所有配置后的终端效果图:

![终端最终效果](https://ws1.sinaimg.cn/large/ecb0a9c3gy1ft1ommynlcj21hc0u0q9i.jpg)

## 相关资源

* [Oh-My-Zsh官方仓库](https://github.com/robbyrussell/oh-my-zsh)
* [Powerline字体仓库](https://github.com/powerline/fonts)
* [Agnoster主题](https://github.com/robbyrussell/oh-my-zsh/blob/master/themes/agnoster.zsh-theme)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.ronething.cn/ubuntu-install-oh-my-zsh.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
