romkatv / powerlevel10k

A Zsh theme
MIT License
45.5k stars 2.16k forks source link

[BUG] - prompt not showing due to terraform plugin #2598

Open juanmatias opened 6 months ago

juanmatias commented 6 months ago

Randomly prompt is not shown with zsh+ohmyzsh+powerlevel10k

What?

I'm using zsh+ohmyzsh+powerlevel10k on a Manjaro.

The problem is that from time to time shell doesn't show the prompt. This is fixed after a couple of restarts. Other shells start well.

Possible cause

If I remove the Terraform plugin from powerlevel10k it starts.

I'm removing it from .p10k.zsh from POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS variable.

Request for help

I am not sure how to dig into this to find the root cause. Could you guide me on how to debug this so I can find a fix?

Workaround

For now I have it deactivated.

Other info

❯ uname -a
Linux tufmanjaro 5.15.148-2-MANJARO #1 SMP PREEMPT Sat Feb 10 11:45:52 UTC 2024 x86_64 GNU/Linux

I have installed these packages:

romkatv commented 6 months ago

The problem is that from time to time shell doesn't show the prompt.

What does that look like?

juanmatias commented 6 months ago

hey @romkatv thanks for answering

at those times, when I start a terminal it remains blank

if I open a different shell (bash or fish), and from there I try to run zsh it hangs

adding set -xv I don't get to much info, except the word powerlevel and terraform.

first I disabled powerlevel10k, zsh started ok (with an ugly prompt :) )

so, following a hunch, I did a search in p10k config file, found terraform loaded under POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS and I commented the line. Then zsh started fine.

romkatv commented 6 months ago

Can you confirm that without terraform everything works but with terraform zsh hangs on start? If you try 3 times each, does it reproduce 100% of the time?

juanmatias commented 6 months ago

I'll try to reproduce this and collect data to do better debugging. Can you recommend anything in particular to take into account?

romkatv commented 6 months ago

Nothing in particular. Just a clear cause and effect: when I do X, Y happens, 100%.

juanmatias commented 6 months ago

@romkatv it happened again

While zsh hangs, I still can open fish and bash.

In the .p10k.zsh file, under typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( the option terraform is enabled (i.e. it is uncommented).

I added set -xv to the .zshrc file.

From bash I try to load zsh and it hangs. The last logs are:

+_p9k_set_prompt:34> _p9k__segment_name=terraform
+_p9k_set_prompt:35> local cond='$commands[terraform]'
+_p9k_set_prompt:36> [[ -z '$commands[terraform]' || -n /home/jdelacamara/.asdf/shims/terraform ]]
+_p9k_set_prompt:37> local disabled=_POWERLEVEL9K_TERRAFORM_DISABLED_DIR_PATTERN
+_p9k_set_prompt:38> [[ /home/jdelacamara !=  ]]
+_p9k_set_prompt:39> local val=''
+_p9k_set_prompt:40> [[ -n '' ]]
+_p9k_set_prompt:43> [[ terraform == custom_* ]]
+_p9k_set_prompt:45> ((  1  ))
+_p9k_set_prompt:46> prompt_terraform
+prompt_terraform:1> local ws=''
+prompt_terraform:2> [[ -z '' ]]

CTRL+C does not work. Only a killall -9 zsh finishes the process.

Full output: first-zsh-load.log

Then I comment the terraform line in .p10k.zsh under typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(.

This time when running zsh it works.

Full logs: first-zsh-load-with-commented-line.log

If I uncomment the line, zsh hangs again. And if comment it again zsh works.

romkatv commented 6 months ago

Thanks for the extra info.

It looks like zsh hangs trying to resolve ${${TF_DATA_DIR:-.terraform}:A}/environment. Could you confirm this? To do that, run the following command:

zsh -fc 'set -x; : $TF_DATA_DIR; \ls -ld -- ${TF_DATA_DIR:-.terraform}; : ${${TF_DATA_DIR:-.terraform}:A}'

You need to run this from the same directory in which you ran your previous tests when zsh was hanging on start.

What does the command print? Does it hang?

juanmatias commented 6 months ago

@romkatv I've run zsh from my home dir previously.

Here it is your command in the home dir:

❯ zsh -fc 'set -x; : $TF_DATA_DIR; \ls -ld -- ${TF_DATA_DIR:-.terraform}; : ${${TF_DATA_DIR:-.terraform}:A}'
+zsh:1> :
+zsh:1> ls -ld -- .terraform
ls: cannot access '.terraform': No such file or directory

It hangs here. But I can cancel with CTRL+C.

Btw, it makes sense not to have the .terraform dir here since it's my home dir.

romkatv commented 6 months ago

This is fascinating. Does the following command also hang?

zsh -fc 'cd && : ${${:-blah}:A}'
juanmatias commented 5 months ago

Today I started the laptop and is a day in which this is working. I activated the terraform plugin and it works. So, I tested the previous command again and it works:

❯ zsh -fc 'set -x; : $TF_DATA_DIR; \ls -ld -- ${TF_DATA_DIR:-.terraform}; : ${${TF_DATA_DIR:-.terraform}:A}'
+zsh:1> :
+zsh:1> ls -ld -- .terraform
ls: cannot access '.terraform': No such file or directory
+zsh:1> : /home/jdelacamara/.terraform
❯ 

It does not hang and return to the prompt.

Right now, the last command you sent also is working.

I'll do the same test when the problem shows up again.

Meanwhile, let me know if you think I can perform more tests.

Thank you!

romkatv commented 5 months ago

I don't think you need to perform any more tests. The previous test (https://github.com/romkatv/powerlevel10k/issues/2598#issuecomment-2002073262) indicates a very serious issue with your machine: realpath(3) hangs when you pass it ~/.terraform.

juanmatias commented 5 months ago

So, can I do something? I mean, if it is not possible I won't use terraform plugin... but if there is some kind of patch that I can create/test it would be great so I can collaborate to the project.

romkatv commented 5 months ago

If my diagnosis is correct, your machine has very serious issues. They aren't confined to terraform. Either the OS or the filesystem is malfunctioning.

juanmatias commented 4 months ago

@romkatv as per your diagnosis, I'm trying to find what problem I have (before go and reinstall)....

I found the point in which it breaks is in file /usr/share/zsh-theme-powerlevel10k/internal/p10k.zsh this line:

_p9k_read_word ${${TF_DATA_DIR:-.terraform}:A}/environment && ws=$_p9k__ret

under function prompt_terraform.

I tried this in the file:

    local TFDD=${TF_DATA_DIR:-.terraform}
    local TFDD2=${TFDD:A}

...and it fails anyway in the second line.

I'm trying to figure it out, but I left the comment here just in case you have an idea.

I created the .terraform dir but it fails again.

Thanks.

romkatv commented 4 months ago

I've misread https://github.com/romkatv/powerlevel10k/issues/2598#issuecomment-2003898102. Specifically, I've missed "not" in "It does not hang". Thus, my saying that you machine has a serious issue was false.

In your last command you say "breaks" and "fails". Do you mean "hangs" in both cases?