Oh My Zsh 离线安装 手动安装 PS1样式颜色
Oh My Zsh 离线安装 手动安装 PS1样式颜色
Oh My Zsh下载
GitHub地址:https://github.com/ohmyzsh/ohmyzsh/
zip直接下载链接:https://github.com/ohmyzsh/ohmyzsh/archive/refs/heads/master.zip
配置
下载安装包后解压,随后整个文件夹拖进linux的主目录(Home)下。
如果不确定主目录,在$
状态下数据pwd
可得知自己的主目录。
将文件夹改名为.oh-my-zsh
。可是这时你看不到,因为它变成了隐藏文件夹,快捷键Ctrl+H可显示隐藏文件。
文件
在主目录下创建.zshrc
文件,填入以下内容。
touch .zshrc
或
vi .zshrc
精简版
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
ZSH_THEME="ys"
plugins=(git)
source $ZSH/oh-my-zsh.sh
完整版
# 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=$HOME/.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="ys"
# 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 $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 one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled # disable automatic updates
# zstyle ':omz:update' mode auto # update automatically without asking
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 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.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# 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 $ZSH/plugins/
# Custom plugins may be added to $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
# 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 libs,
# 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"
生效
source .zshrc
随后输入zsh便可进入崭新的中断,如果切换样式可查看:
如果不想每次都输入zsh,则可以修改默认终端
cat /etc/shells
chsh -s /bin/zsh
root样式设置
但当我们进入root模式会发现一切设置都没了。
虽然暂时没法实现root的美化,但可以做一些简单的美化
复制.bashrc
文件到root下。
sudo cp ~/.bashrc /root/.bashrc
随后编辑文件
vi .bashrc
直奔113行左右(各版本可能各不相同),修改PS1内容
PS1='[`date "+%x %H:%M"`] \u@\h:\w\$ '
时间戳:
也可以直接修改
export PS1="\[\e[36;1m\] \u@\h:\w\$\[\e[m\]"
PS1 参数
符号 | 含义 |
---|---|
\a |
ASCII bell字符 |
\d |
日期以“工作日-月份-日期”格式填写(例如:Tue May 26 ) |
\D{format} |
格式将传递给strftime(3),结果插入到提示符串中; 空格式会导致特定于区域设置的时间表示。 需要括号 |
\e |
ASCII转义字符 |
\h |
主机名直到第一个'.' |
\H |
主机名 |
\j |
当前由shell管理的任务数量 |
\l |
Shell的终端设备名称的基本名称 |
\n |
新建一行 |
\r |
回车 |
\s |
shell的名称,$ 0的基本名(最终斜线以下的部分) |
\t |
24小时HH的当前时间 :MM :SS format |
\T |
12小时HH的当前时间 :MM :SS format |
\@ |
12小时AM / PM格式的当前时间 |
\A |
24小时HH的当前时间:MM格式 |
\u |
当前用户的用户名 |
\v |
Bash的版本(例如,2.00) |
\V |
释放Bash,版本+补丁级别(例如,2.00.0) |
\w |
折叠了$HOME 的当前工作目录, |
\W |
当前工作目录的基本名, $HOME缩写,用波浪号表示 |
\! |
此命令的历史编号 |
\# |
此命令的命令编号 |
\$ |
如果有效UID为0(root),为#,否则为$ |
\nnn |
对应于八进制数NNN的字符 |
\\ |
反斜杠 |
\[ |
开始一系列非打印字符,可用于将终端控制序列嵌入到提示符中 |
\] |
结束一系列非打印字符 |
样例
显示今天的日期和主机名:
PS1="\d \h $ "
输出
Sat Jun 02 server $
显示日期,时间,主机名和当前工作目录:
PS1="[\d \t \u@\h:\w ] $ "
输出
[Sat Jun 02 14:24:12 vivek@server:~ ] $
颜色
格式
'\e[x;ym $PS1 \e[m'
参数 | 含义 |
---|---|
\e[ | 开始配色方案。 |
x;y | 使用颜色对(x; y) |
$PS1 | shell提示变量。 |
\e[m | 结束配色方案。 |
代码 | 含义 |
---|---|
\[\e[30;1m\]...[\e[m\] |
黑字 |
\[\e[31;1m\]...[\e[m\] |
红字 |
\[\e[32;1m\]...[\e[m\] |
绿字 |
\[\e[33;1m\]...[\e[m\] |
黄字 |
\[\e[34;1m\]...[\e[m\] |
蓝字 |
\[\e[35;1m\]...[\e[m\] |
紫字 |
\[\e[36;1m\]...[\e[m\] |
靛字 |
\[\e[37;1m\]...[\e[m\] |
白字 |
\e[31;1;42m\]...[\e[m\] |
红字绿低 混合样式 |
渐变色
export PS1="\[\e[0;33m\][\[\e[0;32m\]\u\[\e[0;33m\]@\h:\[\e[0;39m\]\w\[\e[0;33m\]]\$\[\e[0m\] "