From 4128a45ea3198b9dd7e1379e7a2b04ec92698777 Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 30 Oct 2017 21:52:03 +0800 Subject: [PATCH] Add complete script --- autoload/SpaceVim/bin/complete | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 autoload/SpaceVim/bin/complete diff --git a/autoload/SpaceVim/bin/complete b/autoload/SpaceVim/bin/complete new file mode 100755 index 000000000..767eb9c31 --- /dev/null +++ b/autoload/SpaceVim/bin/complete @@ -0,0 +1,35 @@ +#!/usr/bin/env expect + +log_user 0 +set prompt {/@} +set cmd [lindex $argv 0] + +# start bash with no startup files for clean env +spawn env INPUTRC=/dev/null PS1=$prompt bash --norc +expect $prompt + +# set some readline variables for consistent completion output +send "bind 'set show-all-if-ambiguous on'\r" +expect $prompt +send "bind 'set bell-style none'\r" +expect $prompt +send "bind 'set completion-query-items -1'\r" +expect $prompt +send "bind 'set page-completions off'\r" +expect $prompt +send "bind 'set completion-display-width 0'\r" +expect $prompt + +# run the completion +log $prompt +send "$cmd\t $prompt" +expect { + # multiple matches, printed on separate lines, followed by prompt + -re "^$cmd\r\n(.*)\r\n$prompt$cmd" { puts $expect_out(1,string) } + # single match, completed in-place + -re "^($cmd\[^ \]*) $prompt" { puts $expect_out(1,string) } + # single match, completed in-place, nospace + -re "^($cmd\[^ \]+) $prompt" { puts $expect_out(1,string) } + # no match + -re "^$cmd $prompt" { exit } +}