美观实用的一款命令终端神器!值得一用
Oh - My - Posh 是一款可深度定制的全平台终端工具,是为满足开发人员对简洁、美观且功能强大的提示符需求而诞生的项目。它是跨平台和跨 Shell 的提示符渲染器,以高定制性和低延迟性受到青睐。
美观实用的一款命令终端神器!值得一用
- 特性
- 跨平台支持:支持 Windows、GNU/Linux(WSL)、macOS 三个系统。
- 多种 Shell 支持:包括 PowerShell、bash、zsh、Fish 等。
- 高可定制性:通过 JSON 配置文件进行详细配置。
- 低延迟:优化了性能,保证提示符的快速渲染。
美观实用的一款命令终端神器!值得一用
Oh - My - Posh 的安装
一、在 Windows 上安装
- 使用 Scoop
- 命令:scoop install oh - my - posh
- 使用 Winget
- 命令:winget install JanDeDobbeleer.OhMyPosh
美观实用的一款命令终端神器!值得一用
在 macOS 和 Linux 上安装
- 使用 Homebrew
- 命令:brew install jandedobbeleer/oh - my - posh/oh - my - posh
- 使用 Curl
- 命令:
- sudo wget https://github.com/JanDeDobbeleer/oh - my - posh/releases/latest/download/posh - linux - amd64 - O /usr/local/bin/oh - my - posh
- sudo chmod +x /usr/local/bin/oh - my - posh
美观实用的一款命令终端神器!值得一用
二、Oh - My - Posh 的配置
- 使用 JSON 文件配置
Oh - My - Posh 使用 JSON 文件进行配置,用户可定义提示符的样式、颜色及显示内容。
- 创建配置文件
- 例如创建一个名为 posh.json 的配置文件:
{ "final_space": true, "segments": [ { "type": "prompt", "style": "powerline", "foreground": "#ffffff", "background": "#4c4c4c" }, { "type": "git", "style": "plain", "foreground": "#ff9800", "properties": { "branch_max_length": 20 } }, { "type": "path", "style": "plain", "foreground": "#bb86fc", "background": "#160c28" }, { "type": "shell", "style": "plain", "foreground": "#76c7c0" } ]}
- 在不同 Shell 中加载配置文件
- PowerShell:在 $PROFILE 文件中添加oh - my - posh init pwsh --config ~/path/to/posh.json | Invoke - Expression。
- Bash:在 ~/.bashrc 文件中添加eval "$(oh - my - posh init bash --config ~/path/to/posh.json)"。
- Zsh:在 ~/.zshrc 文件中添加eval "$(oh - my - posh init zsh --config ~/path/to/posh.json)"。
- Fish:在 ~/.config/fish/config.fish 文件中添加oh - my - posh init fish --config ~/path/to/posh.json | source。
三、示例配置详解
Git Segment
- 功能:用于显示 Git 仓库的信息,如当前分支名称、未提交更改等。
- 示例配置:
美观实用的一款命令终端神器!值得一用
{ "type": "git", "style": "plain", "foreground": "#ff9800", "properties": { "branch_max_length": 20, "display_status": true, "display_stash_count": true }}
Path Segment
- 功能:用于显示当前路径,适合长时间导航文件系统的开发人员。可设置路径显示的样式及颜色。
- 示例配置:
{ "type": "path", "style": "short", "foreground": "#bb86fc", "background": "#160c28", "properties": { "path_max_length": 40, "home_icon": "~" }}
Shell Segment
- 功能:用于显示当前 Shell 的信息,包括用户名称、主机名称等。
- 示例配置:
{ "type": "shell", "style": "powerline", "foreground": "#76c7c0", "background": "#2c3e50", "properties": { "user_format": " $user", "host_format": " $hostname" }}
完整配置示例
{ "final_space": true, "segments": [ { "type": "prompt", "style": "powerline", "foreground": "#ffffff", "background": "#4c4c4c" }, { "type": "git", "style": "plain", "foreground": "#ff9800", "properties": { "branch_max_length": 20, "display_status": true, "display_stash_count": true } }, { "type": "path", "style": "short", "foreground": "#bb86fc", "background": "#160c28", "properties": { "path_max_length": 40, "home_icon": "~" } }, { "type": "shell", "style": "powerline", "foreground": "#76c7c0", "background": "#2c3e50", "properties": { "user_format": " $user", "host_format": " $hostname" } }, { "type": "time", "style": "plain", "foreground": "#d3d3d3", "background": "#444444", "properties": { "time_format": "15:04:05" } } ]}
Oh - My - Posh 可以在不同操作系统配置安装以及自定义途径。它丰富的配置选项和简洁的提示符样式能极大提升命令行工具的使用体验,在各个主流操作系统和多种 Shell 环境中都能为用户打造高度定制化的高效提示符。
上篇介绍的神器,需要的可以体验
|