zsh-snap
zsh-snap copied to clipboard
Run a blocking function after shell loaded, with `znap restart` and in general
At the end of my zshrc, I run a function that checks if a certificate is expired, and if so runs a command that prompts the user to enter a password and renew the certificate. This blocks the prompt loading, which is fine, however when running znap restart
, it will get stuck on "Validating dotfiles..." and not show any output, when actually what is happening is the renewal function is running with all of the stdout hidden. Ideally I want the restart to fully execute, then run the renewal function after everything is run.
Also, with a prompt like powerlevel10k, it would be nice to defer this function after that instant prompt as well, but for some reason it seems to conflict there as well so I disabled the instant prompt mechanism. I'm not sure if I just don't properly understand how I should run these kinds of functions, but some kind of guidance on how to do it properly with znap would be great.
I can't provide my specific example code, but it's roughly:
zstyle ':znap:*' repos-dir ~/.znap/data
[[ -f ~/.znap/znap.zsh ]] ||
git clone --depth 1 -- \
https://github.com/marlonrichert/zsh-snap.git ~/.znap
source ~/.znap/znap.zsh
znap source romkatv/powerlevel10k
znap source zsh-users/zsh-completions
# ... more plugins
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
check_certificate() {
if [[ check-if-cert-is-expired ]]; then
echo "Cert is expired, please renew!"
prompt-user-to-renew-cert-with-password
fi
}
check_certificate
Environment:
- OS: Linux
- Terminal: ssh
- Zsh version: 5.8.1
- Repo version: c76ca1b
runs a command that prompts the user to enter a password and renew the certificate.
Sorry, that’s currently not supported and I’m not sure I want to spend time on implementing that. znap restart
is mostly meant for novice users who are likely to accidentally the whole thing. Pull requests welcome, though.
But why would you want to run this whenever your shell starts up? A certificate has a set expiration date. After renewing the certificate, you can script, for example, a cron
job that runs on that date at a suitable time and sends you a reminder.
As a temporary workaround, try replacing your call to check_certificate
with
add-zsh-hook precmd check_certificate
I haven’t tested it, though.
I'm also unable to reproduce this:
% cd $(mktemp -d) % > .zshrc <<EOF
PS1='%# ' PS2= RPS2='%^'; setopt transientrprompt interactivecomments
zstyle ':znap:*' repos-dir $PWD/.znap/data
[[ -f $PWD/.znap/znap.zsh ]] ||
git clone --depth 1 -- https://github.com/marlonrichert/zsh-snap.git $PWD/.znap
source $PWD/.znap/znap.zsh
znap source romkatv/powerlevel10k
znap source zsh-users/zsh-completions
# ... more plugins
[[ ! -f $PWD/.p10k.zsh ]] || source $PWD/.p10k.zsh
check_certificate() {
if [[ check-if-cert-is-expired ]]; then
echo "Cert is expired, please renew!"
#prompt-user-to-renew-cert-with-password
fi
}
check_certificate
EOF
% env -i HOME=$PWD PATH=$PATH TERM=$TERM ${TERMINFO:+TERMINFO=$TERMINFO} zsh -d
Cloning into '/private/var/folders/24/37_vm48s2tz9bhmj1rzffvl40000gn/T/tmp.6vvOCYRH/.znap'...
remote: Enumerating objects: 47, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (45/45), done.
remote: Total 47 (delta 0), reused 9 (delta 0), pack-reused 0
Receiving objects: 100% (47/47), 23.58 KiB | 1.68 MiB/s, done.
Cloning into 'powerlevel10k'...
remote: Enumerating objects: 92, done.
remote: Counting objects: 100% (92/92), done.
remote: Compressing objects: 100% (78/78), done.
remote: Total 92 (delta 16), reused 51 (delta 10), pack-reused 0
Receiving objects: 100% (92/92), 343.28 KiB | 3.50 MiB/s, done.
Resolving deltas: 100% (16/16), done.
Cloning into 'zsh-completions'...
remote: Enumerating objects: 159, done.
remote: Counting objects: 100% (159/159), done.
remote: Compressing objects: 100% (154/154), done.
remote: Total 159 (delta 47), reused 44 (delta 3), pack-reused 0
Receiving objects: 100% (159/159), 365.48 KiB | 3.45 MiB/s, done.
Resolving deltas: 100% (47/47), done.
Cert is expired, please renew!
[Powerlevel10k wizard]
~ > znap restart
Validating dotfiles...
Restarting Zsh...
[WARNING]: Console output during zsh initialization detected.
When using Powerlevel10k with instant prompt, console output during zsh
initialization may indicate issues.
You can:
- Recommended: Change ~/.zshrc so that it does not perform console I/O
after the instant prompt preamble. See the link below for details.
* You will not see this error message again.
* Zsh will start quickly and prompt will update smoothly.
- Suppress this warning either by running p10k configure or by manually
defining the following parameter:
typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet
* You will not see this error message again.
* Zsh will start quickly but prompt will jump down after initialization.
- Disable instant prompt either by running p10k configure or by manually
defining the following parameter:
typeset -g POWERLEVEL9K_INSTANT_PROMPT=off
* You will not see this error message again.
* Zsh will start slowly.
- Do nothing.
* You will see this error message every time you start zsh.
* Zsh will start quickly but prompt will jump down after initialization.
For details, see:
https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt
-- console output produced during zsh initialization follows --
Cert is expired, please renew!
~ >
If you can make me a reproducible test case, then I'll reopen the issue. If I can't reproduce the issue, then I cannot fix it.