-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·111 lines (89 loc) · 3.3 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
#!/usr/bin/env bash
# Filename: install.sh
# Created: 2013-04-22 23:34:09
# Desc: Linux Configuration files
# Author: xutao(Tony Xu), [email protected]
# Company: myself
mkdir -p "$HOME/workspace"
mkdir -p "$HOME/Music"
mkdir -p "$HOME/software"
mkdir -p "$HOME/.config"
# Create mpd dir tree
mkdir -p "$HOME/.mpd/playlists" && touch "$HOME"/.mpd/{db,log,pid,state,sticker.sql}
GIT_CLONE='git clone -q --depth 1'
oh_zsh_dir=$HOME/.oh-my-zsh
DOTFILES_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
ok() { echo -e " \033[1;32m✔\033[0m $1"; }
tips() { echo -e " \033[1;33m?\033[0m $1"; }
skip() { echo -e " \033[1;33m!\033[0m $1"; }
link_file()
{
overwrite_all=${overwrite_all:-false}
backup_all=${backup_all:-false}
skip_all=${skip_all:-false}
local src=$1 dst=$2
local overwrite backup skip action
if [[ -e "$dst" ]]; then
if [[ "$overwrite_all" == "false" && "$backup_all" == "false" && "$skip_all" == "false" ]]; then
if [[ "$(readlink "$dst")" == "$src" ]]; then
skip=true
else
tips "File already exists: $dst ($(basename "$src")), what do you want to do?\n\
[s]kip, [S]kip all, [o]verwrite, [O]verwrite all, [b]ackup, [B]ackup all?"
read -rsn 1 action
case "$action" in
o ) overwrite=true;;
O ) overwrite_all=true;;
b ) backup=true;;
B ) backup_all=true;;
s ) skip=true;;
S ) skip_all=true;;
* ) ;;
esac
fi
fi
overwrite=${overwrite:-$overwrite_all}
backup=${backup:-$backup_all}
skip=${skip:-$skip_all}
[[ "$overwrite" == "true" ]] && rm -rf "$dst" && ok "removed $dst"
[[ "$backup" == "true" ]] && mv "$dst" "${dst}.backup" && ok "moved $dst to ${dst}.backup"
[[ "$skip" == "true" ]] && skip "skipped $src"
fi
# "false" or empty
[[ "$skip" != "true" ]] && ln -s "$1" "$2" && ok "linked $1 to $2"
}
do_link_dir()
{
local src_dir=$1 dst_dir=$2 filter=$3
for src in `ls $src_dir $filter`
do
link_file "$src_dir$src" "$dst_dir$src"
done
}
config_zsh()
{
set -i "s|ZSH=.*|ZSH=$oh_zsh_dir|g" "$DOTFILES_DIR"/zshrc
[ -d "$oh_zsh_dir" ] && return
$GIT_CLONE https://github.com/robbyrussell/oh-my-zsh.git "$oh_zsh_dir"
# Plugins
local plugins_dir="$oh_zsh_dir/custom/plugins"
local themes_dir="$oh_zsh_dir/custom/themes"
# $GIT_CLONE https://github.com/skywind3000/z.lua "$plugins_dir"/z.lua
$GIT_CLONE https://github.com/z-shell/F-Sy-H.git "$plugins_dir"/F-Sy-H
$GIT_CLONE https://github.com/zsh-users/zsh-autosuggestions "$plugins_dir"/zsh-autosuggestions
$GIT_CLONE https://github.com/djui/alias-tips "$plugins_dir"/alias-tips
curl --create-dirs -fLo "$themes_dir"/hhktony.zsh-theme \
https://raw.githubusercontent.com/hhktony/hhktony.zsh-theme/master/hhktony.zsh-theme
# $GIT_CLONE https://github.com/zsh-users/zsh-completions "$plugins_dir"/zsh-completions
}
main()
{
local overwrite_all=false backup_all=false skip_all=false
do_link_dir $HOME/.dotfiles/ $HOME/. '-I ssh -I config -I README.md -I install.sh'
do_link_dir $HOME/.dotfiles/config/ $HOME/.config/
[ ! -e ~/.git-prompt.sh ] && curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.git-prompt.sh
config_zsh
}
main
echo ''
echo ' All installed!'