From 2f530cff83e1f75ce5f0d749a9bd50d191c09db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Dammsh=C3=A4user?= Date: Thu, 12 Aug 2021 21:03:11 +0200 Subject: [PATCH] Allow capture of completions/functions in zshrc I've tested this with the powerlevel10k prompt which needed some special handling. Depending on the plugins loaded in the zshrc this might also have some unwanted side effects --- capture.zsh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/capture.zsh b/capture.zsh index aecf3ab..c527e21 100755 --- a/capture.zsh +++ b/capture.zsh @@ -3,11 +3,24 @@ zmodload zsh/zpty || { echo 'error: missing module zsh/zpty' >&2; exit 1 } # spawn shell -zpty z zsh -f -i +zpty z zsh -i # line buffer for pty output local line +# swallow input of zshrc, disable hooks and disable PROMPT +# the prompt is disabled later as well but at least with powerlevel10k +# it needs to be disabled twice. +zpty -w z "autoload add-zsh-hook" +zpty -w z "add-zsh-hook -D precmd '*'" +zpty -w z "add-zsh-hook -D preexec '*'" +zpty -w z "PROMPT=" +zpty -w z "echo thisisalonganduniquestringtomarktheendoftheinit >/dev/null" +zpty -r z line +while [[ $line != *'thisisalonganduniquestringtomarktheendoftheinit'* ]]; do + zpty -r z line +done + setopt rcquotes () { zpty -w z source $1