Linux $PS1 and custom zsh prompt All In One
Linux $PS1 and custom zsh prompt All In One
macOS
自定义
命令行提示符
$PS1
$ echo $PS1
%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)
# zsh
$ cat .zshrc | grep PS1
# export PS1="\u@\h \W\\$"
# export PS1="\\$"
git
prompt
zsh $PS1
try it out
# default
$ cat ~/.oh-my-zsh/themes/macovsky-ruby.zsh-theme
# ZSH Theme - Preview: https://i.gyazo.com/8becc8a7ed5ab54a0262a470555c3eed.png
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
PROMPT='%{$fg[green]%}%~%{$reset_color%} $(ruby_prompt_info) $(git_prompt_info)%{$reset_color%}%B$%b '
RPROMPT="${return_code}"
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="› %{$reset_color%}"
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}‹"
ZSH_THEME_RUBY_PROMPT_SUFFIX="› %{$reset_color%}"
❌
# 修改不好使 ❌
$ cat ~/.oh-my-zsh/themes/macovsky-ruby.zsh-theme
# ZSH Theme - Preview: https://i.gyazo.com/8becc8a7ed5ab54a0262a470555c3eed.png
# local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})\\$"
# backup
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
# PROMPT='%{$fg[green]%}%~%{$reset_color%} $(ruby_prompt_info) $(git_prompt_info)%{$reset_color%}%B$%b '
PROMPT='%{$fg[green]%}%~%{$reset_color%} $(ruby_prompt_info) $(git_prompt_info)%{$reset_color%}%B$%b \\$xyz'
# RPROMPT="${return_code}"
RPROMPT="${return_code} \\$"
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[yellow]%}‹"
ZSH_THEME_GIT_PROMPT_SUFFIX="› %{$reset_color%} \\$git"
ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}‹"
ZSH_THEME_RUBY_PROMPT_SUFFIX="› %{$reset_color%}"
$ source ~/.zshrc
# 等价于
$ . ~/.zshrc
修改不好使, 改了没有反应!shell 启动是时候会被重新覆盖掉了 ❓
✅
# 隐藏 hostname username
# export PS1="\u@\h \W\\$"
# 显示 $ 提示符号 💰
# export PS1="\\$"
setopt PROMPT_SUBST
# PROMPT='%F{green}%*%f %F{blue}%~%f %F{red}${vcs_info_msg_0_}%f$ '
PROMPT='%{$fg[green]%}%~%{$reset_color%} $(ruby_prompt_info) $(git_prompt_info)%{$reset_color%}%B$%b '
~ $ ✅pwd
/Users/xgqfrms-mm
~ $ ✅cat ~/.zshrc | grep PROMPT
# DISABLE_UPDATE_PROMPT="true"
setopt PROMPT_SUBST
# PROMPT='%F{green}%*%f %F{blue}%~%f %F{red}${vcs_info_msg_0_}%f$ '
PROMPT='%{$fg[green]%}%~%{$reset_color%} $(ruby_prompt_info) $(git_prompt_info)%{$reset_color%}%B$%b ✅'
~ $ ✅
solutions ✅
# zsh default
➜ ~ echo $PS1
%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)
➜ ~ vim ~/.zshrc
➜ ~ . ~/.zshrc
# 结尾没有空格 💩
➜ ~ $echo $PS1
%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info) $
➜ ~ $cat ~/.zshrc | grep PROMPT
# DISABLE_UPDATE_PROMPT="true"
setopt PROMPT_SUBST
# PROMPT='%F{green}%*%f %F{blue}%~%f %F{red}${vcs_info_msg_0_}%f$ '
# PROMPT='%{$fg[green]%}%~%{$reset_color%} $(ruby_prompt_info) $(git_prompt_info)%{$reset_color%}%B$%b ✅'
# PROMPT=' ✅'
PROMPT='%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info) $'
➜ ~ $
➜ ~ $vim ~/.zshrc
➜ ~ $. ~/.zshrc
# 结尾有空格✅
➜ ~ $ echo $PS1
%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info) $
➜ ~ $ cat ~/.zshrc | grep PROMPT
# DISABLE_UPDATE_PROMPT="true"
setopt PROMPT_SUBST
# PROMPT='%F{green}%*%f %F{blue}%~%f %F{red}${vcs_info_msg_0_}%f$ '
# PROMPT='%{$fg[green]%}%~%{$reset_color%} $(ruby_prompt_info) $(git_prompt_info)%{$reset_color%}%B$%b ✅'
# PROMPT=' ✅'
PROMPT='%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info) $ '
➜ ~ $
demos
# apeend $ symbol ✅
➜ ~ echo $PS1
%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)
➜ ~ vim ~/.zshrc
➜ ~ . ~/.zshrc
➜ ~ $ echo $PS1
%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)$
➜ ~ $ cat ~/.zshrc | grep PROMPT
# DISABLE_UPDATE_PROMPT="true"
setopt PROMPT_SUBST
# PROMPT='%F{green}%*%f %F{blue}%~%f %F{red}${vcs_info_msg_0_}%f$ '
# PROMPT='%{$fg[green]%}%~%{$reset_color%} $(ruby_prompt_info) $(git_prompt_info)%{$reset_color%}%B$%b ✅'
# PROMPT=' ✅'
PROMPT='%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)$ '
custom zsh prompt
https://dev.to/cassidoo/customizing-my-zsh-prompt-3417
.zshrc
```sh
$ cat ~/.zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/xgqfrms-mm/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in ~/.oh-my-zsh/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"
# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"
# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"
# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS=true
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"
# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"
# Uncomment the following line to display red dots whilst waiting for completion.
# COMPLETION_WAITING_DOTS="true"
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in ~/.oh-my-zsh/plugins/*
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
source $ZSH/oh-my-zsh.sh
# macOS Chrome 应用分身/应用双开
# /Applications/Google Chrome.app/Contents/MacOS
# https://www.cnblogs.com/xgqfrms/p/16993756.html
# 可执行脚本
# /Users/xgqfrms-mm/Desktop/custom-chrome.sh
# 用户数据
# /Users/xgqfrms-mm/Desktop/Custom_Chrome
# alias 全局快捷方式 $ccapp
alias ccapp='/Users/xgqfrms-mm/Desktop/custom-chrome.sh'
# source ~/.zshrc
# 手动覆盖默认 git alias
alias gad='git add .'
alias gcm='git commit -m'
alias gp='git pull'
alias gps='git push'
# alias gps='git push -u origin master'
# source ~/.zshrc
# User configuration
# export MANPATH="/usr/local/man:$MANPATH"
# You may need to manually set your language environment
# export LANG=en_US.UTF-8
# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
# export EDITOR='vim'
# else
# export EDITOR='mvim'
# fi
# Compilation flags
# export ARCHFLAGS="-arch x86_64"
# Set personal aliases, overriding those provided by oh-my-zsh liAbs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
# 隐藏 hostname username
# export PS1="\u@\h \W\\$"
# 显示 $ 提示符号 💰
# export PS1="\\$"
setopt PROMPT_SUBST
# PROMPT='%F{green}%*%f %F{blue}%~%f %F{red}${vcs_info_msg_0_}%f$ '
# PROMPT='%{$fg[green]%}%~%{$reset_color%} $(ruby_prompt_info) $(git_prompt_info)%{$reset_color%}%B$%b ✅'
# PROMPT=' ✅'
PROMPT='%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)$ '
# tree bug
source ~/.bash_profile
# alias 汇编环境
alias nasm=/usr/bin/nasm
alias gcc=/usr/bin/gcc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# MySQL
export PATH=${PATH}:/usr/local/mysql/bin/
# MongoDB
export PATH="/usr/local/opt/mongodb-community@4.2/bin:$PATH"
# Python 3 ✅
# alias python=/usr/bin/python3
# alias py3='python3'
# which python3
# /usr/bin/python3
# source ~/.zshrc ✅
# Python 3.11 ✅
alias python=/usr/local/bin/python3
alias py3='python'
# which python
# python: aliased to /usr/local/bin/python3
# source ~/.zshrc ✅
# ls /usr/local/bin | grep python
# python3
# python3-config
# python3-intel64
# python3.11
# python3.11-config
# python3.11-intel64
# /usr/local/bin/python3 --version
# Python 3.11.4
# /usr/local/bin/python3.11 --version
# Python 3.11.4
# export PATH="/usr/bin/python3:$PATH"
# export PATH="/usr/bin/:$PATH"
# $ cd /usr/bin/ && ls | grep "python" ✅
# $ cd /usr/bin/ && ls -al | grep "python" ✅
# Python3.11
# alias python=/usr/local/lib/python3.11
# alias py3='python'
# export PATH="/usr/local/lib/python3.11:$PATH"
# source ~/.zshrc ✅
# /usr/local/bin/python3
# /opt/local/bin/python3
# /sw/bin/python3
# /usr/local/bin/python3 --version
# Python 3.11.4
# /usr/local/bin/python3 --version
# Python 3.11.4
# .bash_profile
source ~/.bash_profile
# end zsh
# source ~/.zshrc
# export NVM_USER_ENV
export NVM_USER_ENV=xgqfrms_eric
export NVM_PROFILE=/hone/eric/.bashrc
# bun completions
[ -s "/Users/xgqfrms-mm/.bun/_bun" ] && source "/Users/xgqfrms-mm/.bun/_bun"
# bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
自定义命令行提示符 zsh & Oh My Zsh $PS1
# pi3b
$ echo $PS1
%(?:%{%}%1{➜%} :%{%}%1{➜%} ) %{%}%c%{%} $(git_prompt_info)
# mac mini 2018
$ echo $PS1
%(?:%{%}➜ :%{%}➜ ) %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)$
???
$ cat ~/.oh-my-zsh/themes/macovsky-ruby.zsh-theme
$ vim ~/.oh-my-zsh/themes/macovsky-ruby.zsh-theme
$ source ~/.oh-my-zsh/themes/macovsky-ruby.zsh-theme
https://www.cnblogs.com/xgqfrms/p/18671874#5338409
https://stackoverflow.com/questions/35281630/how-do-i-change-my-ps1-on-a-macbook-for-oh-my-zsh
refs
https://scriptingosx.com/2019/07/moving-to-zsh-06-customizing-the-zsh-prompt/
https://www.tweaking4all.com/software/macosx-software/customize-zsh-prompt/
https://stackoverflow.com/questions/35281630/how-do-i-change-my-ps1-on-a-macbook-for-oh-my-zsh
©xgqfrms 2012-2025
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17725153.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2022-09-23 Apple Watch All In One
2022-09-23 客机飞机航线图 All In One
2022-09-23 js ArrayBufferView & TypeArray All In One
2021-09-23 ui framework & npm multiple packages All In One
2020-09-23 cnblogs 日期错乱 bug
2020-09-23 WebAR in Action
2020-09-23 Caddyfile 是干什么的?