-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_zsh.sh
executable file
·139 lines (117 loc) · 4.67 KB
/
setup_zsh.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
132
133
134
135
136
137
138
139
#!/bin/bash -xe
# To install
# sudo /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/peteroneilljr/.dotfiles/master/setup_zsh.sh)"
# ---------------------------------------------------------------------------- #
# Find package manager
# ---------------------------------------------------------------------------- #
if [[ -x "/usr/bin/apt-get" ]]; then
PCK_MGR="/usr/bin/apt-get"
elif [[ -x "/usr/bin/yum" ]]; then
PCK_MGR="/usr/bin/yum"
elif [[ -x "/usr/local/bin/brew" ]]; then
PCK_MGR="/usr/local/bin/brew"
else
echo "Package manager not in; apt, yum or brew."
exit 1
fi
# ---------------------------------------------------------------------------- #
# # install zsh
# ---------------------------------------------------------------------------- #
if ! command -V zsh; then
$PCK_MGR install zsh -y || \
(
echo "failed zsh install, attempting $PCK_MGR update"
$PCK_MGR update -y --skip-broken
$PCK_MGR install zsh -y || ( echo "failed zsh install"; exit 1 )
)
else
echo "zsh already installed"
fi
# ---------------------------------------------------------------------------- #
# # https://github.com/ohmyzsh/ohmyzsh
# ---------------------------------------------------------------------------- #
if [[ ! -d "$HOME/.oh-my-zsh" ]]; then
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended && \
echo "Installed oh-my-zsh"
else
echo "oh-my-zsh already installed"
fi
# ---------------------------------------------------------------------------- #
# # Install zsh-autosuggestions plugin
# ---------------------------------------------------------------------------- #
if [[ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]]; then
git clone https://github.com/zsh-users/zsh-autosuggestions \
"$HOME"/.oh-my-zsh/custom/plugins/zsh-autosuggestions && \
echo "Installed zsh-autosuggestions" || echo "Install failed"
else
echo "zsh-autosuggestions already installed"
fi
# ---------------------------------------------------------------------------- #
# # Install zsh-syntax-highlighting plugin
# ---------------------------------------------------------------------------- #
if [[ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ]]; then
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \
"$HOME"/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting && \
echo "Installed zsh-syntax-highlighting" || echo "Install failed"
else
echo "zsh-syntax-highlighting already installed"
fi
# ---------------------------------------------------------------------------- #
# Download dotfiles https://github.com/peteroneilljr/.dotfiles.git
# ---------------------------------------------------------------------------- #
if [[ ! -d "$HOME/.dotfiles" ]]; then
# Save current zshrc file if it exists
git clone https://github.com/peteroneilljr/.dotfiles.git "$HOME"/.dotfiles && \
echo "Installed .dotfiles" || echo "Install failed"
else
echo ".dotfiles already installed"
fi
# ---------------------------------------------------------------------------- #
# Backup old zshrc and create a symlink to new zshrc
# ---------------------------------------------------------------------------- #
if [[ -f "$HOME/.zshrc" ]] && [[ ! -L "$HOME/.zshrc" ]]; then
mv "$HOME"/.zshrc "$HOME"/.zshrc.backup && \
echo "created zshrc backup";
fi
if [[ -L "$HOME/.zshrc" ]]; then
echo ".zshrc already linked";
else
ln -sv ~/.dotfiles/.zshrc "$HOME";
fi
# ---------------------------------------------------------------------------- #
# Find current user
# ---------------------------------------------------------------------------- #
if ! logname; then
THISUSER="$USER"
else
THISUSER="$(logname)"
fi && echo "User is $THISUSER"
# ---------------------------------------------------------------------------- #
# Cleanup file ownership, change shell, and load zsh
# ---------------------------------------------------------------------------- #
if [[ "$(grep "$THISUSER" /etc/passwd | cut -d: -f7)" != *"/zsh" ]]; then
if [[ "$THISUSER" == "root" ]]; then
chsh -s "/bin/zsh" "$THISUSER";
else
chown -R "$THISUSER":"$THISUSER" "$HOME"
chmod -R g-w "$HOME"
chsh -s "/usr/bin/zsh" "$THISUSER"
fi
fi
# ---------------------------------------------------------------------------- #
# Start zsh shell
# ---------------------------------------------------------------------------- #
if [[ -d "$HOME/.oh-my-zsh" ]] \
&& [[ -d "$HOME/.dotfiles" ]] \
&& [[ -L "$HOME/.zshrc" ]];
then
if [[ $SHELL != *"/zsh" ]]; then
runuser -l "$THISUSER" -c 'zsh'
else
echo "zsh already running";
fi
else
echo "something went wrong"
exit 1
fi
exit 0