From ea49b52970e14fad08ce7fbdebbfacae2648c352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Dammsh=C3=A4user?= Date: Thu, 12 Aug 2021 20:44:02 +0200 Subject: [PATCH 1/3] Update capture script See: https://github.com/jandamm/zsh-capture-completion/commit/2f530cff83e1f75ce5f0d749a9bd50d191c09db7 --- plugin/capture.zsh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugin/capture.zsh b/plugin/capture.zsh index 1202688..d6c9331 100755 --- a/plugin/capture.zsh +++ b/plugin/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 From 9e1dfff441d1eb8c92a86ffa8c5c67367e1cbd31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Dammsh=C3=A4user?= Date: Thu, 12 Aug 2021 21:22:09 +0200 Subject: [PATCH 2/3] Autload completion function --- {plugin => autoload}/capture.zsh | 0 {plugin => autoload}/zsh_completion.vim | 12 +++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) rename {plugin => autoload}/capture.zsh (100%) rename {plugin => autoload}/zsh_completion.vim (78%) diff --git a/plugin/capture.zsh b/autoload/capture.zsh similarity index 100% rename from plugin/capture.zsh rename to autoload/capture.zsh diff --git a/plugin/zsh_completion.vim b/autoload/zsh_completion.vim similarity index 78% rename from plugin/zsh_completion.vim rename to autoload/zsh_completion.vim index 1adcb81..918de0c 100644 --- a/plugin/zsh_completion.vim +++ b/autoload/zsh_completion.vim @@ -2,13 +2,16 @@ " Maintainer: Valodim Skywalker " Last Updated: 03 Oct 2013 -fun! zsh_completion#Complete(findstart, base) +let s:srcfile = globpath(&runtimepath, 'autoload/capture.zsh') +let s:hasSrcfile = len(s:srcfile) + +fun! zsh_completion#Complete(findstart, base) abort if a:findstart " locate the start of the word let l:line = getline('.') let l:pos = col('.') - 1 - while l:pos > 0 && l:line[l:pos - 1] =~ '\S' + while l:pos > 0 && l:line[l:pos - 1] =~? '\S' let l:pos -= 1 endwhile @@ -23,12 +26,11 @@ fun! zsh_completion#Complete(findstart, base) return l:pos else - let l:srcfile = globpath(&rtp, 'plugin/capture.zsh') - if len(l:srcfile) == 0 + if s:hasSrcfile == 0 return -1 endif - let s:out = system(l:srcfile . ' ' . shellescape(getline(".") . s:base) . ' ' . (col('.')+strlen(s:base)-1)) + let s:out = system(s:srcfile . ' ' . shellescape(getline('.') . s:base) . ' ' . (col('.')+strlen(s:base)-1)) let l:result = [] for item in split(s:out, '\r\n') let l:pieces = split(item, ' -- ') From c398d7c8e45ca127ba393bd24c3f907149a1964f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Dammsh=C3=A4user?= Date: Tue, 17 Aug 2021 13:22:04 +0200 Subject: [PATCH 3/3] Remove removing prompt twice --- autoload/capture.zsh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/autoload/capture.zsh b/autoload/capture.zsh index d6c9331..30877f5 100755 --- a/autoload/capture.zsh +++ b/autoload/capture.zsh @@ -9,8 +9,8 @@ zpty z zsh -i 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. +# the prompt should be disabled here (before init) in case a prompt theme has +# a verbose prompt zpty -w z "autoload add-zsh-hook" zpty -w z "add-zsh-hook -D precmd '*'" zpty -w z "add-zsh-hook -D preexec '*'" @@ -31,9 +31,6 @@ setopt rcquotes echo 'error initializing.' >&2 exit 2 } =( <<< ' -# no prompt! -PROMPT= - # load completion system autoload compinit compinit -d ~/.zcompdump_capture