cantino / mcfly

Fly through your shell history. Great Scott!
MIT License
6.85k stars 178 forks source link

zsh: Partial incompatibility with romkatv/powerlevel10k instant prompt #157

Open volfyd opened 3 years ago

volfyd commented 3 years ago

Powerlevel10k instant prompt is a neat feature where a quite complex prompt can be initially displayed without fully loading .zshrc. During the loading of .zshrc, standard in is redirected to /dev/null.

https://github.com/romkatv/powerlevel10k/blob/master/README.md

When instant prompt is enabled, for the duration of Zsh initialization standard input is redirected to /dev/null and standard output with standard error are redirected to a temporary file. Once Zsh is fully initialized, standard file descriptors are restored and the content of the temporary file is printed out.

This causes problems with mcfly.

The command eval "$(mcfly init zsh)" runs the following as the first command:

# Ensure stdin is a tty
[[ -t 0 ]] || return

This causes the eval to return an error I think. I saw very odd behavior where the zsh prompt would load every other xterm I opened. The other half of the time, the powerlevel10k (p10k) wizard would open.

I was able to solve this by changing the command in .zshrc to

eval "$(mcfly init zsh)" < /dev/tty

I would say that the Powerlevel10k behavior is strange, but it is an exceptionally popular plugin so it may make sense to either document this problem or to code around it.

cantino commented 3 years ago

Does if [ -t 1 ]; then return 0; fi from https://github.com/cantino/mcfly/issues/154#issuecomment-856262557 fix it?

volfyd commented 3 years ago

@cantino That line is almost the opposite logic of the original logic. The original logic returns if FD 0 is NOT a TTY. The logic in

if [ -t 1 ]; then return 0; fi

is the opposite where it returns if FD 1 IS a TTY. I think it will break folks who do not have an unusual setup where the FD are being redirected.

cantino commented 3 years ago

Thank you @volfyd. I guess we want if [[ ! -t 0 ]]; then return 0; fi then?

stepanselyuk commented 3 years ago
[[ ! -o interactive ]] && return 0

this works for me

cantino commented 3 years ago

Can you see if https://github.com/cantino/mcfly/pull/164 fixes this?