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