X-Git-Url: https://arthur.barton.de/gitweb/?p=ax-zsh.git;a=blobdiff_plain;f=install.sh;h=782e4cf761c3892adcdb38a11b283ff92231af69;hp=526256cb9dfb9b8331466b3b7cae2e6dd60c0597;hb=2ddebb388326d38d99b04303397ecadc185ccc58;hpb=ae12b745b56317dd84fe7f31f5678184353ed97b diff --git a/install.sh b/install.sh index 526256c..782e4cf 100755 --- a/install.sh +++ b/install.sh @@ -5,9 +5,11 @@ # # 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,11 +21,16 @@ fi unset dir ax_common ax_common_sourced safe_rm() { - if [ -f "$1" -a ! -L "$1" ]; then - rm -f "$1.bak" || exit 1 - mv -v "$1" "$1.bak" || exit 1 + if [ -f "$1" ] && [ ! -L "$1" ]; then + rm -f "$1.bak" || abort + mv -v "$1" "$1.bak" || abort fi - rm -f "$1" || exit 1 + rm -f "$1" || abort +} + +abort() { + ax_msg 2 "Failed to setup AX-ZSH!" + exit 1 } umask 027 @@ -31,19 +38,61 @@ umask 027 [ -n "$AXZSH" ] || AXZSH="$HOME/.axzsh" export AXZSH -ax_msg - "Installing AX-ZSH into \"$AXZSH\" ..." +S=$(dirname "$0") + +if [ "$S" = "$AXZSH" ] || [ "$PWD" = "$AXZSH" ] || [ -L "$AXZSH" ]; then + ax_msg 1 "Initializing \"$AXZSH\":" +else + ax_msg 1 "Install AX-ZSH into \"$AXZSH\":" + mkdir -p "$AXZSH" || abort + + ax_msg - "Copying binaries and scripts ..." + cp -pRv "$S/ax.zsh"* "$AXZSH/" || abort + mkdir -p "$AXZSH/bin" || abort + cp -pRv "$S/bin/"* "$AXZSH/bin/" || abort + + for f in AUTHORS LICENSE.md README.md; do + cp -pRv "$S/$f" "$AXZSH/" || abort + done -safe_rm "$AXZSH" || exit 1 -ln -sv "$PWD" "$AXZSH" || exit 1 + ax_msg - "Copying plugins ..." + for plugin_type in core default_plugins plugins; do + mkdir -p "$AXZSH/$plugin_type" || abort + for p in "$S/$plugin_type/"*; do + echo "$p -> $AXZSH/$p" + rm -fr "${AXZSH:?}/$p" || abort + 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 - safe_rm "$f" || exit 1 - ln -sv "$AXZSH/ax.zsh" "$f" || exit 1 + 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\" ..." - zsh "$AXZSH/bin/axzshctl" reset-plugins + if command -v zsh >/dev/null; then + zsh "$AXZSH/bin/axzshctl" reset-plugins || abort + else + ax_msg 1 "Oops, \"zsh\" not found!?" + fi else ax_msg - "Plugin directory \"$AXZSH/active_plugins\" already exists. Ok." fi + +ax_msg 0 "AX-ZSH setup successfully."