Search code examples
conemu

Start Conemu with project specific environment variables


I'd like to create shortcuts to open shell consoles with project specific environment variables for each shell. I do this now with batch files like the below. They work but I need to open a CMD session and then run setenv_AA and setenv_BB every time. I'd like to just have shortcuts I can double click on and be running and ready to go. How can I do that?

Project 1 setenv_AA.bat

pushd D:\Projects\AA
set PYTHONHOME=C:\Python27x64\
set PROMPT=[2.7_x64] $p$_$g
set path=%PYTHONHOME%;%cd%\bin;%path%

Project 2 setenv_BB.bat

pushd X:\Work\BB
set PYTHONHOME=C:\Python34\
set PROMPT=[3.4] $p$_$g
set path=%PYTHONHOME%;%cd%\bin;%path%

What I've tried already:

A shortcut to the .bat file just runs ConEmu and than says "Press Enter or Esc to close console...". "C:\Program Files\ConEmu\ConEmu64.exe" /cmd D:\project_aa\setenv.bat does the same.

A shortcut like "C:\Program Files\ConEmu\ConEmu64.exe" /cmd set path=NEW;%path%; yields "ConEmuC: Root process was alive less than 10 sec, ExitCode=0. Press Enter or Esc to close console..."

Using /k /cmd yields a popup message of "unrecognized switch" while /cmd /k reveals it's calling CMD with /c (terminate after run):

'/k' is not recognized as an internal or external command,
operable program or batch file.

Current directory:
D:\p\ytdemv3.2016-03-08

Command to be executed:
"C:\Windows\system32\cmd.exe" /C /k set path=NEW;...blah...blah

ConEmuC: Root process was alive less than 10 sec, ExitCode=1.
Press Enter or Esc to close console...

How to change /C to /K?


Solution

  • Obviously, ConEmu is not a cmd.exe, so your /c or /k have no sense at all.

    Use ...\ConEmu.exe /cmd cmd.exe /k your-batch.bat.

    As for per-folder ".conemurc", that is rather bad idea. These conmands have to be executed per tab, but not globally. Also, these commands must be shell-specific and must be executed by the shell started in that tab. So, this idea doesn't differ from batch started with /k switch.