Last active
November 23, 2016 02:03
-
-
Save xgenvn/c479433b6adc9c840268504269650601 to your computer and use it in GitHub Desktop.
Support conda env on cmder prompt and some custom lamb chars
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function set_prompt_filter() | |
-- orig: $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m | |
-- color codes: "\x1b[1;37;40m" | |
cwd = clink.get_cwd() | |
conda_env = get_conda_env() | |
virtual_env = get_virtual_env() | |
if virtual_env then | |
prompt = "\x1b[1;32;40m{cwd} {git}{hg} \n\x1b[1;30;40m({virtual_env}){lamb} \x1b[0m" | |
new_value = string.gsub(prompt, "{cwd}", cwd) | |
new_value = string.gsub(new_value, "{virtual_env}", virtual_env) | |
else | |
if conda_env then | |
prompt = "\x1b[1;32;40m{cwd} {git}{hg} \n\x1b[1;30;40m({conda_env}){lamb} \x1b[0m" | |
new_value = string.gsub(prompt, "{cwd}", cwd) | |
new_value = string.gsub(new_value, "{conda_env}", conda_env) | |
else | |
prompt = "\x1b[1;32;40m{cwd} {git}{hg} \n\x1b[1;30;40m{lamb} \x1b[0m" | |
new_value = string.gsub(prompt, "{cwd}", cwd) | |
end | |
end | |
clink.prompt.value = string.gsub(new_value, "{lamb}", "➜") | |
--➤ | |
--➜ | |
end | |
function get_virtual_env() | |
virtual_env = clink.get_env('VIRTUAL_ENV') | |
if virtual_env then | |
_prompt = clink.get_env('PROMPT') | |
_env_name = string.gsub(_prompt, "%$P%$G", "") | |
_env_name = string.gsub(_env_name, "%(", "") | |
_env_name = string.gsub(_env_name, "%)%s", "") | |
return _env_name | |
end | |
return false | |
end | |
function get_conda_env() | |
conda_new_env = clink.get_env('CONDA_DEFAULT_ENV') | |
if conda_new_env then | |
return conda_new_env | |
end | |
return false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment