private void FillTerminalTab()
{
if(!EnvUtils.RunningOnWindows())
return; // ConEmu only works on WinNT
TabPage tabpage;
string sImageKey = "Resources.IconConsole";
CommitInfoTabControl.ImageList.Images.Add(sImageKey, Resources.IconConsole);
CommitInfoTabControl.Controls.Add(tabpage = new TabPage("Console"));
tabpage.ImageKey = sImageKey; // After adding page
// Delay-create the terminal window when the tab is first selected
ConEmuControl terminal = null;
CommitInfoTabControl.Selecting += (sender, args) =>
{
if(args.TabPage != tabpage)
return;
if(terminal == null) // Lazy-create on first opening the tab
{
tabpage.Controls.Clear();
tabpage.Controls.Add(terminal = new ConEmuControl() {Dock = DockStyle.Fill, AutoStartInfo = null});
}
if(terminal.IsConsoleEmulatorOpen) // If user has typed "exit" in there, restart the shell; otherwise just return
return;
// Create the terminal
var startinfo = new ConEmuStartInfo();
startinfo.StartupDirectory = Module.WorkingDir;
startinfo.WhenConsoleProcessExits = WhenConsoleProcessExits.CloseConsoleEmulator;
// Choose the console: bash from git with fallback to cmd
string sGitBashFromUsrBin = "";/*This is not a console program and is not reliable yet, suppress for now.*/ //Path.Combine(Path.Combine(Path.Combine(AppSettings.GitBinDir, ".."), ".."), "git-bash.exe"); // Git bin dir is /usr/bin under git installdir, so go 2x up
string sGitBashFromBinOrCmd = "";/*This is not a console program and is not reliable yet, suppress for now.*/ //Path.Combine(Path.Combine(AppSettings.GitBinDir, ".."), "git-bash.exe"); // In case we're running off just /bin or /cmd
var gitDir = Path.GetDirectoryName(AppSettings.GitCommandValue);
string sJustBash = Path.Combine(gitDir, "bash.exe"); // Generic bash, should generally be in the git dir, less configured than the specific git-bash
string sJustSh = Path.Combine(gitDir, "sh.exe"); // Fallback to SH
startinfo.ConsoleProcessCommandLine = new[] {sGitBashFromUsrBin, sGitBashFromBinOrCmd, sJustBash, sJustSh}.Where(File.Exists).FirstOrDefault() ?? ConEmuConstants.DefaultConsoleCommandLine; // Choose whatever exists, or default CMD shell
if(startinfo.ConsoleProcessCommandLine != ConEmuConstants.DefaultConsoleCommandLine)
{
startinfo.ConsoleProcessCommandLine += " --login -i";
}
// Set path to git in this window (actually, effective with CMD only)
if(!string.IsNullOrEmpty(AppSettings.GitCommand))
{
string dirGit = Path.GetDirectoryName(AppSettings.GitCommand);
if(!string.IsNullOrEmpty(dirGit))
startinfo.SetEnv("PATH", dirGit + ";" + "%PATH%");
}
terminal.Start(startinfo);
};
}