From af72bd92abbe9bd7a92cbbe2ef9252163b090c87 Mon Sep 17 00:00:00 2001 From: Robert Baykov Date: Sun, 17 May 2015 23:24:04 -0500 Subject: [PATCH 1/3] Add alterantive installation method --- .zsh-autosuggestionsrc | 13 ++++++++ alt-install | 73 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100755 .zsh-autosuggestionsrc create mode 100755 alt-install diff --git a/.zsh-autosuggestionsrc b/.zsh-autosuggestionsrc new file mode 100755 index 0000000..b016456 --- /dev/null +++ b/.zsh-autosuggestionsrc @@ -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 diff --git a/alt-install b/alt-install new file mode 100755 index 0000000..bdc737f --- /dev/null +++ b/alt-install @@ -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. From 03c5a52a894e999b95d6427f7d7570c646e8f24e Mon Sep 17 00:00:00 2001 From: Robert Baykov Date: Sun, 17 May 2015 23:32:25 -0500 Subject: [PATCH 2/3] Update .zsh-autosuggestionrc --- .zsh-autosuggestionsrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.zsh-autosuggestionsrc b/.zsh-autosuggestionsrc index b016456..f76e1ee 100755 --- a/.zsh-autosuggestionsrc +++ b/.zsh-autosuggestionsrc @@ -1,5 +1,5 @@ # Setup zsh-autosuggestions -source $DIR/autosuggestions.zsh +source $HOME/.zsh-autosuggestions/autosuggestions.zsh # Enable autosuggestions automatically zle-line-init() { From c54c2415f0925f789f07ea4f193cf2c98a4b2591 Mon Sep 17 00:00:00 2001 From: Robert Baykov Date: Sun, 17 May 2015 23:35:14 -0500 Subject: [PATCH 3/3] Fix installation bug. If the install script is run from an alternative directory the use of pwd incorrectly sets the path to .zsh-autosuggesionsrc --- alt-install | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alt-install b/alt-install index bdc737f..61dc41b 100755 --- a/alt-install +++ b/alt-install @@ -4,6 +4,7 @@ DESCRIPTION="this script adds/removes a .zsh-autosuggestionsrc reference to your .zshrc file." ZSHRC="" +PATH_TO_RC="source $HOME/.zsh-autosuggestions/.zsh-autosuggestionsrc" function usage() { @@ -16,7 +17,7 @@ function usage() 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 @@ -31,7 +32,6 @@ function install() 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