]> arthur.barton.de Git - ax-zsh.git/blob - install.sh
install.sh: Check if zsh(1) is available
[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 ax_msg - "Installing AX-ZSH into \"$AXZSH\" ..."
35
36 safe_rm "$AXZSH" || exit 1
37 ln -sv "$PWD" "$AXZSH" || exit 1
38
39 for f in ~/.zlogin ~/.zlogout ~/.zprofile ~/.zshrc; do
40         safe_rm "$f" || exit 1
41         ln -sv "$AXZSH/ax.zsh" "$f" || exit 1
42 done
43
44 if [ ! -d "$AXZSH/active_plugins" ]; then
45         ax_msg - "Initializing plugin directory \"$AXZSH/active_plugins\" ..."
46         type zsh >/dev/null 2>&1
47         if [ $? -eq 0 ]; then
48                 zsh "$AXZSH/bin/axzshctl" reset-plugins
49                 exit $?
50         else
51                 ax_msg 2 "Oops, \"zsh\" not found!?"
52                 exit 1
53         fi
54 else
55         ax_msg - "Plugin directory \"$AXZSH/active_plugins\" already exists. Ok."
56 fi