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)$ '
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
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"
## 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
***
<div>
<a href="https://info.flagcounter.com/QIXi">
<img src="https://s11.flagcounter.com/count2/QIXi/bg_000000/txt_00FF00/border_FF00FF/columns_3/maxflags_12/viewers_0/labels_1/pageviews_1/flags_0/percent_1/" alt="Flag Counter" border="0">
</a>
</div>
***
<blockquote style="display: flex; flex-flow: column; align-items: center; justify-content: center; text-align: center; border: none;">
<h3><strong><span style="font-size: 16pt; color: #00ff00;">©xgqfrms 2012-<span data-uid="copyright-aside">2021</span></strong></span</h3>
<p><span style="font-size: 18pt; color: #00ff00;"><strong>www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!</strong></span></p>
<p><span style="font-size: 18pt; color: #00ff00;"><strong>原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!</strong></span></p>
</blockquote>
***
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17725153.html
未经授权禁止转载,违者必究!