mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-12-29 07:34:11 +08:00
24ac946dd9
User can also supply as a first parameter the script to append to zsh-autosuggestions.
46 lines
1.2 KiB
Bash
Executable File
46 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Install script for zsh-autocomplete
|
|
|
|
config="$HOME/.zshrc"
|
|
for config in "$HOME/.zshrc" "$ZDOTDIR/.zshrc" "$1"
|
|
do
|
|
echo $config
|
|
#first checks if ~/.zshrc file exists and is readable
|
|
if [ -r "$config" ]; then
|
|
break
|
|
elif [ "$config" = "$1" ]; then
|
|
echo "\nError: Please specify as first argument the file in which to load zsh-autosuggestions (usually ~/.zshrc)!\n"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
SOURCE="${BASH_SOURCE[0]}"
|
|
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|
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
|
|
done
|
|
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|
|
|
# appends the string to $config (usually ~/.zshrc) file
|
|
cat >> "$config" << 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
|