New Shell Prompt

| Comments

So I begin using zsh (again) recently and plug some accessories from oh-my-zsh. Inspired by this and my previous bash prompt here:

PS1=":\[\033[01;36m\]\W \[\033[01;35m\]»\[\033[00m\] "

I made my own theme.

Basically, I prefer a prompt with minimal yet useful information, so typical theme with two lines prompt is very much a no no.

(fudanchii.zsh-theme) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env zsh

function prompt_char {
    git branch >/dev/null 2>/dev/null && echo '±' && return
    hg root >/dev/null 2>/dev/null && echo '☿' && return
    echo '➜'
}

function hg_prompt_info {
    hgstatus="$(hg branch 2>/dev/null)"
    if [[ `hg status 2>/dev/null | wc -l` -ne "0" ]]; then
        hgstatus="$hgstatus%{$fg[red]%}✘%{$reset_color%}"
    fi
    echo $hgstatus
}

PROMPT='$(hg_prompt_info)$(git_prompt_info):%{$fg_bold[cyan]%}%c %{$fg_bold[magenta]%}$(prompt_char) %{$reset_color%}'

ZSH_THEME_GIT_PROMPT_PREFIX=""
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}✘%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""

In addition, here is my tmux configuration, which I used to show [email protected] at its bottom-left status bar:

(tmux.conf) download
1
2
3
4
5
6
7
8
9
10
11
12
set -g prefix C-a
bind-key C-a last-window
set -g base-index 1
unbind %
bind | split-window -h
bind - split-window -v
set -g status-bg black
set -g status-fg white
set -g status-left "#[fg=blue]#(whoami)#[fg=white]@#[fg=green]#h"
set-window-option -g window-status-current-bg red
set -g status-right "#[fg=white]%a %h %d, %H:%M "
setw -g automatic-rename on

Comments