Skip to content

Instantly share code, notes, and snippets.

@AmrEldib
Created February 29, 2016 05:33
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AmrEldib/1d31cd54409a8ec612df to your computer and use it in GitHub Desktop.
Save AmrEldib/1d31cd54409a8ec612df to your computer and use it in GitHub Desktop.
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
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
:: 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
@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}", "λ")
end
clink.prompt.register_filter(lambda_prompt_filter, 40)
@lborg019
Copy link

where do you place the prompt.lua file?

@CalumMunro
Copy link

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.

@DRSDavidSoft
Copy link

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

@tnhung2011
Copy link

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

https://amreldib.com/blog/CustomizeWindowsCmderPrompt/
It's accessible (I used a Singaporean VPN).

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