-
Notifications
You must be signed in to change notification settings - Fork 1
/
dotfiles_installer.sh
119 lines (102 loc) · 4.4 KB
/
dotfiles_installer.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
#!/usr/bin/env bash
## Usage:
## 1. Install `curl git`
## 2. Clone repo: source <(curl -fsSL --connect-timeout 5 --max-time 15 https://git.io/JPSue)
## or
## curl -fsSL --connect-timeout 5 --max-time 15 https://git.io/JPSue | bash "$HOME/.dotfiles"
## 3. Install zsh and oh-my-zsh: ${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/zsh/zsh_installer.sh
## 4. Change default shell to zsh: chsh -s $(which zsh)
## 5. Init: ${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/zsh/zsh_upgrade_all_packages.sh && ${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/zsh/zsh_init.sh
## 6. Update: source <(curl -fsSL --connect-timeout 5 --max-time 15 https://git.io/JPSue) && ${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/zsh/zsh_upgrade_all_packages.sh
[[ -z "${CURRENT_DIR}" || ! -d "${CURRENT_DIR}" ]] && CURRENT_DIR=$(pwd)
# Colors
NOCOLOR='\033[0m'
RED='\033[0;31m' # Error message
LIGHTRED='\033[1;31m'
GREEN='\033[0;32m' # Success message
LIGHTGREEN='\033[1;32m'
ORANGE='\033[0;33m'
YELLOW='\033[1;33m' # Warning message
BLUE='\033[0;34m' # Info message
LIGHTBLUE='\033[1;34m'
PURPLE='\033[0;35m'
FUCHSIA='\033[0;35m'
LIGHTPURPLE='\033[1;35m'
CYAN='\033[0;36m'
LIGHTCYAN='\033[1;36m'
DARKGRAY='\033[1;30m'
LIGHTGRAY='\033[0;37m'
WHITE='\033[1;37m'
function colorEcho() {
if [[ $# -gt 1 ]]; then
local COLOR=$1
echo -e "${COLOR}${@:2}${NOCOLOR}"
else
echo -e "${@:1}${NOCOLOR}"
fi
}
if [[ ! "$(command -v git)" ]]; then
colorEcho "${FUCHSIA}git${RED} is not installed, Please install it first!"
exit
fi
MY_SHELL_SCRIPTS="${1:-$HOME/.dotfiles}"
colorEcho "${BLUE}Cloning ${ORANGE}dotfiles & scripts ${BLUE}to ${FUCHSIA}${MY_SHELL_SCRIPTS}${BLUE}..."
# [[ -d "$HOME/terminal-custom" ]] && rm -rf "$HOME/terminal-custom"
if [[ -d "${MY_SHELL_SCRIPTS}" ]]; then
cd "${MY_SHELL_SCRIPTS}" && \
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null) && \
git pull --rebase --stat origin "${BRANCH:-main}"
else
REPOREMOTE="https://github.com/epoweripione/dotfiles.git"
BRANCH=$(git ls-remote --symref "${REPOREMOTE}" HEAD \
| awk '/^ref:/ {sub(/refs\/heads\//, "", $2); print $2}')
git clone -c core.autocrlf=false -c core.filemode=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
--depth=1 --branch "${BRANCH:-main}" "${REPOREMOTE}" "${MY_SHELL_SCRIPTS}"
fi
# starship config
if [[ -x "$(command -v starship)" ]]; then
[[ ! -d "$HOME/.config" ]] && mkdir -p "$HOME/.config"
cp -f "${MY_SHELL_SCRIPTS}/zsh/themes/starship.toml" "$HOME/.config/starship.toml"
fi
# starship config
if [[ -x "$(command -v oh-my-posh)" ]]; then
cp -f "${MY_SHELL_SCRIPTS}/powershell/themes/"*.omp.json "$HOME/.poshthemes"
fi
# make *.sh executable
find "${MY_SHELL_SCRIPTS}" -type f -iname "*.sh" -exec chmod +x {} \;
## git global config
# if [[ -s "${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/git/git_global_config.sh" ]]; then
# source "${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/git/git_global_config.sh"
# fi
# fix location in .zshrc
if [[ -s "$HOME/.zshrc" ]]; then
sed -i "s|^source ~/zsh_custom_conf.sh|source ~/.dotfiles/zsh/zsh_custom_conf.sh|" "$HOME/.zshrc"
sed -i "s|^source ~/terminal-custom/zsh/zsh_custom_conf.sh|source ~/.dotfiles/zsh/zsh_custom_conf.sh|" "$HOME/.zshrc"
sed -i "s|~/terminal-custom|~/.dotfiles|g" "$HOME/.zshrc"
fi
# fix location in cron jobs
if [[ -x "$(command -v crontab)" ]]; then
if crontab -l 2>/dev/null | grep -q '/terminal-custom/' 2>/dev/null; then
crontab -l | sed "s|/terminal-custom/|/.dotfiles/|g" | crontab -
fi
fi
if [[ -d "$ZSH/custom" ]]; then
colorEcho "${BLUE}Copying ZSH custom plugins & themes to ${FUCHSIA}$ZSH/custom${BLUE}..."
# zsh custom plugins
[ -d "$HOME/.dotfiles/zsh/plugins" ] && cp -f "$HOME/.dotfiles/zsh/plugins/"* "$ZSH/custom/plugins"
# zsh custom themes
[ -d "$HOME/.dotfiles/zsh/themes" ] && cp -f "$HOME/.dotfiles/zsh/themes/"*.zsh-theme "$ZSH/custom/themes"
fi
colorEcho "${ORANGE}Dotfiles & Scripts ${GREEN}successfully downloaded to ${FUCHSIA}${MY_SHELL_SCRIPTS}${GREEN}!"
if [[ -d "${MY_SHELL_SCRIPTS}/node_modules" ]]; then
colorEcho "${BLUE}Updating ${FUCHSIA}node modules${BLUE}..."
if [[ -x "$(command -v pnpm)" ]]; then
cd "${MY_SHELL_SCRIPTS}" && pnpm install
elif [[ -x "$(command -v npm)" ]]; then
cd "${MY_SHELL_SCRIPTS}" && npm install
fi
fi
cd "${CURRENT_DIR}" || exit