Compare commits

...

32 Commits

Author SHA1 Message Date
Michael Robinson
5f13490bae Reverted 9e710593e3 2014-12-09 15:53:40 +13:00
Michael Robinson
1be4a54048 Merge pull request #35 from wgallios/master
Created simple install sh script
2014-12-09 15:52:38 +13:00
Michael Robinson
7446059f63 Merge pull request #31 from maksimr/patch-1
fix:Add autosuggest to highlighters list only once
2014-12-09 15:45:18 +13:00
Michael Robinson
71a7154815 Removed "unmaintained" message! 2014-12-09 15:39:55 +13:00
William Gallios
9e710593e3 updates to readme 2014-11-21 13:59:25 -08:00
William Gallios
0d9aabedb2 updated readme for new install script 2014-11-21 13:54:47 -08:00
William Gallios
32fb7930d8 created simple install script 2014-11-21 13:51:19 -08:00
Thiago de Arruda
0d36d4ccdd Add alpha-quality software warning 2014-11-05 07:51:26 -03:00
Thiago de Arruda
cbb0963896 Merge pull request #34 from CoolOppo/patch-1
Removed Shelr demo link because it died
2014-10-01 23:22:01 -03:00
CoolOppo
683b48b644 Removed Shelr demo link because it died 2014-10-01 21:20:52 -04:00
Thiago de Arruda
85739dbe76 Disable autosuggestion server startup.
The server is not working even in zsh5. Disable it until fixed.
2014-09-22 10:08:24 -03:00
Maksim Ryzhikov
6dbb419a7a fix:Add autosuggest to highlighters list only once 2014-08-11 10:26:39 +04:00
Thiago de Arruda
bd11c34e84 Merge pull request #16 from piecioshka/master
Create automatic command for plugin setup
2014-03-14 08:03:20 -02:00
Thiago de Arruda
0cc05bd08e Merge pull request #20 from mihaisucan/master
add a config for RIGHT arrow to accept the suggestion, like in fish
2014-03-14 08:02:05 -02:00
Mihai Sucan
824b9be13f add autosuggestions.plugin.zsh to get this repo working with antigen 2014-02-25 22:45:29 +02:00
Mihai Sucan
1cbd78c850 add a config for RIGHT arrow to accept the suggestion, like in fish 2014-02-23 22:54:31 +02:00
Thiago de Arruda
ebe4cf251a Merge pull request #17 from ajkaanbal/master
Suspend autosuggest on 'history-substring-search-up' and 'history-substr...
2014-02-18 12:11:14 -02:00
Ricardo M. Vilchis
7e69ddda7f Suspend autosuggest on 'history-substring-search-up' and 'history-substring-search-down' (zsh-history-substring-plugin commands). Accept on 'end-of-line' (Ctrl-e or END key) 2014-01-31 08:58:28 -06:00
piecioshka
5dff7a69f1 start label with big letter 2014-01-25 23:49:29 +01:00
piecioshka
c5567cf371 add label for zsh-autosuggestions 2014-01-25 23:47:40 +01:00
piecioshka
b18f01a256 fix end of file 2014-01-25 23:44:37 +01:00
tarruda
a29e838cdf Merge pull request #11 from dreadatour/master
Add plugin config variables
2013-12-04 15:31:36 -08:00
Vladimir Rudnyh
48f03e2b0c Suspend autosuggest on 'history-beginning-search-backward' and 'history-beginning-search-forward' commands 2013-12-04 23:07:24 +04:00
Vladimir Rudnyh
ea19b7bcf8 Add highlight color config variables 2013-12-03 23:45:56 +04:00
Vladimir Rudnyh
196cfa0eb0 Remove spaces at the end of lines 2013-12-03 23:25:52 +04:00
Thiago de Arruda
8af98f7d29 Validate original widget name when restoring on
autosuggest-pause
2013-11-08 11:49:33 -03:00
Thiago de Arruda
6ddbde147f Fixed syntax highlight in README code snippet 2013-11-08 08:24:02 -03:00
Thiago de Arruda
7d737e3cc8 Fixed accept-line and motion widgets integration
with zsh-syntax-highlighting
2013-11-08 08:20:57 -03:00
Thiago de Arruda
a0d6493f34 Update documentation 2013-11-07 20:17:10 -03:00
Thiago de Arruda
7cb87a8a55 Integrate with zsh-syntax-highlighting 2013-11-07 20:12:33 -03:00
Thiago de Arruda
936056fd9b Refactored, only use completion server on
zsh > 5.0.3(where the zle -F issue will be fixed)
2013-11-07 18:42:17 -03:00
Thiago de Arruda
a6f53879ae Direct less frequent log messages to stderr for
easier debugging
2013-10-30 08:36:53 -03:00
6 changed files with 205 additions and 112 deletions

