Refactored completion server to use zsocket
This commit is contained in:
@@ -6,8 +6,32 @@
|
||||
# }
|
||||
# zle -N zle-line-init
|
||||
# ```
|
||||
# zmodload zsh/zpty
|
||||
#
|
||||
zmodload zsh/net/socket
|
||||
|
||||
AUTOSUGGEST_SERVER_SCRIPT="${0:a:h}/completion-server.zsh"
|
||||
|
||||
# function {
|
||||
# [[ -n $ZLE_DISABLE_AUTOSUGGEST ]] && return
|
||||
# setopt local_options no_hup
|
||||
|
||||
# local server_dir="/tmp/zsh-autosuggest-$USER"
|
||||
# local pid_file="$server_dir/pid"
|
||||
# local socket_path="$server_dir/socket"
|
||||
|
||||
# if ! [[ -S $socket_path && -r $pid_file ]] || ! kill -0 $(<$pid_file) &>/dev/null; then
|
||||
# # start server
|
||||
# zsh $AUTOSUGGEST_SERVER_SCRIPT $server_dir $pid_file $socket_path &!
|
||||
# fi
|
||||
|
||||
# integer remaining_tries=10
|
||||
# # wait until the process is listening
|
||||
# while ! [[ -d $server_dir && -r $pid_file ]] || ! kill -0 $(<$pid_file) &> /dev/null; do
|
||||
# (( --remaining_tries )) || break
|
||||
# sleep 0.3
|
||||
# done
|
||||
|
||||
# ZLE_AUTOSUGGEST_SOCKET=$socket_path
|
||||
# }
|
||||
|
||||
ZLE_AUTOSUGGEST_PAUSE_WIDGETS=(
|
||||
vi-cmd-mode vi-backward-char backward-char backward-word beginning-of-line
|
||||
@@ -146,9 +170,15 @@ paused-autosuggest-self-insert() {
|
||||
}
|
||||
|
||||
autosuggest-first-completion() {
|
||||
local cursor=$CURSOR
|
||||
zle .complete-word || return 1
|
||||
CURSOR=$cursor
|
||||
zsocket $ZLE_AUTOSUGGEST_SOCKET &>/dev/null || return 1
|
||||
local connection=$REPLY
|
||||
local completion
|
||||
print -u $connection $LBUFFER
|
||||
while read -u $connection completion; do
|
||||
RBUFFER=" $completion"
|
||||
break
|
||||
done
|
||||
exec {connection}>&-
|
||||
}
|
||||
|
||||
show-suggestion() {
|
||||
|
||||
Reference in New Issue
Block a user