-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.zsh
168 lines (155 loc) · 5.72 KB
/
setup.zsh
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env zsh
function backup-dotfiles() {
echo "Creating backup"
if [ ! -e ~/.dotfiles-backup ]; then
echo "Creating ~/.dotfiles-backup"
mkdir ~/.dotfiles-backup
fi
echo -e "\nBackup dotfiles..."
cp ~/.zshrc ~/.dotfiles-backup
cp ~/.p10k.zsh ~/.dotfiles-backup
cp ~/.vimrc ~/.dotfiles-backup
cp ~/.zprofile ~/.dotfiles-backup
echo
}
function install-brew() {
if [[ "$OSTYPE" == "darwin"* ]]; then
if [ ! -x "$(which brew)" ] ; then
echo -e "\nInstalling brew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
fi
}
function install-zsh-features() {
echo -e "\nInstalling zsh features..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew update
brew install zsh-syntax-highlighting zsh-autosuggestions
elif [[ -f /etc/lsb-release || -f /etc/debian_version ]]; then
sudo apt-get update
sudo apt -y install zsh zsh-autosuggestions zsh-syntax-highlighting
elif [[ -f /etc/redhat-release ]]; then
sudo yum update
echo "Please install zsh features manually"
elif [[ -f /etc/os-release ]]; then
doas pkg update
doas pkg install -y zsh zsh-autosuggestions zsh-syntax-highlighting
else
echo "Please install zsh features manually"
fi
}
function install-ohmyzsh() {
echo -e "\nRemoving ~/.oh-my-zsh"
rm -rf ~/.oh-my-zsh
echo
echo "Installing oh-my-zsh"
if [ -x "$(which wget)" ] ; then
sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) --unattended"
elif [ -x "$(which curl)" ]; then
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) --unattended"
elif [ -x "$(which fetch)" ]; then
sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) --unattended"
else
echo "Could not find curl, wget or fetch, please install one." >&2
fi
echo
}
function install-other() {
echo -e "\nInstalling other..."
if [[ "$OSTYPE" == "darwin"* ]]; then
brew update
brew install wakeonlan neofetch
elif [[ -f /etc/lsb-release || -f /etc/debian_version ]]; then
echo "Ubuntu or Debian"
sudo apt-get update
sudo apt -y install git curl apt-transport-https ca-certificates gnupg lsb-release neofetch vim
elif [[ -f /etc/os-release ]]; then
doas pkg update
doas pkg install -y doas git gnupg neofetch vim
elif [[ -f /etc/redhat-release ]]; then
sudo yum update
echo "Please install zsh features manually"
else
echo "Please install zsh features manually"
fi
}
function install-powerlevel10k() {
echo -e "\nInstalling powerlevel10k"
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
echo
}
function copy-dotfiles() {
echo "Copy..."
/bin/cp .zshrc ~
/bin/cp .p10k.zsh ~
/bin/cp .vimrc ~
echo
}
function configure-zshrc() {
echo -e "\nConfiguring .zshrc"
echo "- adding zsh-syntax-highlighting"
echo "- adding zsh-autosuggestions"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo "source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc
echo "source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
elif [[ "$OSTYPE" == "darwin"* ]]; then
if [ -f /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then
echo "source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc
echo "source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
elif [ -f /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]; then
echo "source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc
echo "source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
else
echo "WARNING macOS: zsh-syntax-highlighting & zsh-autosuggestions & neofetch not found!"
fi
elif [[ "$OSTYPE" == "freebsd"* ]]; then
echo "source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ~/.zshrc
echo "source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh" >> ~/.zshrc
else
echo "!!! Unknown OS !!!"
fi
echo "- adding neofetch"
if [ -x "$(which neofetch)" ] ; then
echo `which neofetch` >> ~/.zshrc
else
echo "!!! Could not find neofetch. !!!" >&2
fi
}
function configure-zprofile() {
echo -e "\nConfiguring .zprofile"
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "eval $(/opt/homebrew/bin/brew shellenv)" >> ~/.zprofile
echo 'export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"' >> ~/.zprofile
else
echo "Please configure your .zprofile"
fi
}
function change-shell() {
if [[ "$SHELL" != *"zsh" ]]; then
echo -e "\n$SHELL in use... Select *zsh* from available shells..."
cat /etc/shells
chsh
echo "ATTENTION! logout/login and re-run this script"
exit 0
fi
}
function this-is-the-end() {
echo -e "\nFinished. Use 'source ~/.zshrc'"
echo "Consider to add yourself to sudoers"
echo "e.g.: echo \"harry ALL=(ALL) NOPASSWD:ALL\" > /etc/sudoers.d/harry"
source ~/.zshrc
}
main() {
backup-dotfiles
install-brew
install-other
install-zsh-features
change-shell
install-ohmyzsh
install-powerlevel10k
copy-dotfiles
configure-zshrc
configure-zprofile
this-is-the-end
}
main "$@"