
저는 Windows 10을 실행 중이고 동일한 시스템의 bash 프롬프트와 동일하게 보이도록 cmd.exe 프롬프트를 설정하고 싶습니다. cmd.exe를 로드할 때 PROMPT 변수를 설정하도록 시작 스크립트를 설정했습니다. 이 변수는 셸이 루트 권한으로 실행 중인지 감지하고 이에 따라 색상을 설정합니다.
그러나 스크린샷에서 볼 수 있듯이 bash(하단 창)에 표시된 것처럼 명령을 마친 후 색상이 기본값으로 재설정되도록 cmd.exe(상단 창)에서 프롬프트를 설정할 수 없습니다. cmd에서 bash를 실행하면 색상도 재설정할 수 없습니다.
그런 다음 두 셸 모두에서 색상을 사용하여 ls를 실행합니다. cmd에서 실행하거나 cmd 내에서 bash를 실행하면 일반 파일에서 색상을 재설정할 수 없습니다. 그러나 bash에서만 실행하면 색상이 재설정될 수 있습니다.
cmd.exe의 색상 동작이 내 bash 쉘과 동일하도록 시작 스크립트를 어떻게 설정합니까?
답변1
Windows 10 콘솔에는 *NIX와 훨씬 더 유사한 몇 가지 새로운 실험적 기능이 있습니다. 예를 들어 지금까지 사용할 수 있었던 16가지 색상으로 더 이상 제한되지 않는 색상, 커서 모양 등이 있습니다.
이전과 같이 속성 창에서 구성됩니다.
자세한 내용은 여기에서 확인할 수 있습니다.
https://devblogs.microsoft.com/commandline/new-experimental-console-features/
답변2
한 가지 옵션은 다음과 같습니다.콘에뮤 (맞춤형conemu.xml
)Powershell과 결합하여 터미널을 완벽하게 사용자 정의할 수 있으므로 터미널 관리자로서profile.ps1
cmd
명령 앞에 다음을 입력하면 Powershell에서 특정 명령을 실행할 수 있습니다.cmd /c
%UserProfile%\Documents\WindowsPowerShell\profile.ps1
#
##::[[--- PowerShell PS1 Profile ---]]::##
#================================================================
# Parameters
#----------------------------------------------------------------
# ANSI:
$ESC = [char]27
# Host.PrivateData
$PD = $($Host.PrivateData)
# Colors
#----------------------------------------------------------------
# Powershell
$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
#Clear-Host
# Prompt
#----------------------------------------------------------------
Function set-prompt {
Param (
[Parameter(Position=0)]
[ValidateSet("Default","Test")]
$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 " "
}
}
"Test" {
function prompt() {
if ( Test-Wow64 ) {
write-host -NoNewLine "Wow64 "
}
if ( Test-Admin ) {
write-host -NoNewLine -f red "Admin "
}
write-host -NoNewLine -ForegroundColor Green $(get-location)
foreach ( $entry in (get-location -stack)) {
write-host -NoNewLine -ForegroundColor Red '+';
}
write-host -NoNewLine -ForegroundColor Green '>'
' '
}
}
}
}
set-prompt Default
- 색상화된 텍스트를 표시합니다.즉각적인사용자의 경우 빨간색 텍스트 프롬프트가 관리자에게 표시됩니다.
- 프로필을 즉시 전환할 수 있습니다.(를 통해 다시 로드/전환 프롬프트
set-prompt <name>
)Default
아래 섹션을 복사/붙여넣고 적절하게 편집하세요.(보다Test
)
마이크로소프트의 새로운단말기또한 구성 파일을 통해 고도로 사용자 정의할 수 있지만 .json
ConEmu는 여러 셸을 사용자 정의하고 실행하기가 더 쉽습니다.