Instantly share code, notes, and snippets.

What would you like to do?
Customize Windows Cmder Prompt
-- Find out current branch
-- @return {false|git branch name}
function get_git_branch()
for line in io.popen("git branch 2>nul"):lines() do
local m = line:match("%* (.+)$")
if m then
return m
return false
-- Get the status of working dir
-- @return {bool}
function get_git_status()
return os.execute("git diff --quiet --ignore-submodules HEAD")
function git_prompt_filter()
-- Colors for git status
-- clean = "\x1b[1;37;40m",
-- dirty = "\x1b[31;1m",
local colors = {
clean = "\x1b[34;42m\x1b[37;42m",
dirty = "\x1b[34;43m\x1b[30;43m",
local branch = get_git_branch()
if branch then
-- Has branch => therefore it is a git folder, now figure out status
if get_git_status() then
-- clean
color = colors.clean
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color..""..branch.." \x1b[32;40m")
-- dirty
color = colors.dirty
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color..""..branch.." \x1b[33;40m")
return true
-- No git present or not in git file
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", " \x1b[34;40m")
return false
clink.prompt.register_filter(git_prompt_filter, 50)
:: Init Script for cmd.exe
:: Sets some nice defaults
:: Created as part of cmder project
:: Find root dir
@if not defined CMDER_ROOT (
for /f %%i in ("%ConEmuDir%\..\..") do @set CMDER_ROOT=%%~fi
:: Change the prompt style
:: Mmm tasty lamb
@prompt $E[37;44m$P$S{git}$_$E[34;40m{lamb}$S$E[0m
::@prompt $E[1;32;40m$P$S{git}$S$_$E[1;30;40m{lamb}$S$E[0m
::@prompt $E[1;32;40m$P$S$S$_$E[1;30;40m$G$S$E[0m
:: Pick right version of clink
set architecture=86
) else (
set architecture=64
:: Run clink
@"%CMDER_ROOT%\vendor\clink\clink_x%architecture%.exe" inject --quiet --profile "%CMDER_ROOT%\config"
:: Prepare for msysgit
:: I do not even know, copypasted from their .bat
@if not defined TERM set TERM=cygwin
:: Enhance Path
@set git_install_root=%CMDER_ROOT%\vendor\msysgit
@set PATH=%CMDER_ROOT%\bin;%git_install_root%\bin;%git_install_root%\mingw\bin;%git_install_root%\cmd;%git_install_root%\share\vim\vim74;%CMDER_ROOT%;%PATH%
:: Add aliases
@doskey /macrofile="%CMDER_ROOT%\config\aliases"
:: Set home path
@if not defined HOME set HOME=%USERPROFILE%
@if defined CMDER_START (
@cd /d "%CMDER_START%"
) else (
@if "%CD%\" == "%CMDER_ROOT%" (
@cd /d "%HOME%"
function lambda_prompt_filter()
clink.prompt.value = string.gsub(clink.prompt.value, "{lamb}", "λ")
clink.prompt.register_filter(lambda_prompt_filter, 40)

This comment has been minimized.

lborg019 commented Oct 20, 2016

where do you place the prompt.lua file?


This comment has been minimized.

CalumMunro commented Sep 6, 2017

Not sure if it's still relevant to you @Iborg019, but the prompt.lua just goes in the cmder/config folder with the git.lua.


This comment has been minimized.

DRSDavidSoft commented Mar 23, 2018

This page is available on the Web Archive, if @AmrEldib's blog is still inaccessible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment