]> arthur.barton.de Git - ax-zsh.git/blob - install.sh
homebrew: Set HOMEBREW_AUTO_UPDATE_SECS to 10 minutes
[ax-zsh.git] / install.sh
1 #!/bin/sh
2 #
3 # AX-ZSH: Alex' Modular ZSH Configuration
4 # Copyright (c) 2015-2022 Alexander Barton <alex@barton.de>
5 #
6
7 # Include "ax-common.sh":
8 ax_common_sourced=
9 for dir in "$HOME" "$HOME/.ax" /usr/local /opt/ax /usr; do
10         [ -z "$ax_common_sourced" ] || break
11         ax_common="${dir}/lib/ax/ax-common.sh"
12         # shellcheck source=/usr/local/lib/ax/ax-common.sh
13         [ -r "$ax_common" ] && . "$ax_common"
14 done
15 if [ -z "$ax_common_sourced" ]; then
16         ax_msg() {
17                 shift
18                 echo "$@"
19         }
20 fi
21 unset dir ax_common ax_common_sourced
22
23 safe_rm() {
24         if [ -f "$1" ] && [ ! -L "$1" ]; then
25                 rm -f "$1.bak" || abort
26                 mv -v "$1" "$1.bak" || abort
27         fi
28         rm -f "$1" || abort
29 }
30
31 abort() {
32         ax_msg 2 "Failed to setup AX-ZSH!"
33         exit 1
34 }
35
36 umask 027
37
38 [ -n "$AXZSH" ] || AXZSH="${ZDOTDIR:-$HOME}/.axzsh"
39 export AXZSH
40
41 S=$(dirname "$0")
42
43 if [ "$S" = "$AXZSH" ] || [ "$PWD" = "$AXZSH" ] || [ -L "$AXZSH" ]; then
44         ax_msg 1 "Initializing \"$AXZSH\":"
45 else
46         ax_msg 1 "Install AX-ZSH into \"$AXZSH\":"
47         mkdir -p "$AXZSH" || abort
48
49         ax_msg - "Copying binaries and scripts ..."
50         cp -pRv "$S/ax.zsh"* "$AXZSH/" || abort
51         mkdir -p "$AXZSH/bin" || abort
52         cp -pRv "$S/bin/"* "$AXZSH/bin/" || abort
53
54         for f in AUTHORS LICENSE.md README.md; do
55                 cp -pRv "$S/$f" "$AXZSH/" || abort
56         done
57
58         ax_msg - "Copying plugins ..."
59         for plugin_type in core default_plugins plugins; do
60                 mkdir -p "$AXZSH/$plugin_type" || abort
61                 for p in "$S/$plugin_type/"*; do
62                         echo "$p -> $AXZSH/$p"
63                         rm -fr "${AXZSH:?}/$p" || abort
64                         cp -pR "$S/$p" "$AXZSH/$p" || abort
65                 done
66         done
67
68         ax_msg - "Copying themes ..."
69         mkdir -p "$AXZSH/themes" || abort
70         for p in "$S/themes/"*; do
71                 echo "$p -> $AXZSH/$p"
72                 rm -fr "${AXZSH:?}/$p" || abort
73                 cp -pR "$S/$p" "$AXZSH/$p" || abort
74         done
75 fi
76
77 mkdir -p "$AXZSH/custom_plugins" || abort
78 mkdir -p "$AXZSH/custom_themes" || abort
79
80 ax_msg - "Linking ZSH startup files ..."
81
82 for f in \
83         ${ZDOTDIR:-$HOME}/.zlogin \
84         ${ZDOTDIR:-$HOME}/.zlogout \
85         ${ZDOTDIR:-$HOME}/.zprofile \
86         ${ZDOTDIR:-$HOME}/.zshrc \
87 ; do
88         safe_rm "$f" || abort
89         ln -sv "$AXZSH/ax.zsh" "$f" || abort
90 done
91
92 if [ ! -d "$AXZSH/active_plugins" ]; then
93         ax_msg - "Initializing plugin directory \"$AXZSH/active_plugins\" ..."
94         if command -v zsh >/dev/null; then
95                 zsh "$AXZSH/bin/axzshctl" reset-plugins || abort
96         else
97                 ax_msg 1 "Oops, \"zsh\" not found!?"
98                 exit 1
99         fi
100 else
101         ax_msg - "Plugin directory \"$AXZSH/active_plugins\" already exists. Ok."
102 fi
103
104 ax_msg 0 "AX-ZSH setup successfully."