Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conda environment not displaying #1056

Closed
cmorgan opened this issue Aug 2, 2016 · 3 comments
Closed

conda environment not displaying #1056

cmorgan opened this issue Aug 2, 2016 · 3 comments

Comments

@cmorgan
Copy link

cmorgan commented Aug 2, 2016

the conda env, usually looks like (dev) c:\dev\code (master)
is missing from version 1.30 full distribution

@jankatins
Copy link
Contributor

jankatins commented Aug 2, 2016

As we currently do not use the original prompt, you have to add conda information yourself:

Add a file called <cmder dir>\config\<something>.lua with the following content:

---
 -- Find out current conda env
 -- @return {false|conda env name}
---
function get_conda_env()
    env_path = clink.get_env('CONDA_DEFAULT_ENV')
    if env_path then
        basen = basename(env_path)
        return basen
    end
    return false
end

---
 -- add conda env name 
---
function conda_prompt_filter()
    -- add in conda env name
    local conda_env = get_conda_env()
    if conda_env then
        clink.prompt.value = string.gsub(clink.prompt.value, "{lamb}", "["..conda_env.."] {lamb}")
    end
end

clink.prompt.register_filter(conda_prompt_filter, 20)

@lpinner
Copy link

lpinner commented Aug 3, 2016

At the point this runs, the "{lamb}" has already been replaced with "λ".

To get it working, I replaced:
clink.prompt.value = string.gsub(clink.prompt.value, "{lamb}", "["..conda_env.."] {lamb}")

with:
clink.prompt.value = string.gsub(clink.prompt.value, "λ", "["..conda_env.."] λ")

Full lua I ended up with:

 -- Code based on https://github.com/cmderdev/cmder/issues/1056
 -- with modifications to make it work with conda/virtual envs (https://github.com/cmderdev/cmder/issues/1056#issuecomment-237403714)
---
 -- Find out current conda/virtual envs
 -- @return {false|conda/virtual env name}
---

local clink_path_lua_file = clink.get_env('CMDER_ROOT')..'\\vendor\\clink-completions\\modules\\path.lua'
dofile(clink_path_lua_file)

function get_virtual_env(env_var)
    env_path = clink.get_env(env_var)
    if env_path then
        basen = exports.basename(env_path)
        return basen
    end
    return false
end

---
 -- add conda env name 
---
function conda_prompt_filter()
    -- add in conda env name
    local conda_env = get_virtual_env('CONDA_DEFAULT_ENV')
    if conda_env then
        clink.prompt.value = string.gsub(clink.prompt.value, "λ", "["..conda_env.."] λ")
    end
end

---
 -- add virtual env name 
---
function venv_prompt_filter()
    -- add in virtual env name
    local venv = get_virtual_env('VIRTUAL_ENV')
    if venv then
        clink.prompt.value = string.gsub(clink.prompt.value, "λ", "["..venv.."] λ")
    end
end

clink.prompt.register_filter(conda_prompt_filter, 20)
clink.prompt.register_filter(venv_prompt_filter, 20)

@jankatins
Copy link
Contributor

Please try #1070 for a version which parses the original prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants