diff --git a/doc/install.sh b/doc/install.sh index 721299d2b..81f4f08a9 100755 --- a/doc/install.sh +++ b/doc/install.sh @@ -6,48 +6,57 @@ ZINIT_HOME="${ZINIT_HOME:-$ZPLG_HOME}" if [ -z "$ZINIT_HOME" ]; then - ZINIT_HOME="${ZDOTDIR:-$HOME}/.zinit" + ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit" fi ZINIT_BIN_DIR_NAME="${ZINIT_BIN_DIR_NAME:-$ZPLG_BIN_DIR_NAME}" if [ -z "$ZINIT_BIN_DIR_NAME" ]; then - ZINIT_BIN_DIR_NAME="bin" + ZINIT_BIN_DIR_NAME="zinit.git" fi if ! test -d "$ZINIT_HOME"; then - mkdir "$ZINIT_HOME" + mkdir -p "$ZINIT_HOME" chmod g-w "$ZINIT_HOME" chmod o-w "$ZINIT_HOME" fi if ! command -v git >/dev/null 2>&1; then - echo "▓▒░ Something went wrong: no git available, cannot proceed." + echo "▓▒░ Something went wrong: git is not available, cannot proceed." + exit 1 +fi + +ZINIT_BRANCH="${ZINIT_BRANCH:-master}" +ZINIT_TMPDIR="$(mktemp --directory)" +if [ ! -d "$ZINIT_TMPDIR" ]; then + echo "Tempdir creation failed. This ain't good." >&2 exit 1 fi # Get the download-progress bar tool +GIT_PROCESS_SCRIPT_URL="https://raw.githubusercontent.com/zdharma-continuum/zinit/${ZINIT_BRANCH}/git-process-output.zsh" +trap 'rm -rvf "$ZINIT_TMPDIR"' EXIT INT if command -v curl >/dev/null 2>&1; then - mkdir -p /tmp/zinit - cd /tmp/zinit - curl -fsSLO https://raw.githubusercontent.com/zdharma-continuum/zinit/master/git-process-output.zsh && \ - chmod a+x /tmp/zinit/git-process-output.zsh + curl -fsSL -o "${ZINIT_TMPDIR}/git-process-output.zsh" "$GIT_PROCESS_SCRIPT_URL" elif command -v wget >/dev/null 2>&1; then - mkdir -p /tmp/zinit - cd /tmp/zinit - wget -q https://raw.githubusercontent.com/zdharma-continuum/zinit/master/git-process-output.zsh && \ - chmod a+x /tmp/zinit/git-process-output.zsh + wget -q -O "${ZINIT_TMPDIR}/git-process-output.zsh" "$GIT_PROCESS_SCRIPT_URL" fi +chmod a+x "${ZINIT_TMPDIR}/git-process-output.zsh" 2>/dev/null echo if test -d "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME/.git"; then - cd "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME" - echo "▓▒░ Updating DHARMA Initiative Plugin Manager at $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" - git pull origin master + cd "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME" || { echo "Failed to cd to $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" >&2; exit 1; } + echo "▓▒░ Updating ZDHARMA-CONTINUUM Initiative Plugin Manager to $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" + git pull origin "${ZINIT_BRANCH}" else - cd "$ZINIT_HOME" - echo "▓▒░ Installing DHARMA Initiative Plugin Manager at $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" - { git clone --progress https://github.com/zdharma-continuum/zinit.git "$ZINIT_BIN_DIR_NAME" \ - 2>&1 | { /tmp/zinit/git-process-output.zsh || cat; } } 2>/dev/null + cd "$ZINIT_HOME" || { echo "Failed to cd to $ZINIT_HOME" >&2; exit 1; } + echo "▓▒░ Installing ZDHARMA-CONTINUUM Initiative Plugin Manager to $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" + { + git clone --progress --branch "$ZINIT_BRANCH" \ + https://github.com/zdharma-continuum/zinit.git \ + "$ZINIT_BIN_DIR_NAME" 2>&1 | { + "${ZINIT_TMPDIR}/git-process-output.zsh" || cat; + } + } 2>/dev/null if [ -d "$ZINIT_BIN_DIR_NAME" ]; then echo echo "▓▒░ Zinit succesfully installed at $ZINIT_HOME/$ZINIT_BIN_DIR_NAME". @@ -55,7 +64,7 @@ else echo "▓▒░ Version: $VERSION" else echo - echo "▓▒░ Something went wrong, couldn't install Zinit at $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" + echo "▓▒░ Something went wrong, couldn't install Zinit to $ZINIT_HOME/$ZINIT_BIN_DIR_NAME" fi fi @@ -64,19 +73,19 @@ fi # THE_ZDOTDIR="${ZDOTDIR:-$HOME}" RCUPDATE=1 -if egrep '(zinit|zplugin)\.zsh' "$THE_ZDOTDIR/.zshrc" >/dev/null 2>&1; then +if grep -E '(zinit|zplugin)\.zsh' "$THE_ZDOTDIR/.zshrc" >/dev/null 2>&1; then echo "▓▒░ .zshrc already contains \`zinit …' commands – not making changes." RCUPDATE=0 fi if [ $RCUPDATE -eq 1 ]; then echo "▓▒░ Updating $THE_ZDOTDIR/.zshrc (10 lines of code, at the bottom)" - ZINIT_HOME="$(echo $ZINIT_HOME | sed "s|$HOME|\$HOME|")" + ZINIT_HOME="$(echo "$ZINIT_HOME" | sed "s|$HOME|\$HOME|")" command cat <<-EOF >> "$THE_ZDOTDIR/.zshrc" ### Added by Zinit's installer if [[ ! -f $ZINIT_HOME/$ZINIT_BIN_DIR_NAME/zinit.zsh ]]; then - print -P "%F{33}▓▒░ %F{220}Installing %F{33}DHARMA%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f" + print -P "%F{33}▓▒░ %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f" command mkdir -p "$ZINIT_HOME" && command chmod g-rwX "$ZINIT_HOME" command git clone https://github.com/zdharma-continuum/zinit "$ZINIT_HOME/$ZINIT_BIN_DIR_NAME" && \\ print -P "%F{33}▓▒░ %F{34}Installation successful.%f%b" || \\ @@ -105,7 +114,7 @@ echo "▓▒░ Would you like to add 4 useful plugins" \ "functions-features to the plugin manager) to the zshrc as well?" \ "It will be the following snippet:" command cat "$file" - echo -n "▓▒░ Enter y/n and press Return: " + printf "▓▒░ Enter y/n and press Return: " read -r input if [ "$input" = y ] || [ "$input" = Y ]; then command cat "$file" >> "$THE_ZDOTDIR"/.zshrc @@ -141,12 +150,12 @@ command cat <<-EOF ▓▒░ run-atpull reset-prompt trackbinds aliases sh bash ksh csh For more information see: +- The zdharma-continuum GitHub organization, which hosts zinit and all related components + - https://github.com/zdharma-continuum - README section on the ice-modifiers: - - https://github.com/zdharma-continuum/zinit#ice-modifiers, -- intro to Zinit at the Wiki: - - https://zdharma-continuum.org/zinit/wiki/INTRODUCTION/, -- zinit-zsh GitHub account, which holds all the available Zinit annexes: - - https://github.com/zdharma-continuum/, -- For-Syntax article on the Wiki; it is less directly related to the ices, however, it explains how to use them conveniently: - - https://zdharma-continuum.org/zinit/wiki/For-Syntax/. + - https://github.com/zdharma-continuum/zinit#ice-modifiers +- An introduction to Zinit on the wiki: + - https://zdharma-continuum.github.io/zinit/wiki/INTRODUCTION/ +- For-Syntax article on the wiki; it is less directly related to the ices but it explains how to use them conveniently: + - https://zdharma-continuum.github.io/zinit/wiki/For-Syntax/ EOF