What is a beautiful prompt
-
double line;
-
provide username, hostname, current directory;
-
provide information of git branch and commit status;
-
provide command exit code;
-
prompt is easy to distinguished from command results;
-
optional: provide command order number, current time;
Customize zsh prompt
Some important escape sequences in zsh prompt:
-
%n: username;
-
%m: hostname;
-
%~: current directory;
-
%t: current time;
-
%?: return code of last command;
Customization of font and color see the following demonstration.
Ref:
-
"3.9 Customizing the prompt" on zsh on archlinux
Put it together
-
Create a new file: ~/.oh-my-zsh/themes/lichao.zsh-theme:
rc=\(reset_color cy=\)fg_bold[cyan] bl=\(fg_bold[blue] re=\)fg_bold[red] wh=\(fg_bold[white] ye=\)fg_bold[yellow] gr=\(fg_bold[green] ma=\)fg_bold[magenta]
ZSH_THEME_GIT_PROMPT_PREFIX="git(" ZSH_THEME_GIT_PROMPT_SUFFIX="):" ZSH_THEME_GIT_PROMPT_CLEAN="✔" ZSH_THEME_GIT_PROMPT_DIRTY="✗" ZSH_THEME_GIT_PROMPT_ADDED="%{\(fg[green]%} ✚" ZSH_THEME_GIT_PROMPT_MODIFIED="%{\)fg[blue]%} M" ZSH_THEME_GIT_PROMPT_DELETED="%{\(fg[red]%} ✖" ZSH_THEME_GIT_PROMPT_RENAMED="%{\)fg[magenta]%} ➜" ZSH_THEME_GIT_PROMPT_UNMERGED="%{\(fg[yellow]%} ═" ZSH_THEME_GIT_PROMPT_UNTRACKED="%{\)fg[cyan]%} U"
PROMPT='\(ye%n\)rc @ \(cy%m $gr%~ $re\)(git_prompt_info)\((git_prompt_status)\)rc \(wh%t\)rc [%?] '
-
Modify "ZSH_THEME" in ~/.zshrc as:
ZSH_THEME="lichao"
Note: If you want add any color or highlight in the 2nd line of the prompt, remember escape the color directives with "%{" and "%}". For example, if your prompt is like this:
PROMPT='$ye%n$rc @ $cy%m $gr%~ $re$(git_prompt_info)$(git_prompt_status)$rc $wh%t$rc
${wh}[%?]${rc} '
you have to define variables like this:
wh=%{$fg_bold[white]%}
rc=%{$reset_color%}
If you keep using variables without escape, when you use tab-completion, your command line will be messed up.
Ref: http://stackoverflow.com/questions/13546672/custom-oh-my-zsh-theme-long-prompts-disappear-cut-off/14179542#14179542 http://stackoverflow.com/questions/7957435/zsh-auto-complete-screws-up-command-name/10644062#10644062
Recommended Themes
kphoen: double line, display user, host, CWD, command exit code when it's nonzero, git branch and status, no time, its title line is darker than "ys", but the command and command output is the same;
ys: double line, display user, host, CWD, time, partial git information, no exit code;
bureau: double line, display user, host, CWD, time, complete git information, no exit code;
steeef: double line, display user, host, CWD, complete git information, no exit code;
rkj: double line, display user, host, CWD, time, command exit code, no git information;
duellj: double line, display user, host, CWD, command order number, time, no git information;
some other good themes includes: frisk, candy, blinks