-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.sh
executable file
·123 lines (107 loc) · 3.46 KB
/
config.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
#!/usr/bin/env bash
mkdir -p "$HOME/.site/zfunctions"
# shellcheck source=~/.zsh/profile.sh
test -e "$HOME/.zsh/profile.sh" && source "$HOME/.zsh/profile.sh"
# get the dir of the current script
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
if [[ $overwrite == "yes" ]] && [[ $SHELL != *zsh* ]]; then
USER_ZSH=$(command -v zsh)
if ! grep -q "$USER_ZSH" "/etc/shells"; then
echo "Try adding $USER_ZSH to /etc/shells"
sudo -v 2>&1 && echo "$USER_ZSH" | sudo tee -a /etc/shells
fi
echo "Now set zsh as your login shell"
if grep -q "zsh" "/etc/shells"; then
if grep -q "$USER_ZSH" "/etc/shells"; then
if sudo -v 2>&1; then
sudo chsh -s "$USER_ZSH" "$USER"
else
# try to authenticate with username as password
chsh -s "$USER_ZSH" "$USER" <<EOF
$USER
EOF
# Check the exit status of the command
if [[ $? -ne 0 ]]; then
# Last command failed, execute ls ls
echo "Input password for user $(whoami):"
chsh -s "$USER_ZSH" "$USER"
fi
fi
else
echo "$USER_ZSH is not in /etc/shells, now use other available zsh"
if sudo -v 2>&1; then
sudo chsh -s "$(tac /etc/shells | grep -m 1 zsh)" "$USER"
else
# try to authenticate with username as password
chsh -s "$(tac /etc/shells | grep -m 1 zsh)" "$USER" <<EOF
$USER
EOF
# Check the exit status of the command
if [[ $? -ne 0 ]]; then
# Last command failed, execute ls ls
echo "Input password for user $(whoami):"
chsh -s "$(tac /etc/shells | grep -m 1 zsh)" "$USER"
fi
fi
fi
else
echo "No zsh found in /etc/shells"
echo "Now add zsh to your bash config"
grep -q "$(command -v zsh)" && "command -v zsh" >>~/.bashrc
fi
fi
if [[ $overwrite == "yes" ]] || ! [[ -e ~/.zshrc ]]; then
touch ~/.site/pre.zsh
echo "export CONF_DIR='$script_dir'" >>~/.site/pre.zsh
touch ~/.site/plugins.zsh
touch ~/.site/post.zsh
touch ~/.site/profile.sh
ln -sf "$script_dir/zsh/rc.zsh" ~/.zshrc
ln -sfn "$script_dir/zsh" ~/.zsh
ln -sfn "$script_dir/zsh/profile.sh" ~/.profile
if [[ $(uname) == 'Darwin' ]]; then
ln -sf "$script_dir/zsh/p10k.macos.zsh" ~/.p10k.zsh
else
ln -sf "$script_dir/zsh/p10k.linux.zsh" ~/.p10k.zsh
fi
# install package manager for zsh
if [[ ! -d ~/.zgen/.git/ ]]; then
rm -rvf ~/.zgen
git clone https://github.com/tarjoilija/zgen.git ~/.zgen
fi
zgen update && zgen selfupdate
fi
if [[ $overwrite == "yes" ]] || ! [[ -e ~/.tmux.conf ]]; then
mkdir -p ~/.config/tmux
touch ~/.site/tmux.conf
ln -sfn "$script_dir/tmux" ~/.config/tmux/conf
ln -sf ~/.config/tmux/conf/tmux.conf ~/.tmux.conf
rm -rvf ~/.tmux/plugins
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
~/.tmux/plugins/tpm/bin/install_plugins
fi
if [[ $overwrite == "yes" ]]; then
rm -rvf ~/.config/git
ln -sfn "$script_dir/git/configgit" ~/.config/git
fi
if [[ $overwrite == "yes" ]]; then
rm -rvf ~/.config/kitty
ln -sfn "$script_dir/kitty" ~/.config/kitty
fi
if [[ $overwrite == "yes" ]] || ! [[ -e ~/.config/nvim/init.vim ]]; then
touch ~/.site/pre.vim
touch ~/.site/post.vim
mkdir -p ~/.config/nvim/
# for nvim
ln -sfn "$script_dir/nvim/nvim.vim" ~/.config/nvim/init.vim
ln -sfn "$script_dir/nvim/rc" ~/.config/nvim/rc
fi
if [[ $overwrite == "yes" ]] || ! [[ -e ~/.inputrc ]]; then
ln -sf "$script_dir/misc/inputrc" ~/.inputrc
fi
if [[ $overwrite == "yes" ]] || ! [[ -e ~/.haskeline ]]; then
ln -sf "$script_dir/misc/haskeline" ~/.haskeline
fi
touch ~/.site/init.el
# -p says to create the dir if it doesn't exist already
mkdir -p "$HOME/bin"