X-Git-Url: https://arthur.barton.de/gitweb/?p=ax-zsh.git;a=blobdiff_plain;f=install.sh;h=782e4cf761c3892adcdb38a11b283ff92231af69;hp=923ab8694213eedcbf80878e0c1c09cb6edfcb57;hb=HEAD;hpb=ab4280c3ec2f2e99c01bc52775a9a3135bca8ee1 diff --git a/install.sh b/install.sh index 923ab86..6d7b22a 100755 --- a/install.sh +++ b/install.sh @@ -1,13 +1,15 @@ #!/bin/sh # # AX-ZSH: Alex' Modular ZSH Configuration -# Copyright (c) 2015 Alexander Barton +# Copyright (c) 2015-2022 Alexander Barton # # Include "ax-common.sh": -for dir in "$HOME/lib" "$HOME/.ax" /usr/local /opt/ax /usr; do +ax_common_sourced= +for dir in "$HOME" "$HOME/.ax" /usr/local /opt/ax /usr; do [ -z "$ax_common_sourced" ] || break ax_common="${dir}/lib/ax/ax-common.sh" + # shellcheck source=/usr/local/lib/ax/ax-common.sh [ -r "$ax_common" ] && . "$ax_common" done if [ -z "$ax_common_sourced" ]; then @@ -19,7 +21,7 @@ fi unset dir ax_common ax_common_sourced safe_rm() { - if [ -f "$1" -a ! -L "$1" ]; then + if [ -f "$1" ] && [ ! -L "$1" ]; then rm -f "$1.bak" || abort mv -v "$1" "$1.bak" || abort fi @@ -33,17 +35,15 @@ abort() { umask 027 -[ -n "$AXZSH" ] || AXZSH="$HOME/.axzsh" +[ -n "$AXZSH" ] || AXZSH="${ZDOTDIR:-$HOME}/.axzsh" export AXZSH S=$(dirname "$0") -if [ "$S" = "$AXZSH" -o "$PWD" = "$AXZSH" ]; then +if [ "$S" = "$AXZSH" ] || [ "$PWD" = "$AXZSH" ] || [ -L "$AXZSH" ]; then ax_msg 1 "Initializing \"$AXZSH\":" else ax_msg 1 "Install AX-ZSH into \"$AXZSH\":" - - [ -L "$AXZSH" ] && rm -f "$AXZSH" mkdir -p "$AXZSH" || abort ax_msg - "Copying binaries and scripts ..." @@ -64,24 +64,38 @@ else cp -pR "$S/$p" "$AXZSH/$p" || abort done done + + ax_msg - "Copying themes ..." + mkdir -p "$AXZSH/themes" || abort + for p in "$S/themes/"*; do + echo "$p -> $AXZSH/$p" + rm -fr "${AXZSH:?}/$p" || abort + cp -pR "$S/$p" "$AXZSH/$p" || abort + done fi mkdir -p "$AXZSH/custom_plugins" || abort +mkdir -p "$AXZSH/custom_themes" || abort ax_msg - "Linking ZSH startup files ..." -for f in ~/.zlogin ~/.zlogout ~/.zprofile ~/.zshrc; do +for f in \ + ${ZDOTDIR:-$HOME}/.zlogin \ + ${ZDOTDIR:-$HOME}/.zlogout \ + ${ZDOTDIR:-$HOME}/.zprofile \ + ${ZDOTDIR:-$HOME}/.zshrc \ +; do safe_rm "$f" || abort ln -sv "$AXZSH/ax.zsh" "$f" || abort done if [ ! -d "$AXZSH/active_plugins" ]; then ax_msg - "Initializing plugin directory \"$AXZSH/active_plugins\" ..." - which zsh >/dev/null 2>&1 - if [ $? -eq 0 ]; then + if command -v zsh >/dev/null; then zsh "$AXZSH/bin/axzshctl" reset-plugins || abort else ax_msg 1 "Oops, \"zsh\" not found!?" + exit 1 fi else ax_msg - "Plugin directory \"$AXZSH/active_plugins\" already exists. Ok."