mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-12-30 00:03:56 +08:00
Fix and unify formatting and code-style
This commit is contained in:
parent
f860711cc5
commit
258e06c9ab
|
@ -28,22 +28,22 @@ function {
|
||||||
}
|
}
|
||||||
|
|
||||||
ZLE_AUTOSUGGEST_SUSPEND_WIDGETS=(
|
ZLE_AUTOSUGGEST_SUSPEND_WIDGETS=(
|
||||||
vi-cmd-mode vi-backward-char backward-char backward-word beginning-of-line
|
vi-cmd-mode vi-backward-char backward-char backward-word beginning-of-line
|
||||||
history-search-forward history-search-backward up-line-or-history
|
history-search-forward history-search-backward up-line-or-history
|
||||||
history-beginning-search-forward history-beginning-search-backward
|
history-beginning-search-forward history-beginning-search-backward
|
||||||
down-line-or-history history-substring-search-up history-substring-search-down
|
down-line-or-history history-substring-search-up history-substring-search-down
|
||||||
backward-kill-word
|
backward-kill-word
|
||||||
)
|
)
|
||||||
|
|
||||||
ZLE_AUTOSUGGEST_COMPLETION_WIDGETS=(
|
ZLE_AUTOSUGGEST_COMPLETION_WIDGETS=(
|
||||||
complete-word expand-or-complete expand-or-complete-prefix list-choices
|
complete-word expand-or-complete expand-or-complete-prefix list-choices
|
||||||
menu-complete reverse-menu-complete menu-expand-or-complete menu-select
|
menu-complete reverse-menu-complete menu-expand-or-complete menu-select
|
||||||
accept-and-menu-complete
|
accept-and-menu-complete
|
||||||
)
|
)
|
||||||
|
|
||||||
ZLE_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
ZLE_AUTOSUGGEST_ACCEPT_WIDGETS=(
|
||||||
vi-forward-char forward-char vi-forward-word forward-word vi-add-eol
|
vi-forward-char forward-char vi-forward-word forward-word vi-add-eol
|
||||||
vi-add-next vi-forward-blank-word end-of-line
|
vi-add-next vi-forward-blank-word end-of-line
|
||||||
)
|
)
|
||||||
|
|
||||||
autosuggest-pause() {
|
autosuggest-pause() {
|
||||||
|
@ -100,9 +100,9 @@ autosuggest-resume() {
|
||||||
|
|
||||||
autosuggest-start() {
|
autosuggest-start() {
|
||||||
if [[ -z $ZLE_DISABLE_AUTOSUGGEST && -n $functions[_zsh_highlight] ]]; then
|
if [[ -z $ZLE_DISABLE_AUTOSUGGEST && -n $functions[_zsh_highlight] ]]; then
|
||||||
if [[ ${ZSH_HIGHLIGHT_HIGHLIGHTERS[(i)autosuggest]} -gt ${#ZSH_HIGHLIGHT_HIGHLIGHTERS} ]];then
|
if [[ ${ZSH_HIGHLIGHT_HIGHLIGHTERS[(i)autosuggest]} -gt ${#ZSH_HIGHLIGHT_HIGHLIGHTERS} ]]; then
|
||||||
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(autosuggest)
|
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(autosuggest)
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
autosuggest-resume
|
autosuggest-resume
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ _zsh_highlight_autosuggest_highlighter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
autosuggest-insert-or-space() {
|
autosuggest-insert-or-space() {
|
||||||
setopt localoptions noshwordsplit noksharrays
|
setopt localoptions noshwordsplit noksharrays
|
||||||
if [[ $LBUFFER == *$'\012'* ]] || (( PENDING )); then
|
if [[ $LBUFFER == *$'\012'* ]] || (( PENDING )); then
|
||||||
# Editing multiline buffer or pasting a chunk of text, pause
|
# Editing multiline buffer or pasting a chunk of text, pause
|
||||||
autosuggest-suspend
|
autosuggest-suspend
|
||||||
|
@ -163,13 +163,13 @@ autosuggest-insert-or-space() {
|
||||||
autosuggest-backward-delete-char() {
|
autosuggest-backward-delete-char() {
|
||||||
if (( $#LBUFFER > 1 )); then
|
if (( $#LBUFFER > 1 )); then
|
||||||
setopt localoptions noshwordsplit noksharrays
|
setopt localoptions noshwordsplit noksharrays
|
||||||
if [[ $LBUFFER = *$'\012'* || $LASTWIDGET != (self-insert|magic-space|backward-delete-char) ]]; then
|
if [[ $LBUFFER = *$'\012'* || $LASTWIDGET != (self-insert|magic-space|backward-delete-char) ]]; then
|
||||||
LBUFFER="$LBUFFER[1,-2]"
|
LBUFFER="$LBUFFER[1,-2]"
|
||||||
else
|
else
|
||||||
((--CURSOR))
|
((--CURSOR))
|
||||||
autosuggest-invalidate-highlight-cache
|
autosuggest-invalidate-highlight-cache
|
||||||
zle .history-beginning-search-forward || RBUFFER=''
|
zle .history-beginning-search-forward || RBUFFER=''
|
||||||
fi
|
fi
|
||||||
autosuggest-highlight-suggested-text
|
autosuggest-highlight-suggested-text
|
||||||
else
|
else
|
||||||
zle .kill-whole-line
|
zle .kill-whole-line
|
||||||
|
@ -237,11 +237,11 @@ autosuggest-tab() {
|
||||||
}
|
}
|
||||||
|
|
||||||
autosuggest-accept-suggestion() {
|
autosuggest-accept-suggestion() {
|
||||||
if [[ AUTOSUGGESTION_ACCEPT_RIGHT_ARROW -eq 1 && "$WIDGET" == 'forward-char' ]]; then
|
if [[ AUTOSUGGESTION_ACCEPT_RIGHT_ARROW -eq 1 && "$WIDGET" == 'forward-char' ]]; then
|
||||||
zle autosuggest-end-of-line-orig "$@"
|
zle autosuggest-end-of-line-orig "$@"
|
||||||
else
|
else
|
||||||
zle autosuggest-${WIDGET}-orig "$@"
|
zle autosuggest-${WIDGET}-orig "$@"
|
||||||
fi
|
fi
|
||||||
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
|
||||||
autosuggest-invalidate-highlight-cache
|
autosuggest-invalidate-highlight-cache
|
||||||
autosuggest-highlight-suggested-text
|
autosuggest-highlight-suggested-text
|
||||||
|
|
|
@ -48,7 +48,7 @@ zstyle -d ':completion:*' list-colors
|
||||||
zmodload zsh/zutil
|
zmodload zsh/zutil
|
||||||
|
|
||||||
# override compadd (this our hook)
|
# override compadd (this our hook)
|
||||||
compadd () {
|
compadd() {
|
||||||
|
|
||||||
# check if any of -O, -A or -D are given
|
# check if any of -O, -A or -D are given
|
||||||
if [[ ${@[1,(i)(-|--)]} == *-(O|A|D)\ * ]]; then
|
if [[ ${@[1,(i)(-|--)]} == *-(O|A|D)\ * ]]; then
|
||||||
|
|
|
@ -45,7 +45,7 @@ handle-request() {
|
||||||
done
|
done
|
||||||
if ! (( read_something )); then
|
if ! (( read_something )); then
|
||||||
print "connection with fd $connection closed" >&2
|
print "connection with fd $connection closed" >&2
|
||||||
unset fds[$connection]
|
unset fds[$connection]
|
||||||
exec {connection}>&- # free the file descriptor
|
exec {connection}>&- # free the file descriptor
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
31
install
31
install
|
@ -3,8 +3,7 @@
|
||||||
# Install script for zsh-autocomplete
|
# Install script for zsh-autocomplete
|
||||||
|
|
||||||
config="$HOME/.zshrc"
|
config="$HOME/.zshrc"
|
||||||
for config in "$HOME/.zshrc" "$ZDOTDIR/.zshrc" "$1"
|
for config in "$HOME/.zshrc" "$ZDOTDIR/.zshrc" "$1"; do
|
||||||
do
|
|
||||||
echo $config
|
echo $config
|
||||||
#first checks if ~/.zshrc file exists and is readable
|
#first checks if ~/.zshrc file exists and is readable
|
||||||
if [ -r "$config" ]; then
|
if [ -r "$config" ]; then
|
||||||
|
@ -17,28 +16,28 @@ done
|
||||||
|
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
SOURCE="${BASH_SOURCE[0]}"
|
||||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
SOURCE="$(readlink "$SOURCE")"
|
SOURCE="$(readlink "$SOURCE")"
|
||||||
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
||||||
done
|
done
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
||||||
|
|
||||||
# appends the string to $config (usually ~/.zshrc) file
|
# appends the string to $config (usually ~/.zshrc) file
|
||||||
cat >> "$config" << EOF
|
cat >> "$config" <<-EOF
|
||||||
|
|
||||||
# Setup zsh-autosuggestions
|
# Setup zsh-autosuggestions
|
||||||
source $DIR/autosuggestions.zsh
|
source $DIR/autosuggestions.zsh
|
||||||
|
|
||||||
# Enable autosuggestions automatically
|
# Enable autosuggestions automatically
|
||||||
zle-line-init() {
|
zle-line-init() {
|
||||||
zle autosuggest-start
|
zle autosuggest-start
|
||||||
}
|
}
|
||||||
|
|
||||||
zle -N zle-line-init
|
zle -N zle-line-init
|
||||||
|
|
||||||
# use ctrl+t to toggle autosuggestions(hopefully this wont be needed as
|
# use ctrl+t to toggle autosuggestions(hopefully this wont be needed as
|
||||||
# zsh-autosuggestions is designed to be unobtrusive)
|
# zsh-autosuggestions is designed to be unobtrusive)
|
||||||
bindkey '^T' autosuggest-toggle
|
bindkey '^T' autosuggest-toggle
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo "\nSetup completed successfully!\n"
|
echo "\nSetup completed successfully!\n"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user