Add Kubectl Context to Cmder Prompt
October 17, 2019•62 words
Add a .lua file under .\config\myconfig.lua_
function custom_prompt()
-- Exectute kubectl command to get context (Note the output will contain a newline)
local handle = io.popen("kubectl config current-context")
local context = handle:read("*a")
handle:close()
cwd = clink.get_cwd()
prompt = "\x1b[1;32;40m{cwd} {git}{hg} \x1b[0;35;40m{context}\x1b[1;30;40m{lamb} \x1b[0m"
new_value = string.gsub(prompt, "{cwd}", cwd)
add_context = string.gsub(new_value, "{context}", context)
clink.prompt.value = string.gsub(add_context, "{lamb}", "λ")
end
clink.prompt.register_filter(custom_prompt, 1)