Skip to content

尝试更换命令行工具

早上看到一个好看的命令行界面,心生羡慕,于是准备换一下自己的命令行工具。

看了半天选择了zsh + oh-my-zsh | github

2024.3.6 更新了 Linux 下的体验

环境:windows 11 / Ubuntu22

安装 zsh

参考资料:

安装 oh-my-zsh

参考资料:oh-my-zsh 官网

bash
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

插件安装

zsh-syntax-highlighting | 语法高亮

zsh-syntax-highlighting | github

zsh-autosuggestion | 自动补全

Ubuntu 安装:

bash
git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions

~/.zshrc文件中加入:

source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

oh my Zsh 非常值得推荐的插件(自动补全,高亮,快捷跳转) | 知乎

zsh-autosuggestions | github

遇到的问题

zsh 没有加载.bashrc

.bashrc 中的配置复制到 .zshrc 中即可

中文乱码

https://github.com/hokein/Wiki/wiki/zsh中文乱码解决方法

zsh 默认不显示用户名,自定义修改

oh-my-zsh 提示符显示当前用户名和主机名 | 知乎

自用配置

PROMPT="%(?:%{$fg_bold[green]%}%1{➜%} :%{$fg_bold[red]%}%1{➜%} ) %{$fg[green]%}%n:%{$fg[cyan]%}%c%{$reset_color%}"
PROMPT+=' $(git_prompt_info)'

# Always export the NODE_NAME environment variable with the hostname.
export NODE_NAME=$(hostname)

# Define the primary prompt with the arrow symbol and current path
# PROMPT="%{$fg[magenta]%}%1{?%} %{$fg[cyan]%}%~ "

# Add the node name and username to the prompt with proper formatting.
# If you want the username to change dynamically depending on the user who is logged in, use '%n'.

# Adjust the color formatting as per your preference.
# PROMPT+="%{$fg[green]%}[%n@%{$fg_no_bold[blue]%}$NODE_NAME%{$fg[green]%}] "
# PROMPT+="%{$fg[green]%}[%n] "

# Add the final prompt symbol
# PROMPT+="%{$fg_bold[green]%}%B\$%b%{$reset_color%} "

ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}%1{✗%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"

其他参考资料

Copyright © 2022 田园幻想乡 浙ICP备2021038778号-1