虽然OMZ有很多的主题可以选择,但是总是有的地方不是很满意,所以想要自己定义一个主题,但是百度发现居然没有一篇文章介绍这个。所以Google了一下怎么自己创建一个主题。
主题的位置是在~/.oh-my-zsh/themes/这个文件夹中。 所以在这个文件夹中创建一个文件,并修改~/.zshrc配置文件中的ZSH_THEME=字段, 将这个字段该为你创建的主题文件的文件名就可以了。
现在来说一下主题文件中该怎么写:
首先最基础的两行是:
# 左边的内容
PROMPT=’‘
# 右边的内容
RPROMPT=’’
PROMPT是显示在左边的内容,RPROMPT是显示在右边的内容
Prompting
偷个懒,复制一下别人写的 [原文]
%n - username
%m - short name of the current host
%M - name of curent host
%# - a `%` or a `#`, depending on whether the shell is running as root or not
%~ - relative path
%/ or %d - absolute path
%c or %C - Trailing component of the current working directory.
%t - time 12hr am/pm format
%T - time 24hr format
%w - day and date (day-dd)
%D - Date (default: yy-mm-dd)
%D{%f} - day of the month
%l or %y - The line (tty) the user is logged in on, without `/dev/' prefix.
例如 如果想在左边显用户和时间
PROMPT=’%n %t‘
然后是颜色:
字体颜色有几种写法:
%F{237}256 color number%F{red}8 color name (black, red, green, yellow, blue, magenta, cyan, white)$FG[237](notice the$sign instead of%) 256 color number$fg[red](notice the$and lower casefg) 8 color name (black, red, green, yellow, blue, magenta, cyan, white)%{$fg_bold[blue]%}bold variants%Fis Foreground color,$ffor resetting foreground color
%Kis bacKground color,%kfor resetting background-color
$reset_coloris a Zsh variable that resets the color of the output
You can use Unicode for symbols
%EClear to end of the line.
%U(%u)to Start (stop) underline mode.
你可以用下面的命令来检查一下样式:
print -P '%F{237} %m %f'
下面是OMZ默认主题的代码
PROMPT="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )"
PROMPT+=' %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'