View File

@@ -1,22 +1,32 @@
# zsh-autosuggestions # zsh-autosuggestions
> [Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh. > [Fish](http://fishshell.com/)-like fast/unobtrusive autosuggestions for zsh.
> [Shelr demo](http://shelr.tv/records/527007a99660803c5d000048).
## Installation ## Installation
```zsh
git clone git://github.com/tarruda/zsh-autosuggestions ~/.zsh-autosuggestions
cat >> ~/.zshrc << "EOF"
source ~/.zsh-autosuggestions/autosuggestions.zsh
# Enable autosuggestions automatically
zle-line-init() {
zle autosuggest-start
}
zle -N zle-line-init
# use ctrl+t to toggle autosuggestions(hopefully this wont be needed)
bindkey '^T' autosuggest-toggle
# use ctrl+f to accept a suggested word
bindkey '^F' autosuggest-accept-suggested-word
EOF
``` ```
$ git clone git://github.com/tarruda/zsh-autosuggestions ~/.zsh-autosuggestions
sh .zsh-autosuggestions/install
```
Any widget that moves the cursor to the right(forward-word, forward-char...)
will accept parts of the suggested text. For example, vi-mode users can do
this:
```sh
# Accept suggestions without leaving insert mode
bindkey '^f' vi-forward-word
# or
bindkey '^f' vi-forward-blank-word
```
Emacs-mode users can simply use alt+f which is bound to forward-word
The [zsh-history-substring-search](https://github.com/zsh-users/zsh-history-substring-search)
plugin is also recommended.
## Configuration
You may override default global config variables after plugin load.
- `AUTOSUGGESTION_HIGHLIGHT_COLOR`: suggestion highlight color, default is `'fg=8'`.
- `AUTOSUGGESTION_HIGHLIGHT_CURSOR`: highlight word after cursor or not. Must be integer value `1` or `0`, default is `1`.

1
autosuggestions.plugin.zsh Symbolic link
View File

@@ -0,0 +1 @@
autosuggestions.zsh

View File

@@ -11,15 +11,28 @@ zmodload zsh/net/socket
source "${0:a:h}/completion-client.zsh" source "${0:a:h}/completion-client.zsh"
# configuration variables
AUTOSUGGESTION_HIGHLIGHT_COLOR='fg=8'
AUTOSUGGESTION_HIGHLIGHT_CURSOR=1
function { function {
[[ -n $ZLE_DISABLE_AUTOSUGGEST ]] && return if [[ -n $ZLE_DISABLE_AUTOSUGGEST ]]; then
autosuggest-ensure-server ZSH_HIGHLIGHT_HIGHLIGHTERS=()
return
fi
autoload -U is-at-least
# if is-at-least 5.0.3; then
# autosuggest-ensure-server
# fi
} }
ZLE_AUTOSUGGEST_PAUSE_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
down-line-or-history history-beginning-search-forward history-beginning-search-backward
down-line-or-history history-substring-search-up history-substring-search-down
backward-kill-word
) )
ZLE_AUTOSUGGEST_COMPLETION_WIDGETS=( ZLE_AUTOSUGGEST_COMPLETION_WIDGETS=(
@@ -28,25 +41,31 @@ menu-complete reverse-menu-complete menu-expand-or-complete menu-select
accept-and-menu-complete accept-and-menu-complete
) )
ZLE_AUTOSUGGEST_ACCEPT_WIDGETS=(
vi-forward-char forward-char vi-forward-word forward-word vi-add-eol
vi-add-next vi-forward-blank-word end-of-line
)
autosuggest-pause() { autosuggest-pause() {
[[ -z $ZLE_AUTOSUGGESTING ]] && return [[ -z $ZLE_AUTOSUGGESTING ]] && return
unset ZLE_AUTOSUGGESTING unset ZLE_AUTOSUGGESTING
local widget local widget
# When autosuggestions are disabled, kill the unmaterialized part # When autosuggestions are disabled, kill the unmaterialized part
RBUFFER='' RBUFFER=''
zle -A self-insert autosuggest-paused-self-insert zle -A autosuggest-paused-self-insert self-insert
zle -A .magic-space magic-space zle -A autosuggest-magic-space-orig magic-space
zle -A .backward-delete-char backward-delete-char zle -A autosuggest-backward-delete-char-orig backward-delete-char
zle -A .accept-line accept-line zle -A autosuggest-accept-line-orig accept-line
for widget in $ZLE_AUTOSUGGEST_PAUSE_WIDGETS; do for widget in $ZLE_AUTOSUGGEST_ACCEPT_WIDGETS $ZLE_AUTOSUGGEST_SUSPEND_WIDGETS $ZLE_AUTOSUGGEST_COMPLETION_WIDGETS; do
[[ -z $widgets[$widget] || -z $widgets[autosuggest-${widget}-orig] ]] &&\
continue
eval "zle -A autosuggest-${widget}-orig ${widget}" eval "zle -A autosuggest-${widget}-orig ${widget}"
done done
for widget in $ZLE_AUTOSUGGEST_COMPLETION_WIDGETS; do
eval "zle -A autosuggest-${widget}-orig $widget"
done
autosuggest-highlight-suggested-text autosuggest-highlight-suggested-text
zle -F $ZLE_AUTOSUGGEST_CONNECTION if [[ -n $ZLE_AUTOSUGGEST_CONNECTION ]]; then
zle -F $ZLE_AUTOSUGGEST_CONNECTION
fi
} }
autosuggest-resume() { autosuggest-resume() {
@@ -54,90 +73,106 @@ autosuggest-resume() {
ZLE_AUTOSUGGESTING=1 ZLE_AUTOSUGGESTING=1
local widget local widget
# Replace prediction widgets by versions that will also highlight RBUFFER # Replace prediction widgets by versions that will also highlight RBUFFER
zle -N self-insert autosuggest-insert-or-space zle -A autosuggest-insert-or-space self-insert
zle -N magic-space autosuggest-insert-or-space zle -A autosuggest-insert-or-space magic-space
zle -N backward-delete-char autosuggest-backward-delete-char zle -A autosuggest-backward-delete-char backward-delete-char
zle -N accept-line autosuggest-accept-line zle -A autosuggest-accept-line accept-line
# Hook into some default widgets that should pause autosuggestion # Hook into some default widgets that should suspend autosuggestion
# automatically # automatically
for widget in $ZLE_AUTOSUGGEST_PAUSE_WIDGETS; do for widget in $ZLE_AUTOSUGGEST_ACCEPT_WIDGETS; do
eval "zle -A $widget autosuggest-${widget}-orig; \ [[ -z $widgets[$widget] ]] && continue
zle -A autosuggest-suspend $widget" eval "zle -A autosuggest-accept-suggestion $widget"
done done
# Hook into completion widgets to handle suggestions after completions for widget in $ZLE_AUTOSUGGEST_SUSPEND_WIDGETS; do
[[ -z $widgets[$widget] ]] && continue
eval "zle -A autosuggest-suspend $widget"
done
# Hook into completion widgets to trim RBUFFER before completion
for widget in $ZLE_AUTOSUGGEST_COMPLETION_WIDGETS; do for widget in $ZLE_AUTOSUGGEST_COMPLETION_WIDGETS; do
eval "zle -A $widget autosuggest-${widget}-orig; \ [[ -z $widgets[$widget] ]] && continue
zle -A autosuggest-tab $widget" eval "zle -A autosuggest-tab $widget"
done done
if [[ $BUFFER != '' ]]; then
autosuggest-request-suggestion
fi
if [[ -n $ZLE_AUTOSUGGEST_CONNECTION ]]; then if [[ -n $ZLE_AUTOSUGGEST_CONNECTION ]]; then
# install listen for suggestions asynchronously # install listen for suggestions asynchronously
zle -F $ZLE_AUTOSUGGEST_CONNECTION autosuggest-pop-suggestion zle -Fw $ZLE_AUTOSUGGEST_CONNECTION autosuggest-pop-suggestion
fi fi
} }
autosuggest-start() { autosuggest-start() {
if [[ -z $ZLE_DISABLE_AUTOSUGGEST && -n $functions[_zsh_highlight] ]]; then
if [[ ${ZSH_HIGHLIGHT_HIGHLIGHTERS[(i)autosuggest]} -gt ${#ZSH_HIGHLIGHT_HIGHLIGHTERS} ]];then
ZSH_HIGHLIGHT_HIGHLIGHTERS+=(autosuggest)
fi
fi
autosuggest-resume autosuggest-resume
zle recursive-edit
integer rv=$?
autosuggest-pause
zle -A .self-insert self-insert
(( rv )) || zle accept-line
return rv
} }
# Toggles autosuggestions on/off # Toggles autosuggestions on/off
autosuggest-toggle() { autosuggest-toggle() {
if [[ -n $ZLE_AUTOSUGGESTING ]]; then if [[ -n $ZLE_AUTOSUGGESTING ]]; then
autosuggest-pause autosuggest-pause
zle -A autosuggest-self-insert-orig self-insert
else else
autosuggest-resume autosuggest-resume
fi fi
} }
autosuggest-highlight-suggested-text() { autosuggest-highlight-suggested-text() {
if [[ -n $ZLE_AUTOSUGGESTING ]]; then if (( $+functions[_zsh_highlight_buffer_modified] > 0 )); then
local color='fg=8' _zsh_highlight
[[ -n $AUTOSUGGESTION_HIGHLIGHT_COLOR ]] &&\
color=$AUTOSUGGESTION_HIGHLIGHT_COLOR
region_highlight=("$(( $CURSOR + 1 )) $(( $CURSOR + $#RBUFFER )) $color")
else else
region_highlight=() region_highlight=()
_zsh_highlight_autosuggest_highlighter
fi fi
} }
_zsh_highlight_autosuggest_highlighter_predicate() {
[[ -n $ZLE_AUTOSUGGESTING ]] && (( $#RBUFFER > 0 ))
}
_zsh_highlight_autosuggest_highlighter() {
region_highlight+=("$(( $CURSOR + $AUTOSUGGESTION_HIGHLIGHT_CURSOR )) $(( $CURSOR + $#RBUFFER )) $AUTOSUGGESTION_HIGHLIGHT_COLOR")
}
autosuggest-insert-or-space() { autosuggest-insert-or-space() {
setopt localoptions noshwordsplit noksharrays
if [[ $LBUFFER == *$'\012'* ]] || (( PENDING )); then if [[ $LBUFFER == *$'\012'* ]] || (( PENDING )); then
# Editing a multiline buffer or pasting in a chunk of text, dont # Editing multiline buffer or pasting a chunk of text, pause
# autosuggest autosuggest-suspend
zle .$WIDGET "$@"
elif [[ ${RBUFFER[1]} == ${KEYS[-1]} ]]; then
# Same as what's typed, just move on
((++CURSOR))
autosuggest-highlight-suggested-text
else
LBUFFER="$LBUFFER$KEYS"
autosuggest-request-suggestion
fi
}
autosuggest-backward-delete-char() {
if ! (( $CURSOR )); then
zle .kill-whole-line
return return
fi fi
if [[ $LBUFFER == *$'\012'* || $LASTWIDGET != (self-insert|magic-space|backward-delete-char) ]]; then if [[ ${RBUFFER[1]} == ${KEYS[-1]} ]]; then
# When editing a multiline buffer or if the last widget was e.g. a motion, # Same as what's typed, just move on
# then probably the intent is to actually edit the line, not change the ((++CURSOR))
# search prefix. autosuggest-invalidate-highlight-cache
LBUFFER="$LBUFFER[1,-2]"
else else
((--CURSOR)) LBUFFER="$LBUFFER$KEYS"
zle .history-beginning-search-forward || RBUFFER='' if [[ $LASTWIDGET == (self-insert|magic-space|backward-delete-char) || $LASTWIDGET == (complete-word|accept-*|zle-line-init) ]]; then
if ! zle .history-beginning-search-backward; then
RBUFFER=''
if [[ ${KEYS[-1]} != ' ' ]]; then
autosuggest-send-request ${LBUFFER}
fi
fi
fi
fi
autosuggest-highlight-suggested-text
}
autosuggest-backward-delete-char() {
if (( $#LBUFFER > 1 )); then
setopt localoptions noshwordsplit noksharrays
if [[ $LBUFFER = *$'\012'* || $LASTWIDGET != (self-insert|magic-space|backward-delete-char) ]]; then
LBUFFER="$LBUFFER[1,-2]"
else
((--CURSOR))
autosuggest-invalidate-highlight-cache
zle .history-beginning-search-forward || RBUFFER=''
fi
autosuggest-highlight-suggested-text
else
zle .kill-whole-line
fi fi
} }
@@ -145,17 +180,20 @@ autosuggest-backward-delete-char() {
# section when the user accepts the line # section when the user accepts the line
autosuggest-accept-line() { autosuggest-accept-line() {
RBUFFER='' RBUFFER=''
region_highlight=() if ! (( $+functions[_zsh_highlight_buffer_modified] )); then
# Only clear the colors if the user doesn't have zsh-highlight installed
region_highlight=()
fi
zle .accept-line zle .accept-line
} }
autosuggest-paused-self-insert() { autosuggest-paused-self-insert() {
if [[ $RBUFFER == '' ]]; then if [[ $RBUFFER == '' ]]; then
# Resume autosuggestions when inserting at the end of the line # Resume autosuggestions when inserting at the end of the line
autosuggest-enable autosuggest-resume
zle autosuggest-modify zle self-insert
else else
zle .self-insert zle autosuggest-self-insert-orig
fi fi
} }
@@ -187,18 +225,6 @@ autosuggest-pop-suggestion() {
zle -Rc zle -Rc
} }
autosuggest-request-suggestion() {
if (( $CURSOR == 0 )) || [[ ${LBUFFER[-1]} == ' ' ]]; then
RBUFFER=''
return
fi
[[ -n $ZLE_DISABLE_AUTOSUGGEST || $LBUFFER == '' ]] && return
zle .history-beginning-search-backward ||\
autosuggest-first-completion ${LBUFFER}
autosuggest-highlight-suggested-text
}
autosuggest-suspend() { autosuggest-suspend() {
autosuggest-pause autosuggest-pause
zle autosuggest-${WIDGET}-orig "$@" zle autosuggest-${WIDGET}-orig "$@"
@@ -210,19 +236,44 @@ autosuggest-tab() {
autosuggest-highlight-suggested-text autosuggest-highlight-suggested-text
} }
autosuggest-accept-suggested-small-word() { autosuggest-accept-suggestion() {
zle .vi-forward-word if [[ AUTOSUGGESTION_ACCEPT_RIGHT_ARROW -eq 1 && "$WIDGET" == 'forward-char' ]]; then
autosuggest-highlight-suggested-text zle autosuggest-end-of-line-orig "$@"
else
zle autosuggest-${WIDGET}-orig "$@"
fi
if [[ -n $ZLE_AUTOSUGGESTING ]]; then
autosuggest-invalidate-highlight-cache
autosuggest-highlight-suggested-text
fi
} }
autosuggest-accept-suggested-word() { autosuggest-invalidate-highlight-cache() {
zle .forward-word # invalidate the buffer for zsh-syntax-highlighting
autosuggest-highlight-suggested-text _ZSH_HIGHLIGHT_PRIOR_BUFFER=''
} }
zle -N autosuggest-toggle zle -N autosuggest-toggle
zle -N autosuggest-start zle -N autosuggest-start
zle -N autosuggest-accept-suggested-small-word zle -N autosuggest-accept-suggested-small-word
zle -N autosuggest-accept-suggested-word zle -N autosuggest-accept-suggested-word
zle -N autosuggest-suspend
zle -N autosuggest-paused-self-insert
zle -N autosuggest-insert-or-space
zle -N autosuggest-backward-delete-char
zle -N autosuggest-accept-line
zle -N autosuggest-tab zle -N autosuggest-tab
zle -N autosuggest-suspend
zle -N autosuggest-accept-suggestion
# Save all widgets
zle -A self-insert autosuggest-self-insert-orig
zle -A magic-space autosuggest-magic-space-orig
zle -A backward-delete-char autosuggest-backward-delete-char-orig
zle -A accept-line autosuggest-accept-line-orig
for widget in ${ZLE_AUTOSUGGEST_ACCEPT_WIDGETS} ${ZLE_AUTOSUGGEST_SUSPEND_WIDGETS} ${ZLE_AUTOSUGGEST_COMPLETION_WIDGETS}; do
[[ -z $widgets[$widget] ]] && continue
eval "zle -A $widget autosuggest-${widget}-orig"
done

View File

@@ -9,7 +9,7 @@ autosuggest-ensure-server() {
local pid_file="$server_dir/pid" local pid_file="$server_dir/pid"
local socket_path="$server_dir/socket" local socket_path="$server_dir/socket"
if [[ ! -S $socket_path || ! -r $pid_file ]] || ! kill -0 $(<$pid_file) &> /dev/null; then if [[ ! -d $server_dir || ! -r $pid_file ]] || ! kill -0 $(<$pid_file) &> /dev/null; then
if which setsid &> /dev/null; then if which setsid &> /dev/null; then
setsid zsh $AUTOSUGGEST_SERVER_SCRIPT $server_dir $pid_file $socket_path &! setsid zsh $AUTOSUGGEST_SERVER_SCRIPT $server_dir $pid_file $socket_path &!
else else
@@ -33,9 +33,8 @@ autosuggest-server-connect() {
ZLE_AUTOSUGGEST_CONNECTION=$REPLY ZLE_AUTOSUGGEST_CONNECTION=$REPLY
} }
autosuggest-first-completion() { autosuggest-send-request() {
[[ -z $ZLE_AUTOSUGGEST_CONNECTION ]] && return 1 [[ -z $ZLE_AUTOSUGGEST_CONNECTION ]] && return 1
setopt local_options noglob setopt local_options noglob
local response
print -u $ZLE_AUTOSUGGEST_CONNECTION - $1 &> /dev/null || return 1 print -u $ZLE_AUTOSUGGEST_CONNECTION - $1 &> /dev/null || return 1
} }

View File

@@ -14,7 +14,7 @@ read-to-null() {
accept-connection() { accept-connection() {
zsocket -a $server zsocket -a $server
fds[$REPLY]=1 fds[$REPLY]=1
print "connection accepted, fd: $REPLY" print "connection accepted, fd: $REPLY" >&2
} }
handle-request() { handle-request() {
@@ -44,7 +44,7 @@ handle-request() {
break # handle more requests/return to zselect break # handle more requests/return to zselect
done done
if ! (( read_something )); then if ! (( read_something )); then
print "connection with fd $connection closed" 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
@@ -69,7 +69,7 @@ zmodload zsh/zpty
zmodload zsh/zselect zmodload zsh/zselect
zmodload zsh/net/socket zmodload zsh/net/socket
setopt noglob setopt noglob
print "autosuggestion server started, pid: $$" print "autosuggestion server started, pid: $$" >&2
# Start an interactive zsh connected to a zpty # Start an interactive zsh connected to a zpty
zpty z ZLE_DISABLE_AUTOSUGGEST=1 zsh -i zpty z ZLE_DISABLE_AUTOSUGGEST=1 zsh -i
@@ -96,10 +96,10 @@ cleanup() {
trap cleanup TERM INT HUP EXIT trap cleanup TERM INT HUP EXIT
mkdir -m 700 $server_dir &> /dev/null mkdir -m 700 $server_dir
while ! zsocket -l $socket_path; do while ! zsocket -l $socket_path; do
if [[ ! -r $pid_file ]] || ! kill -0 $(<$pid_file) &> /dev/null; then if [[ ! -r $pid_file ]] || ! kill -0 $(<$pid_file); then
rm -f $socket_path rm -f $socket_path
else else
exit 1 exit 1

32
install Executable file
View File

@@ -0,0 +1,32 @@
#!/bin/sh
# Install script for zsh-autocomplete
#first checks if ~/.zshrc file exists and is readable
if [ ! -r ~/.zshrc ]; then
echo "\nError: ~/.zshrc file does not exist or is not readable!\n"
exit 1
fi
DIR=$(dirname $(readlink -e $0)) ;
# appends the string to ~/.zshrc file
cat >> ~/.zshrc << EOF
# Setup zsh-autosuggestions
source $DIR/autosuggestions.zsh
# Enable autosuggestions automatically
zle-line-init() {
zle autosuggest-start
}
zle -N zle-line-init
# use ctrl+t to toggle autosuggestions(hopefully this wont be needed as
# zsh-autosuggestions is designed to be unobtrusive)
bindkey '^T' autosuggest-toggle
EOF
echo "\nSetup completed successfully!\n"
exit 0