4

Good morning,
This is not a duplicate of questions like this one: I'm not looking to open the command prompt and to replace the text of the prompt by something else:
I have just downloaded conEmu, a console emulator, and I would like to replace the command prompt program (cmd.exe) by that one.

Hereby some history: I have an application that opens a command prompt, writes some things to that prompt, and also writes those same things to a logfile. In case something goes wrong, I can either read it from the command prompt or from the logfile.
Now this is the situation I'm facing: the application starts, opens the command prompt, writes some stuff and closes. While closing, also the command prompt gets closed.

I know from previous experience that this can be handled, replacing cmd.exe by a more persistent commandline tool (like conEmu, the one I've just downloaded).
Point is: I don't know how I should configure my Windows-10 machine in order to open conEmu instead of cmd.exe.

Does anybody know?
Thanks in advance

Dominique
  • 2,373

1 Answers1

3

When installing ConEmu, the user is usually looking to replace the cmd and powershell terminals as the default terminal for both (possibly others):

  • You may find useful this export of the heavily customized config file I use, which has the options below enabled
    (Settings → Import... → Save settings)

  1. Open Settings: WinKey+Alt+P
  2. GeneralInject ConEmuHk.dll into processes, started in ConEmu tabs
  3. IntegrationDefault Term → Tick boxes:
    1. Force ConEmu as default terminal for console applications
    2. Register on OS startup
    3. Aggressive Mode
    4. Optional:
      1. Use existing ConEmu window if available
      2. List of hooked executables or window class names
        (Often this isn't needed, however if the application's console window doesn't open within ConEmu, add the application's executable)
  4. Save Settings

Since PowerShell has its own color scheme, it often doesn't look quite right in a terminal if not customized, especially if wanting the same background color regardless of command output, so I recommend also adding this to the PowerShell profile(s) used:

#

#=========================================================== ##::[[--- Powershell PS1 Profile ---]]::## #===========================================================

$env:UserProfile\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

%UserProfile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

ANSI:

$ESC = [char]27

Colors

#----------------------------------------------------------- $PD = $($Host.PrivateData)

$Host.UI.RawUI.BackgroundColor = ($bckgrnd = 'Black') $Host.UI.RawUI.ForegroundColor = 'Gray'

$PD.ErrorForegroundColor = 'Red' $PD.ErrorBackgroundColor = $bckgrnd

$PD.WarningForegroundColor = 'Magenta' $PD.WarningBackgroundColor = $bckgrnd

$PD.DebugForegroundColor = 'Yellow' $PD.DebugBackgroundColor = $bckgrnd

$PD.VerboseForegroundColor = 'Green' $PD.VerboseBackgroundColor = $bckgrnd

$PD.ProgressForegroundColor = 'Yellow' $PD.ProgressBackgroundColor = $bckgrnd

Terminal

#----------------------------------------------------------- Function set-prompt { Param ( [Parameter(Position=0)] [ValidateSet("Default")] $Action )

switch ($Action) { "Default" { Function global:prompt { if (test-path variable:/PSDebugContext) { '[DBG]: ' } write-host " " write-host ("$ESC[48;2;40;40;40m$ESC[38;2;170;210;0m$(Get-Location) $ESC[0m $ESC[0m")

    if ( $host.UI.RawUI.WindowTitle -match "Administrator" ) {
      $Host.UI.RawUI.ForegroundColor = 'Red'
      $(if ($nestedpromptlevel -ge 1) {
        write-host ('PS $$ ') -ForegroundColor Red -NoNewLine
      } else {
        write-host ('PS $ ') -ForegroundColor Red -NoNewLine
      })
    } else {
      $(if ($nestedpromptlevel -ge 1) {
        write-host ('PS $$ ') -ForegroundColor Blue -NoNewLine
      } else {
        write-host ('PS $ ') -ForegroundColor Blue -NoNewLine
      })
    }
    return " "
  }
}

} }

set-prompt Default

  • Lines 10 - 33: Specifies formatting character and prompt colors
  • Lines 36 - 72: Specifies prompt layout, with different colors for regular and Admin prompts
JW0914
  • 9,096