Home

Awesome

zcmder

A zsh theme inspired by Cmder with some additional git related prompt features.

<p align="center"><img src="assets/preview.png"></p>

Installation

Oh My Zsh

Clone this repository into your .oh-my-zsh/custom/themes directory:

git clone https://github.com/bwpge/zcmder "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/zcmder"

Set the theme in your .zshrc:

ZSH_THEME=zcmder/zcmder

Manual

Clone this repository to your machine (e.g., ~/.zsh):

git clone https://github.com/bwpge/zcmder ~/.zsh/zcmder

Source the theme in your .zshrc:

source ~/.zsh/zcmder/zcmder.zsh-theme

Updating

To update, pull any new commits from this repository:

cd "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/zcmder" && git pull

Be sure to reload (e.g., omz reload) or source the new file (e.g., source zcmder.zsh-theme) for any active sessions.

Configuration

Environment variables used by this theme are always prefixed with ZCMDER_. This theme uses following associative arrays:

When the theme is sourced, these variables are reset to ensure proper declaration and initial values. To customize them, set your desired values after sourcing the theme (or oh-my-zsh.sh).

Example .zshrc:

ZSH_THEME=zcmder/zcmder
source $ZSH/oh-my-zsh.sh

# zcmder options
ZCMDER_STYLES[cwd]="fg=green,underline" # use green fg and underline effect on cwd
ZCMDER_STYLES[git_branch_default]='fg=blue'  # use blue for default git branch color
ZCMDER_STYLES[git_new_repo]='bg=#2277ff,standout'  # use RGB value for new repo bg color
ZCMDER_COMPONENTS[python_env]=false  # disable python env component
ZCMDER_STRINGS[git_separator]=''  # don't print 'on ' before git prompt
ZCMDER_STRINGS[git_prefix]='■ '  # use different branch icon

The following tables explains each option and usage.

ZCMDER_COMPONENTS

Controls which components or segments of the prompt are printed. These values are evaluated with arithmetic evaluation (e.g., (( $foo ))), so to disable a component set the value to 0. To enable it, use a non-zero value:

ZCMDER_COMPONENTS[git_status]=0  # disable git prompt
ZCMDER_COMPONENTS[username]=1    # enable username
KeyTypeUsage
cwdboolPrint the current working directory in the prompt
git_statusboolPrint a git status (if in a git repo) in the prompt
hostnameboolPrint the hostname (zsh expanded %M) in the prompt
python_envboolPrint the current python environment (condaor venv) in the prompt
usernameboolPrint the username (zsh expanded %n) in the prompt

ZCMDER_STYLES

Controls colors and text effects of the various items in the prompt.

This associative array uses very similar syntax as "types of highlighting" in zshzle(1):

Valid style tokens:

Valid colors have the following form (see fg section of Character Highlighting in zshzle(1) for more information):

Example usage:

# green and bold text, inverted (green/default-bg swapped)
ZCMDER_STYLES[cwd]='fg=2,bold,standout'
# white on black in italic/underline
ZCMDER_STYLES[cwd]='fg=#ffffff,bg=#000000,italic,underline'

Git status styles have the following priority:

KeyTypeUsage
caretstyleDefault caret style
caret_errorstyleCaret style when the last exit code was non-zero
cwdstylestyle of the current working directory
cwd_readonlystylestyle when the current working directory is read-only
git_branch_defaultstyleDefault git status style
git_modifiedstyleGit status style when only tracked files are modified
git_new_repostyleGit status style when in a new repository
git_stagedstyleGit status style when all local changes are staged
git_unmergedstyleGit status when there are unmerged changes
git_untrackedstyleGit status when untracked (dirty) files are present
python_envstyleThe style for current python environment name
user_and_hoststylestyle for both username and hostname components

ZCMDER_OPTIONS

Controls general behavior of the prompt.

KeyTypeUsage
git_show_remoteboolShow the remote with git status (e.g., main:origin/main)
newline_before_promptboolPrint an empty line before the next prompt (excluding the first prompt)

ZCMDER_STRINGS

Controls values or tokens in each component that are printed.

KeyTypeUsage
caretstringPrompt string (the value printed directly before user input area)
caret_rootstringPrompt string when running with elevated permissions
git_ahead_postfixstringPrinted when repo is ahead of upstream (initialized with $ZSH_THEME_GIT_PROMPT_AHEAD)
git_behind_postfixstringPrinted when repo is behind upstream (initialized with $ZSH_THEME_GIT_PROMPT_BEHIND)
git_clean_postfixstringPrinted when repo has no local changes (initialized with $ZSH_THEME_GIT_PROMPT_CLEAN)
git_dirty_postfixstringPrinted when repo contains unstaged changes (initialized with $ZSH_THEME_GIT_PROMPT_DIRTY)
git_diverged_postfixstringPrinted when repo is both ahead and behind (diverged from) upstream (initialized with $ZSH_THEME_GIT_PROMPT_DIVERGED)
git_label_newstringLabel to use for a new repository
git_prefixstringPrefix always printed for git status e.g., a branch icon or git( (initialized with $ZSH_THEME_GIT_PROMPT_PREFIX)
git_separatorstringA separator or preamble before the git status is printed e.g., ' on '
git_stashed_modifierstringPrinted when repo contains stashes (initialized with $ZSH_THEME_GIT_PROMPT_STASHED)
git_suffixstringSuffix always printed for git status e.g., ) (initialized with $ZSH_THEME_GIT_PROMPT_SUFFIX)
readonly_prefixstringPrinted before current working directory when read-only (see man test, -w flag)

Prevent Modifying ZSH_THEME_GIT_PROMPT_*

By default, this theme will set/change several ZSH_THEME_GIT_PROMPT_* environment variables since ZCMDER_STRINGS initializes values from these variables. Changes to these variables will persist through omz reload, so this behavior may not be desireable.

To disable this behavior, set ZCMDER_NO_MODIFY_ZSH_THEME prior to loading oh-my-zsh or sourcing the theme.

Example .zshrc:

# ...

ZSH_THEME=zcmder/zcmder
ZCMDER_NO_MODIFY_ZSH_THEME=1
source $ZSH/oh-my-zsh.sh

# ... zcmder config

To use the zcmder git status style without modifying ZSH_THEME_GIT_PROMPT_* variables, use the following options after sourcing this theme:

ZSH_THEME=zcmder/zcmder
ZCMDER_NO_MODIFY_ZSH_THEME=1
source $ZSH/oh-my-zsh.sh

# zcmder config
ZCMDER_STRINGS[git_ahead_postfix]=" ↑"
ZCMDER_STRINGS[git_behind_postfix]=" ↓"
ZCMDER_STRINGS[git_clean_postfix]=" ✓"
ZCMDER_STRINGS[git_dirty_postfix]=" *"
ZCMDER_STRINGS[git_diverged_postfix]=" ↑↓"
ZCMDER_STRINGS[git_prefix]=" "
ZCMDER_STRINGS[git_stashed_modifier]=" ⚑"
ZCMDER_STRINGS[git_suffix]=""