zshrc export GPG_TTY=$(tty) says not a tty

tty command requires that stdin is attached to a terminal. When using Powerlevel10k, stdin is redirected from /dev/null when Instant Prompt is activated and until Zsh is fully initialized. This is explained in more detail in Powerlevel10k FAQ.

To solve this problem you can either move export GPG_TTY=$(tty) to the top of ~/.zshrc so that it executes before Instant Prompt is activated, or (better!) use export GPG_TTY=$TTY. The latter version will work anywhere and it's over 1000 times faster. TTY is a special parameter set by Zsh very early during initialization. It gives you access to the terminal even when stdin might be redirected.


I solved it so, just sharing it with others.

I moved the export GPG_TTY=$(tty) to top. Specifically above the p10k instant prompt initialization. I don't know but if I export tty after that script is executed the tty is not available. Anyways, I am not an expert in the field but it just solves the issue for me and I hope it does for you too.