-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
executable file
·131 lines (97 loc) · 3.48 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#! /usr/bin/env sh
set -e
# source the colors
SCRIPT_DIR="${2:-$(cd -- "$(dirname -- "$0")" && pwd -P)}"
. "$SCRIPT_DIR"/src/sh/scripts/eval/set-colors
export HOMEBREW_NO_AUTO_UPDATE=1
export AM_HOME="$HOME/.am"
export AM_PROMPT="$AM_HOME/prompt"
__am_prompt_install() {
NOW=$(date +"%Y%m%d_%H%M%S")
BACKUP_PATH="$AM_HOME/backup/prompt/$NOW"
print-success "creating backup path: $BACKUP_PATH"
mkdir -p "$BACKUP_PATH" 1>/dev/null
for TEMPLATE in "$SCRIPT_DIR"/template/*; do
TEMPLATE_NAME=$(basename "$TEMPLATE")
TEMPLATE_PATH="$HOME/.${TEMPLATE_NAME}"
if [ -f "$TEMPLATE_PATH" ]; then
print-success "backing up ${TEMPLATE_NAME}"
cp "$TEMPLATE_PATH" "$BACKUP_PATH/$TEMPLATE_NAME"
fi
cp "$TEMPLATE" "$TEMPLATE_PATH"
done
if [ -d "$AM_PROMPT" ]; then
print-success "backing up $AM_PROMPT"
cp -R "$AM_PROMPT"/* "$BACKUP_PATH" 1>/dev/null
print-success "removing $AM_PROMPT"
rm -rf "$AM_PROMPT/bash" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/sh" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/zsh" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/themes" 1>/dev/null 2>&1
# remove legacy paths
rm -rf "$AM_PROMPT/completions" 1>/dev/null 2>&1
rm -rf "$AM_PROMPT/scripts" 1>/dev/null 2>&1
rm -f "$AM_PROMPT/bashrc" 1>/dev/null 2>&1
fi
print-success "creating $AM_PROMPT"
mkdir -p "$AM_PROMPT/user/bin" 1>/dev/null 2>&1
print-success "installing promptMastermind to $AM_PROMPT"
cp -Rf "$SCRIPT_DIR/src/bash" "$AM_PROMPT" 1>/dev/null
cp -Rf "$SCRIPT_DIR/src/sh" "$AM_PROMPT" 1>/dev/null
cp -Rf "$SCRIPT_DIR/src/zsh" "$AM_PROMPT" 1>/dev/null
cp -Rf "$SCRIPT_DIR/src/themes" "$AM_PROMPT" 1>/dev/null
for USER_ITEM in "$SCRIPT_DIR"/src/user/*; do
USER_ITEM_NAME=$(basename "$USER_ITEM")
USER_ITEM_PATH="$AM_PROMPT/user/$USER_ITEM_NAME"
if [ ! -f "$USER_ITEM_PATH" ]; then
print-success "initializing user profile: $USER_ITEM_NAME at $USER_ITEM_PATH"
cp -r "$USER_ITEM" "$USER_ITEM_PATH"
fi
done
# detect platform
if [ -f /etc/os-release ]; then
. /etc/os-release
UNAMES="$ID ${ID_LIKE:-unknown} linux"
else
UNAMES=$(uname | tr '[:upper:]' '[:lower:]')
fi
# detect wsl
if [ -n "${WSL_DISTRO_NAME:-}" ]; then
UNAMES="wsl $UNAMES"
fi
for UNAME in $UNAMES; do
UNAME_PATH="$AM_PROMPT/sh/install/$UNAME.sh"
if [ ! -f "$UNAME_PATH" ]; then
continue
fi
print-success "installing platform prerequisites ($UNAME)"
. "$UNAME_PATH"
done
if [ ! -d "$AM_PROMPT/zsh/completions" ]; then
mkdir -p "$AM_PROMPT/zsh/completions" 1>/dev/null
fi
if [ ! -d "$AM_PROMPT/bash/completions" ]; then
mkdir -p "$AM_PROMPT/bash/completions" 1>/dev/null
fi
PROMPT_SHA=$(cat "$SCRIPT_DIR/VERSION")
PROMPT_SHA_PATH=$HOME/.am/prompt/.sha
printf "%s\n" "$PROMPT_SHA" > "$PROMPT_SHA_PATH"
# get the requested shell
PROMPT_SHELL="${1:-$(printf "%s" "$SHELL" | rev | cut -d'/' -f1 | rev)}"
# test if the current shell is something other than zsh
if [ "$PROMPT_SHELL" != "zsh" ]; then
# default to bash
PROMPT_SHELL="bash"
fi
# lowercase the prompt shell
PROMPT_SHELL=$(printf "%s" $PROMPT_SHELL | tr '[:upper:]' '[:lower:]')
# use the correct shell
. "$AM_PROMPT/sh/scripts/use-shell"
# open the changelog url
"$AM_PROMPT/sh/scripts/open-url" "https://github.com/automotivemastermind/prompt/blob/$PROMPT_SHA/CHANGELOG.md"
}
print-warn "prompt: establishing sudo (you may be prompted for credentials)..."
sudo printf "%s\n" ""
print-success "prompt: sudo enabled"
trap 'print-warn "prompt: terminating install..."; exit 1;' INT
__am_prompt_install "$@"