Skip to content

Instantly share code, notes, and snippets.

@Murazaki
Last active August 1, 2019 09:40
Show Gist options
  • Save Murazaki/dbea1adade21611b9b2719ffeec9bf1b to your computer and use it in GitHub Desktop.
Save Murazaki/dbea1adade21611b9b2719ffeec9bf1b to your computer and use it in GitHub Desktop.
Cmder cmd prompt customization zsh agnoster-like based on https://amreldib.com/blog/CustomizeWindowsCmderPrompt/

How to Install

  • Download Powerline Fonts, or get SourceCode Pro, Hack or else from Nerd Fonts (recommended)
  • Change Cmder fonts in Cmder settings (General > Fonts). Make sure the font charset is set to ANSI.

NB: Remember to backup every config files you will modify

  • Change Cmder/vendor/init.bat file with the one provided
  • Replace Cmder/config/git.lua file with the one provided and add prompt.lua in the same folder
  • Make sure Cmder loads cmd with init.bat, for instance, like this :
cmd /k ""%ConEmuDir%\..\init.bat" "
  • Restart Cmder

More info

Command prompt list of colors

This is based on Amr Elib blog post and gist

Known issues

Prompt styling jammed when cmd window is too small

---
-- 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
end
end
return false
end
---
-- Get the status of working dir
-- @return {bool}
---
function get_git_status()
return os.execute("git diff --quiet --ignore-submodules HEAD")
end
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")
else
-- dirty
color = colors.dirty
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."  "..branch.." \x1b[33;40m")
end
return true
end
-- No git present or not in git file
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", " \x1b[34;40m")
return false
end
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
@prompt %username%@%computername%{caret}$E[30;44m$P{git}$S$E[0m
:: Pick right version of clink
@if "%PROCESSOR_ARCHITECTURE%"=="x86" (
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
@set PLINK_PROTOCOL=ssh
@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.value = string.gsub(clink.prompt.value, "{caret}", " \x1b[30;44m\x1b[37;34m ")
end
clink.prompt.register_filter(lambda_prompt_filter, 40)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment