본문 바로가기
목차
개발환경

[Env] oh-my-posh에서 conda env prefix 없애기

by ds31x 2023. 6. 29.
728x90
반응형

Powershell에서 oh-my-posh를 설치하는 경우,
다음과 같은 형태로 conda의 환경을 나타내는 문자열이 앞에 보일 때가 있음.

(개인적으로 그냥 귀찮아서 놔두었는데... 계속 질문을 받은 터라. 지우는 방법을 정리함.)

위 그림에서 보이듯이 (base)가 prompt 앞에 보인다.

  • 사실 oh-my-posh 에서 python의 가상환경이 보이는 기능이 있어서 이는 중복된 정보이니 지우는게 낫다.

 

이 문제를 해결하려면, Power Shell의 profile을 수정하면 된다.

notepad $PROFILE 

 

참고로 $PROFILE은 powershell의 profile로 onedrive를 사용할 경우 다음과 같은 경로를 가르킴.

C:\Users\dsain\OneDrive\문서\PowerShell\Microsoft.PowerShell_profile.ps1

 

 

어째든 oh-my-posh 의 관련 설정 앞에 conda의 prompt에 환경을 출력하지 않도록 다음과 같이 기재.

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
If (Test-Path "C:\Users\dsain\miniconda3\Scripts\conda.exe") { `
    (& "C:\Users\dsain\miniconda3\Scripts\conda.exe" "shell.powershell" "hook") `
        | Out-String `
        | ? { $_ } `
        | Invoke-Expression `
}
#endregion

# remove conda's env name from prompt
conda config --set changeps1 False

# initialize oh-my-posh (must be last)
oh-my-posh init pwsh `
    --config "D:/lecture/mkdocs_site/docs/CE/oh_my_posh/test2.json" `
    | Invoke-Expression
  • 위의 내용에서 conda config --set changeps1 Falseenv출력을 없애주는 부분임.
  • 보기 좋게 하기 위해서 line continuation character 인 backtick(`)을 사용함.
  • oh-my-posh초기화하는 부분 이전에 있어야 함.
    (위의 예에선 맨 하단 line이 oh-my-posh 초기화 하는 부분임)
    그 위 부분은 conda관련 설정부분임.
    (windows에선 아직 conda를 사용함. mamba는 아직 적용을 안했음)

이후 다음과 같이 앞의 부분이 사라짐.


참고자료

https://ohmyposh.dev/docs/faq#conda-environment-name-displayed-in-front-of-the-prompt

 

FAQ | Oh My Posh

Before validating anything, make sure you're on the latest version of Oh My Posh and your terminal and shell are up-to-date.

ohmyposh.dev

 

728x90