If you run Anaconda on windows, you have an activate.bat
file which concludes with this line to put your current conda env on the prompt:
set PROMPT=[%CONDA_DEFAULT_ENV%] $P$G
If you run cmder on windows, there is a nice lua script to customize your prompt:
function lambda_prompt_filter()
clink.prompt.value = string.gsub(clink.prompt.value, "{lamb}", "λ")
end
clink.prompt.register_filter(lambda_prompt_filter, 40)
These two scripts do not play very nicely with each other. Clink has an API that seems like I could use to incorporate the change from activate.bat
, but I cannot figure out how to call it from a batch file.
My overall goal is to merge these two prompts into the nicer Cmder-style. My thought is to create an environment variable, change activate.bat
to check for the existence of the variable, and, if so, call the Clink API to change the prompt instead of set PROMPT
. At that point I would think I could create a new filter to cleanly merge the value in. I can't figure out how to call the API from the batch file, though.
Other solutions welcome.
EDIT: Partial, non-working solution
require "os" -- added to top of file, rest in filter function
local sub = os.getenv("CONDA_DEFAULT_ENV")
if sub == nil then
sub = ""
end
print(sub)
clink.prompt.value = string.gsub(clink.prompt.value, "{conda}", sub)
I added a {conda} in the prompt definition at the very beginning; removed the prompt statement from activate.bat
, and added this to git_prompt_filter
. Prior to using activate, everything is fine - the {conda}
gets suppressed by the ''
. However, if I use activate and switch into a folder with a git repo to trigger the change, I see:
{conda}C:\...
Does os.getenv
not get user set variables? Don't know what else the problem would be. I also tried adding a print, it doesn't print out the contents of CONDA...
either.