jonmosco / kube-ps1

Kubernetes prompt info for bash and zsh
Apache License 2.0
3.52k stars 351 forks source link

Running kube_ps1 in bash function returns blank #171

Closed eogden93 closed 9 months ago

eogden93 commented 1 year ago

I have a function in my .bash_profile

function kubeshell() {
    source /usr/bin/kube-ps1.sh
    PS1="[\u@\h \W $(kube_ps1)]\$ "
}

When I run this function it returns [root@0232a48ae63e home ]$ This is missing the colored output from kube_ps1

I've done some debugging and when I run $(kube_ps1) within the function it will return blank. However, running kube_ps1 manually returns (\033[38;5;4m⎈|\033[38;5;1mrancher-desktop:\033[38;5;6mN/A)

My setup is a 3.15 Alpine docker image running on M1 Mac using bash (not zsh)

roeniss commented 1 year ago

Same here.

# ~/.zshrc
source kube_ps1.sh
echo $(kube_ps1)

When I launched a new terminal, the echo message is empty. But If I source ~/.zshrc again, it shows the prompt text.

I guess kube-ps1 didn't update PS1 through precmd.

roeniss commented 1 year ago

by the way, https://github.com/jonmosco/kube-ps1/issues/168#issuecomment-1377737774 this trick works well. Put PROMPT='$(kube_ps1)'$PROMPT on last line in ~/.zshrc`.

eogden93 commented 1 year ago

by the way, #168 (comment) this trick works well. Put PROMPT='$(kube_ps1)'$PROMPT on last line in ~/.zshrc`.

This doesn't seem to be working using bash (not zsh) I get the output but its still not decoding the colors

roeniss commented 1 year ago

Aha. I'm using zsh.

jonmosco commented 9 months ago

Closing this issue. If problem persists, please check out the README