본문 바로가기
개발환경

[Env] Oh-My-Posh

by ds31x 2023. 6. 20.

Oh-My-Posh는 Command Line Interface(cli)에서 prompt 부분을 customize할 수 있게 해주는 custom prompt engine이다.

  • 유사한 것으로는 Oh-My-Zsh 이 있음 (사실 oh-my-zsh이 먼저고 이를 bash등에서 가능하도록 만들어준 것이 oh-my-posh임)
  • 다양한 정보를 보여주는 장점이 있지만... terminal을 처음 띄울 때 시간이 상당히 늘어난다. (Windows terminal의 tab도 마찬가지...)
  • 때문에 default theme를 그대로 사용하기보다 필요한 부분만으로 다시 구성하는 것을 권한다.

설명

prompt에서 배터리 현황, git에서의 branch, 이전 command의 수행에서 에러 발생 여부, python 버전 및 가상환경의 이름 등등의 정보를 다채로운 색상과 아이콘으로 꾸밀 수 있음.

다음 그림을 보면 확연히 다른 prompt를 볼 수 있다.

특히, oh-my-posh의 경우 bash와 PowerShell 등의 다양한 shell과 linux, mac, windows등의 다양한 OS를 지원하며, 문서화가 매우 잘 되어 있다. (제공되는 테마도 정말 많다.)

단, 대부분의 테마에서 Nerd Font 를 사용하므로 해당 폰트를 꼭 추가해야만 prompt가 정상적으로 보인다.


참고

WSL2에서 git을 사용할 때 shared drive에서는 git 관련 정보가 prompt에서 보이지 않는 문제가 있음.

  • 이를 해결하려면, Windows에도 git.exe가 있어야 하고, theme file에서 Git 설정 부분에서 native_fallback property를 true로 설정해야한다.
  • WSL2에만 git이 설치된 경우, windosw의 storage들에서는 git 관련 정보가 보이지 않기 때문 활용도가 떨어진다.
  • 더욱이 oh-my-posh에서는 native_fallback의 default 설정값이 false이기 때문에 windows에서 git을 설치하고 이를 바꿔줘야 함.

다음과 같이 git 설정 부분에서 properties > native_fallback 을 반드시 true로 변경할 것.

        {
          "background": "#fffb38",
          "background_templates": [
            "{{ if or (.Working.Changed) (.Staging.Changed) }}#FF9248{{ end }}",
            "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#ff4500{{ end }}",
            "{{ if gt .Ahead 0 }}#B388FF{{ end }}",
            "{{ if gt .Behind 0 }}#B388FF{{ end }}"
          ],
          "foreground": "#193549",
          "leading_diamond": "\ue0b6",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "branch_max_length": 25,
            "fetch_stash_count": true,
            "fetch_status": true,
            "fetch_upstream_icon": true,
            "native_fallback": true
          },
          "style": "powerline",
          "template": " {{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \ueb4b {{ .StashCount }}{{ end }} ",
          "trailing_diamond": "\ue0b4",
          "type": "git"
        },

관련 내용 URL : https://github.com/JanDeDobbeleer/oh-my-posh/issues/2097

 

Git status not working in WSL · Issue #2097 · JanDeDobbeleer/oh-my-posh

Code of Conduct I agree to follow this project's Code of Conduct What happened? Hi, I was previously running version 7.9.1 and noticed that the Git segment does not render in WSL when targeting a r...

github.com


관련자료

Oh My Posh의 공식 홈페이지의 설치 문서 (linux)임.

https://ohmyposh.dev/docs/installation/linux

 

Linux | Oh My Posh

Set up your terminal

ohmyposh.dev

 

다음은 Scott Hanselman 의 YouTube임.

  • PowerShell 을 이용한 설명이지만 Windows에서 Terminal 을 개선할 수 있는 방법을 확실히 알 수 있음.
  • 상당히 긴 편임.

https://youtu.be/VT2L1SXFq9U

 

728x90

'개발환경' 카테고리의 다른 글

[Env] PowerShell v7.3.5  (0) 2023.06.28
[Env] xterm: Font  (0) 2023.06.26
[Env] VSCode : Terminal Font 변경  (0) 2023.06.21
[Env] Environment Variable (환경변수)  (0) 2023.06.20
[Shell] env and Shebang line  (0) 2023.06.20