2015-02-23 03:45:25 +08:00
#!/bin/bash
2014-11-22 05:51:19 +08:00
# Install script for zsh-autocomplete
2015-05-04 04:57:03 +08:00
config="$HOME/.zshrc"
2015-05-18 20:50:14 +08:00
for config in "$HOME/.zshrc" "$ZDOTDIR/.zshrc" "$1"; do
2015-05-04 04:57:03 +08:00
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
2014-11-22 05:51:19 +08:00
2015-01-24 06:38:46 +08:00
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
2015-05-18 20:50:14 +08:00
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
2015-01-24 06:38:46 +08:00
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
2014-11-22 05:51:19 +08:00
2015-05-04 04:57:03 +08:00
# appends the string to $config (usually ~/.zshrc) file
2015-05-18 20:50:14 +08:00
cat >> "$config" <<-EOF
2014-11-22 05:51:19 +08:00
2015-05-18 20:50:14 +08:00
# Setup zsh-autosuggestions
source $DIR/autosuggestions.zsh
2014-11-22 05:51:19 +08:00
2015-05-18 20:50:14 +08:00
# Enable autosuggestions automatically
zle-line-init() {
zle autosuggest-start
}
2014-11-22 05:51:19 +08:00
2015-05-18 20:50:14 +08:00
zle -N zle-line-init
2014-11-22 05:51:19 +08:00
2015-05-18 20:50:14 +08:00
# use ctrl+t to toggle autosuggestions(hopefully this wont be needed as
# zsh-autosuggestions is designed to be unobtrusive)
bindkey '^T' autosuggest-toggle
2014-11-22 05:51:19 +08:00
EOF
echo "\nSetup completed successfully!\n"
exit 0