]> arthur.barton.de Git - ax-zsh.git/blob - install.sh
Keep $AXZSH variable in axttyinfo alias
[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" || abort
24                 mv -v "$1" "$1.bak" || abort
25         fi
26         rm -f "$1" || abort
27 }
28
29 abort() {
30         ax_msg 2 "Failed to setup AX-ZSH!"
31         exit 1
32 }
33
34 umask 027
35
36 [ -n "$AXZSH" ] || AXZSH="$HOME/.axzsh"
37 export AXZSH
38
39 S=$(dirname "$0")
40
41 if [ "$S" = "$AXZSH" ] || [ "$PWD" = "$AXZSH" ] || [ -L "$AXZSH" ]; then
42         ax_msg 1 "Initializing \"$AXZSH\":"
43 else
44         ax_msg 1 "Install AX-ZSH into \"$AXZSH\":"
45         mkdir -p "$AXZSH" || abort
46
47         ax_msg - "Copying binaries and scripts ..."
48         cp -pRv "$S/ax.zsh"* "$AXZSH/" || abort
49         mkdir -p "$AXZSH/bin" || abort
50         cp -pRv "$S/bin/"* "$AXZSH/bin/" || abort
51
52         for f in AUTHORS LICENSE.md README.md; do
53                 cp -pRv "$S/$f" "$AXZSH/" || abort
54         done
55
56         ax_msg - "Copying plugins ..."
57         for plugin_type in core default_plugins plugins; do
58                 mkdir -p "$AXZSH/$plugin_type" || abort
59                 for p in "$S/$plugin_type/"*; do
60                         echo "$p -> $AXZSH/$p"
61                         rm -fr "${AXZSH:?}/$p" || abort
62                         cp -pR "$S/$p" "$AXZSH/$p" || abort
63                 done
64         done
65
66         ax_msg - "Copying themes ..."
67         mkdir -p "$AXZSH/themes" || abort
68         for p in "$S/themes/"*; do
69                 echo "$p -> $AXZSH/$p"
70                 rm -fr "${AXZSH:?}/$p" || abort
71                 cp -pR "$S/$p" "$AXZSH/$p" || abort
72         done
73 fi
74
75 mkdir -p "$AXZSH/custom_plugins" || abort
76 mkdir -p "$AXZSH/custom_themes" || abort
77
78 ax_msg - "Linking ZSH startup files ..."
79
80 for f in ~/.zlogin ~/.zlogout ~/.zprofile ~/.zshrc; do
81         safe_rm "$f" || abort
82         ln -sv "$AXZSH/ax.zsh" "$f" || abort
83 done
84
85 if [ ! -d "$AXZSH/active_plugins" ]; then
86         ax_msg - "Initializing plugin directory \"$AXZSH/active_plugins\" ..."
87         which zsh >/dev/null 2>&1
88         if [ $? -eq 0 ]; then
89                 zsh "$AXZSH/bin/axzshctl" reset-plugins || abort
90         else
91                 ax_msg 1 "Oops, \"zsh\" not found!?"
92         fi
93 else
94         ax_msg - "Plugin directory \"$AXZSH/active_plugins\" already exists. Ok."
95 fi
96
97 ax_msg 0 "AX-ZSH setup successfully."