-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·138 lines (120 loc) · 4.67 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
132
133
134
135
136
137
138
#!/usr/bin/env bash
#set -e # exit script when error happens
#set -u # report error if visiting undeclared variable
echo_start() {
echo "$(tput setaf 6)------$(tput sgr0) $*"
}
echo_ask() {
echo "[ $(tput setaf 3)??$(tput sgr0) ] $*"
}
echo_info() {
echo "[ $(tput setaf 5)..$(tput sgr0) ] $*"
}
safe_ln() {
local -r target=$1
local -r symlink=$2
[[ ! -e $target ]] && echo "$(tput setaf 1)target $target does not exsit. Won't do symlink!$(tput sgr0)" && return
local yn="y"
if [[ -e $symlink ]]; then
yn="n"
echo_ask "$(tput setaf 2)$symlink$(tput sgr0) exists. Overwrite it? [y/n]"
read -rn 1 yn
fi
if [[ $yn == "y" ]]; then
rm "$symlink"
ln -sf "$target" "$symlink"
# \b to delete previous char
echo -e "\bCreate symlink $(tput setaf 2)$symlink$(tput sgr0) -> $(tput setaf 5)$target$(tput sgr0)"
else
echo -e "\bWon't overwrite $(tput setaf 2)$symlink$(tput sgr0)"
fi
}
prepare() {
export DOTFILES_HOME=$HOME/.dotfiles
[[ ! -e $DOTFILES_HOME ]] && git clone https://github.com/fjchen7/dotfiles "$DOTFILES_HOME"
export XDG_CONFIG_HOME=$HOME/.config
[[ ! -d $XDG_CONFIG_HOME ]] && mkdir -p "$XDG_CONFIG_HOME"
# soft link oh-my-zsh custom configuration
git clone https://github.com/ohmyzsh/ohmyzsh "$DOTFILES_HOME/config/oh-my-zsh" --depth 1
local zsh_custom_plugins="$DOTFILES_HOME/config/oh-my-zsh/custom/plugins"
mkdir -p "$zsh_custom_plugins"
git clone https://github.com/Aloxaf/fzf-tab "$zsh_custom_plugins/fzf-tab" --depth 1
git clone https://github.com/djui/alias-tips "$zsh_custom_plugins/alias-tips" --depth 1
git clone https://github.com/zsh-users/zsh-autosuggestions "$zsh_custom_plugins/zsh-autosuggestions" --depth 1
git clone https://github.com/zsh-users/zsh-completions "$zsh_custom_plugins/zsh-completions" --depth 1
git clone https://github.com/zsh-users/zsh-syntax-highlighting "$zsh_custom_plugins/zsh-syntax-highlighting" --depth 1
git clone https://github.com/TamCore/autoupdate-oh-my-zsh-plugins "$zsh_custom_plugins/autoupdate" --depth 1
}
setup_zsh() {
echo_start "Start to setup zsh"
local local_configs=(zshenv zshrc)
for i in "${local_configs[@]}"; do
local file=$DOTFILES_HOME/zsh/$i.local
[[ ! -e $file ]] && cp "$file.example" "$file" && echo "Create $file"
done
}
setup_git() {
echo_start "Start to setup git"
local file=$DOTFILES_HOME/git/gitconfig.local
[[ ! -e $file ]] && cp "$file.example" "$file" && echo "Create $file"
# -q quiet
if grep -Fq "USERNAME" "$file"; then
echo 'setup gitconfig.local'
echo_ask ' - What is your github user name?'
read -re user_name
echo_ask ' - What is your github user email?'
read -re user_email
sed -i '' -e "s/USERNAME/$user_name/g" -e "s/USEREMAIL/$user_email/g" "$file"
echo 'Git user name and email are configured.'
fi
}
setup_cheatsheets() {
echo_start "Start to setup cheatsheet"
CHEATSHEETS_HOME=$DOTFILES_HOME/cheatsheets
local yn="n"
if [[ -e $CHEATSHEETS_HOME ]]; then
echo "$CHEATSHEETS_HOME exits. Won't do anything."
else
echo_ask "Create $CHEATSHEETS_HOME? [y/n]"
read -rn 1 yn
fi
[[ $yn != "y" ]] && return
local target=
echo_ask "Prepare to crate symlink $CHEATSHEETS_HOME, please input the target directory: "
read -r target
safe_ln "$target" "$CHEATSHEETS_HOME"
}
setup_tools() {
echo_start "Start to setup tools"
echo_ask "Setup tools? [y/n]"
read -rn 1 yn
[[ $yn != 'y' ]] && echo_info "Won't steup tools" && return
# install formulas
brew update
# basic
brew install go zsh starship tmux autojump bash vim less ripgrep exa fd fzf navi bat jq httpie procs gh git-extras git-delta koekeishiya/formulae/yabai yqrashawn/goku/goku
# good tools
brew install tree thefuck tokei beeftornado/rmtree/brew-rmtree pstree dust duf nnn dog
# dev tools
brew install python shellcheck yarn node cmake openssl
# gnu replacement
brew install coreutils findutils gnutls gnu-sed gnu-which gawk grep gnu-tar gzip watch
# macos utility
brew install qlcolorcode qlstephen qlmarkdown quicklook-json qlimagesize suspicious-package apparency qlvideo
# install nodejs package
npm install -g tldr
}
setup_config() {
echo_start "Start to setup ~/.config"
safe_ln "$DOTFILES_HOME/config" "$XDG_CONFIG_HOME"
local -r home_configs=($(find "$XDG_CONFIG_HOME/HOME" -mindepth 1))
for file_path in "${home_configs[@]}"; do
safe_ln "$file_path" "$HOME/.$(basename "$file_path")"
done
}
prepare
setup_config
setup_tools
setup_zsh
setup_git
setup_cheatsheets