
Cmder is an awsome package of software which replaces the default consolecmd.exe
orpowershell
on windows.
If you are in a git repo, you see the current branch in the prompt, colored in white if its clean or red if dirty. There are similar features for yarn, npm, ...
Sometimes you want to add the output of to the prompt too. This can be done like this:
In my case i wanted to see on whichterraform workspace i am. with terraform you can do this by runningterraform workspace show
in your terraform directory. this would output something like
λ terraform workspace showdefault
To do this you have to create aclink extension. Assuming that you installed cmder inC:\Program Files\Cmder
you create a file calledterraform.lua
inC:\Program Files\Cmder\vendor\clink-completions
terraform.lua
localcolor=require("color")localfunctionis_terraform()fordirinio.popen([[dir ".\" /b /ad]]):lines()doifdir==".terraform"thenreturntrueendendreturnfalseendlocalfunctionterraform_prompt_filter()ifis_terraform()thenf=assert(io.popen("terraform workspace show"))forlineinf:lines()doterraform_context='(workspace: '..line..')'ifline=="production"thenprompt_color=color.REDelseifline=="development"thenprompt_color=color.GREENelseprompt_color=color.YELLOWendbreakend-- for loopf:close()terraform_context=color.color_text(terraform_context,prompt_color)clink.prompt.value=clink.prompt.value:gsub("\n",terraform_context.."\n")returnfalseendendclink.prompt.register_filter(terraform_prompt_filter,1)
this code checks if it is currently in a terraform directory by looking if the directory.terraform
exists. it colors the workspace output in green if you are ondevelopment
workspace, red if you are onproduction
and yellow on all others. adapt the code for your needs.
i am sure that the lua code can be optimized, i am open for comments and enhancements.
links:
- cover image by Willi Heidelbachhttps://pixabay.com/en/puzzle-match-missing-hole-blank-693870/
Top comments(3)

Cmder was the best terminal for custom prompt with zsh before Hyper. I love the git integration and syntax highlighting without any configuration. But now cmder became a bit obsolete.
For further actions, you may consider blocking this person and/orreporting abuse