Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions plugin/capture.zsh → autoload/capture.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 '*'"
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
Expand All @@ -18,9 +31,6 @@ setopt rcquotes
echo 'error initializing.' >&2
exit 2
} =( <<< '
# no prompt!
PROMPT=

# load completion system
autoload compinit
compinit -d ~/.zcompdump_capture
Expand Down
12 changes: 7 additions & 5 deletions plugin/zsh_completion.vim → autoload/zsh_completion.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
" Maintainer: Valodim Skywalker <[email protected]>
" 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

Expand All @@ -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, ' -- ')
Expand Down