SetEnv() public method

Sets the startup environment variable for the console process, before it is started.

This cannot be used to change the environment variables of a running console process.

public SetEnv ( [ name, [ value ) : void
name [ Environment variable name, case-insensitive.
value [ Environment variable value, or NULL to remove this environment variable.
return void
示例#1
0
        /// <summary>
        /// Adds a tab with console interface to Git over the current working copy. Recreates the terminal on tab activation if user exits the shell.
        /// </summary>
        private void FillTerminalTab()
        {
            if (!EnvUtils.RunningOnWindows() || !Module.EffectiveSettings.Detailed.ShowConEmuTab.ValueOrDefault)
                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(_consoleTabCaption.Text));
            tabpage.ImageKey = sImageKey; // After adding page

            // Delay-create the terminal window when the tab is first selected
            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,
                            IsStatusbarVisible = false
                        }
                    );
                }
                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 sJustBash = "bash.exe"; // Generic bash, should generally be in the git dir, less configured than the specific git-bash
                string sJustSh = "sh.exe"; // Fallback to SH

                string cmdPath = new[] { sJustBash, sJustSh }.
                    Select(shell =>
                      {
                          string shellPath;
                          if (PathUtil.TryFindShellPath(shell, out shellPath))
                              return shellPath;
                          return null;
                      }).
                      Where(shellPath => shellPath != null).
                      FirstOrDefault();

                if (cmdPath == null)
                {
                    startinfo.ConsoleProcessCommandLine = ConEmuConstants.DefaultConsoleCommandLine;
                }
                else
                {
                    startinfo.ConsoleProcessCommandLine = cmdPath + " --login -i";
                }
                startinfo.ConsoleProcessExtraArgs = " -new_console:P:\"<Solarized Light>\"";

                // Set path to git in this window (actually, effective with CMD only)
                if (!string.IsNullOrEmpty(AppSettings.GitCommandValue))
                {
                    string dirGit = Path.GetDirectoryName(AppSettings.GitCommandValue);
                    if (!string.IsNullOrEmpty(dirGit))
                        startinfo.SetEnv("PATH", dirGit + ";" + "%PATH%");
                }

                terminal.Start(startinfo);
            };
        }
示例#2
0
	    /// <summary>
	    /// Adds a tab with console interface to Git over the current working copy. Recreates the terminal on tab activation if user exits the shell.
	    /// </summary>
	    private void FillTerminalTab()
	    {
		    if(!EnvUtils.RunningOnWindows() || !Module.EffectiveSettings.Detailed.ShowConEmuTab.ValueOrDefault)
			    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
		    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);
		    };
	    }