mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-11-18 09:51:06 +01:00
Add alterantive installation method
This commit is contained in:
parent
0371904875
commit
af72bd92ab
2 changed files with 86 additions and 0 deletions
13
.zsh-autosuggestionsrc
Executable file
13
.zsh-autosuggestionsrc
Executable file
|
@ -0,0 +1,13 @@
|
|||
# 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
|
73
alt-install
Executable file
73
alt-install
Executable file
|
@ -0,0 +1,73 @@
|
|||
#!/bin/bash
|
||||
# An alternative install script for zsh-autocomplete.
|
||||
#
|
||||
DESCRIPTION="this script adds/removes a
|
||||
.zsh-autosuggestionsrc reference to your .zshrc file."
|
||||
ZSHRC=""
|
||||
|
||||
function usage()
|
||||
{
|
||||
echo $0 : $DESCRIPTION
|
||||
echo "Usage"
|
||||
echo -e "\t" $0 " install : attempts to install"
|
||||
echo -e "\t" $0 " uninstall : attempts to uninstall"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function install()
|
||||
{
|
||||
PATH_TO_RC="source "$(pwd)"/.zsh-autosuggestionsrc"
|
||||
# check if line exists in zshrc, add it if missing
|
||||
if grep -Fxq "$PATH_TO_RC" "$ZSHRC"
|
||||
then
|
||||
echo "currently installed, see $ZSHRC"
|
||||
else
|
||||
echo "Backing up $ZSHRC to $ZSHRC.bak"
|
||||
cp "$ZSHRC" "$ZSHRC.bak"
|
||||
echo "Adding $PATH_TO_RC to $ZSHRC"
|
||||
echo "$PATH_TO_RC" >> "$ZSHRC"
|
||||
fi
|
||||
}
|
||||
|
||||
function uninstall()
|
||||
{
|
||||
PATH_TO_RC="source "$(pwd)"/.zsh-autosuggestionsrc"
|
||||
# check if line exists in zshrc, remove if preset
|
||||
if grep -Fxq "$PATH_TO_RC" "$ZSHRC"
|
||||
then
|
||||
echo "Removing $PATH_TO_RC from $ZSHRC"
|
||||
grep -v "$PATH_TO_RC" "$ZSHRC" > "tmp-zsh-autosuggestion"
|
||||
cat "tmp-zsh-autosuggestion" > "$ZSHRC"
|
||||
rm "tmp-zsh-autosuggestion"
|
||||
else
|
||||
echo "not currently installed, see $ZSHRC"
|
||||
fi
|
||||
}
|
||||
|
||||
function get_zhsrc()
|
||||
{
|
||||
# attempt to find a .zshrc
|
||||
# check if it exists and writeable
|
||||
if [ -w "$HOME/.zshrc" ] ; then
|
||||
ZSHRC="$HOME/.zshrc"
|
||||
elif [ -w "$ZDOTDIR/.zshrc" ] ; then
|
||||
ZSHRC="$ZDOTDIR/.zshrc"
|
||||
else
|
||||
echo "Cannot find .zshrc "
|
||||
exit -1
|
||||
fi
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
if [ "$1" == "install" ] ; then
|
||||
get_zhsrc
|
||||
install "$@"
|
||||
elif [ "$1" == "uninstall" ] ; then
|
||||
get_zhsrc
|
||||
uninstall "$@"
|
||||
else
|
||||
usage
|
||||
fi
|
||||
}
|
||||
main "$@" # $@ passes args to main.
|
Loading…
Reference in a new issue