Powershell 스크립트에서 Bash 콘솔의 텍스트 색상을 변경할 수 있습니다.

Powershell 스크립트에서 Bash 콘솔의 텍스트 색상을 변경할 수 있습니다.

병합 중에 powershell 스크립트를 실행하기 위해 git 설정이 있습니다. git 명령을 위해 Windows에서 Git Bash를 사용합니다. Powershell의 Write-Host 기능은 텍스트를 Bash 콘솔에 출력하지만 -ForegroundColor 플래그를 사용해도 텍스트 색상은 변경되지 않습니다. Powershell 스크립트가 Bash 콘솔에서 출력 색상을 설정하는 방법이 있습니까?

답변1

우선 먼저.

Write-Host 사용은 오랫동안 뜨거운 논쟁거리가 되어 왔습니다. PowerShell의 발명가/저자도 마찬가지입니다.

유해한 것으로 간주되는 쓰기 호스트 - PowerShell 창립자 Jeffrey Snover 작성

https://jsnover.com/blog/2013/12/07/write-host-considered-harmful

PowerShell 스크립트를 작성하거나 검토할 때 다음 경험 법칙을 기억해 두시기 바랍니다.

Write-Host를 사용하는 것은 거의 항상 잘못되었습니다.

Write-Host는 자동화를 방해하기 때문에 거의 항상 잘못된 작업입니다. 사람들이 Write-Host를 사용하는 데는 일반적으로 두 가지 이유가 있습니다.

해당 주제에 관한 다른 기사도 많이 있습니다.

이전 버전의 PoSH에서는 Write-Host를 파이프라인에서 사용할 수 없었습니다. 사용하는 순간 데이터가 버퍼에서 사라지기 때문입니다.

그러나 PoSHv5에서 Jeffrey Snover는 이제 다음과 같이 말합니다.

PowerShell v5를 사용하면 Write-Host가 더 이상 "강아지를 죽이지" 않습니다. 데이터는 정보 스트림으로 캡처됩니다.

https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Write-Information?view=powershell-5.1

설명

Write-Information cmdlet은 Windows PowerShell이 ​​명령에 대한 정보 스트림 데이터를 처리하는 방법을 지정합니다.

Windows PowerShell 5.0 introduces a new, structured information stream (number 6 in Windows PowerShell streams) that you can use to transmit structured data between a script and its callers (or hosting environment). Write-Information lets you add an informational message to the stream, and specify how Windows PowerShell handles information stream data for a command.

Colorized text to the screen for user interaction stuff - even that can be worked around easily.

Write-Verbose has a blue color Write-Warning has a orange color

You can still use colors, without using Write-Host, by doing this ...

PowerTip: Write PowerShell Output in Color Without Using Write-Host

https://blogs.technet.microsoft.com/heyscriptingguy/2012/10/11/powertip-write-powershell-output-in-color-without-using-write-host

Summary: Write colorized output to the Windows PowerShell console without using the Write-Host cmdlet.

Secondly, you also don't state what editor / console you are using. powershell.exe/powershell_ise.exe or something else, say VSCode.

Now, full disclosure: I not tried this in Bash. Yet, the without spending the extra time configuring PoSH for Bash integration...

Configuring the PowerShell ISE for use with Git and GitHub

The goal of this blog article is to configure the PowerShell ISE (Integrated Scripting Environment) so the management of Git version control can be performed from it. Most tutorials you’ll find will attempt to lead you down the path of using SSH instead of HTTPS to synchronize your repositories to GitHub from the command-line but that’s really over-complicated and unnecessary if you’re using a Windows based machine.

http://mikefrobbins.com/2016/02/09/configuring-the-powershell-ise-for-use-with-git-and-github

...then, bash terminal and PoSH console are two different environments. If you are saying, that you are using Bash command in a PoSH script and redirecting output to the Bash terminal, then I get that, but, outside of using Write-Host being wrong in most cases, when PoSH sends output to something else, then it's the destination that controls how it will look, not PowerShell.

Even in using PoSH WinForm / WPF, from text boxes can be sent text from PoSH, but you must use the from properties to set colors.

Anyway, there are several discussions on color in GIT Bash with PowerShell. See if these help further.

Using Git from PowerShell

Customize your Git environment

You may want to customize some of the settings of your Git environment, especially if this is a new install of Git. Being a good project contributor in Git you should identify yourself so that Git knows who to blame for your commits. Also, I found that the default colors used by Git in the shell could be hard to read. So I customized the colors to make them more visible. For more information, see the Customizing Git topic in the Git documentation.

다음 명령은 한 번만 실행하면 됩니다. 전역 기본 설정을 지정하므로 일단 설정되면 새 셸을 시작할 때마다 사용됩니다.

https://seanonit.wordpress.com/2016/12/05/using-git-from-powershell

Windows의 git bash에서 ls에 대한 색상 설정

저는 최근에 Windows용 GitHub를 설치했고 git bash 프롬프트를 사용하고 있습니다. 지금 저를 괴롭히는 것은 LS를 입력할 때 모든 디렉터리가 파란색으로 나열된다는 것입니다.

LS를 입력할 때 디렉토리가 파란색과 다른 색상으로 나열되도록 git bash 쉘을 어떻게 변경합니까?

https://stackoverflow.com/questions/14049896/setting-colors-for-ls-in-git-bash-on-windows

Windows용 Ubuntu의 bash에서 색 구성표를 어떻게 변경합니까?

나는 색 구성표를 만들려고 노력했습니다.https://terminal.sexy그리고 http://ciembor.github.io/4bit/하지만 Windows의 Ubuntu에서 bash와 함께 작동하도록 내보내기를 할 수 없습니다.

boUoW의 색상을 사용자 정의하는 올바른 접근 방식은 무엇입니까?

Windows용 Ubuntu의 bash에서 색 구성표를 어떻게 변경합니까?

관련 정보