mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2025-12-08 15:32:31 +01:00
restructure to make it work with antigen
This commit is contained in:
parent
ebe4cf251a
commit
aa81de0ba1
4 changed files with 3 additions and 3 deletions
40
lib/completion-client.zsh
Executable file
40
lib/completion-client.zsh
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env zsh
|
||||
zmodload zsh/net/socket
|
||||
|
||||
AUTOSUGGEST_SERVER_SCRIPT="${0:a:h}/lib/completion-server.zsh"
|
||||
|
||||
autosuggest-ensure-server() {
|
||||
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 [[ ! -d $server_dir || ! -r $pid_file ]] || ! kill -0 $(<$pid_file) &> /dev/null; then
|
||||
if which setsid &> /dev/null; then
|
||||
setsid zsh $AUTOSUGGEST_SERVER_SCRIPT $server_dir $pid_file $socket_path &!
|
||||
else
|
||||
zsh $AUTOSUGGEST_SERVER_SCRIPT $server_dir $pid_file $socket_path &!
|
||||
fi
|
||||
fi
|
||||
|
||||
autosuggest-server-connect
|
||||
}
|
||||
|
||||
autosuggest-server-connect() {
|
||||
unset ZLE_AUTOSUGGEST_CONNECTION
|
||||
|
||||
integer remaining_tries=10
|
||||
while (( --remaining_tries )) && ! zsocket $socket_path &>/dev/null; do
|
||||
sleep 0.3
|
||||
done
|
||||
|
||||
[[ -z $REPLY ]] && return 1
|
||||
|
||||
ZLE_AUTOSUGGEST_CONNECTION=$REPLY
|
||||
}
|
||||
|
||||
autosuggest-send-request() {
|
||||
[[ -z $ZLE_AUTOSUGGEST_CONNECTION ]] && return 1
|
||||
setopt local_options noglob
|
||||
print -u $ZLE_AUTOSUGGEST_CONNECTION - $1 &> /dev/null || return 1
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue