-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotctl
executable file
·184 lines (162 loc) · 5.02 KB
/
dotctl
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
set -eu
set -o pipefail
# Copy a file if it does not exist
# Skip if the diff is empty
# Interactively resolve the diff if needed
dotctl_vimdiff() {
if [[ "${#}" -ne 2 ]]; then
exit 1
fi
if [[ ! -e "${1}" ]]; then
echo "[+] Installing ${2} to ${1}..."
cp -i "${2}" "${1}"
return
fi
if [[ -z "$(diff "${1}" "${2}")" ]]; then
echo "[+] Skippping (empty diff) ${1}"
else
echo "[+] Updating ${1}..."
vimdiff "${1}" "${2}"
fi
}
# Diff files from this repo with the ones in $HOME
dotctl_diff() {
# Diff configuration files prefixed by a '.' in $HOME
for f in 'bashrc' 'zshrc' 'tmux.conf' 'vimrc' 'colordiffrc' 'digrc'; do
dotctl_vimdiff "${HOME}/.${f}" "${f}"
done
# Diff configuration files in $HOME/.shell/
for f in 'shell/'*.{sh,bash,zsh}; do
dotctl_vimdiff "${HOME}/.shell/$(basename "${f}")" "${f}"
done
# Diff configuration files in $HOME/.config directories
for f in 'git/'*; do
dotctl_vimdiff "${HOME}/.config/git/$(basename "${f}")" "${f}"
done
}
# Initial installation on a fresh system
dotctl_install() {
# Use any argument to bypass this check
if [[ "${#}" -ne 1 ]]; then
echo 'READ ME before blindly launching me!!'
exit 1
fi
# Git config directory setup
mkdir -p "${HOME}/.config/git"
# Shell setup
mkdir -p "${HOME}/.shell/history"
pushd "${HOME}/.shell/" > /dev/null
curl -Sso 'dircolors.256dark' \
'https://raw.githubusercontent.com/seebi/dircolors-solarized/master/dircolors.256dark'
if [[ ! -d 'zsh-syntax-highlighting' ]]; then
git clone 'https://github.com/zsh-users/zsh-syntax-highlighting.git'
fi
popd > /dev/null
# Vim setup
for d in 'autoload' 'bundle' 'backup' 'undodir'; do
mkdir -p "${HOME}/.vim/${d}"
done
# Install pathogen plugin
curl -Sso "${HOME}/.vim/autoload/pathogen.vim" \
'https://raw.githubusercontent.com/tpope/vim-pathogen/master/autoload/pathogen.vim'
pushd "${HOME}/.vim/bundle/" > /dev/null
# bogado/file-line: Open a file and go to specified line using <filename>:<line>
# tpope/vim-fugitive: a Git wrapper so awesome, it should be illegal
# tpope/vim-markdown: Vim Markdown runtime files
# tpope/vim-git: Vim Git runtime files
# altercation/vim-colors-solarized: precision colorscheme for the vim text editor
# ciaranm/securemodelines: A secure alternative to Vim modelines
# tpope/vim-commentary: comment stuff out
# dahu/SearchParty: Extended search commands and maps for Vim
# dahu/vim-fanfingtastic: Find a char across lines
# tpope/vim-repeat: enable repeating supported plugin maps with "."
# scrooloose/syntastic: Syntax checking hacks for vim
# tpope/vim-surround: quoting/parenthesizing made simple
# wting/rust.vim: Rust support
# tpope/vim-unimpaired: pairs of handy bracket mappings
# fatih/vim-go: Go development plugin for Vim
# editorconfig/editorconfig-vim: Editor Config support
plugins=(
'https://github.com/bogado/file-line.git'
'https://github.com/tpope/vim-fugitive.git'
'https://github.com/tpope/vim-markdown.git'
'https://github.com/tpope/vim-git.git'
'https://github.com/altercation/vim-colors-solarized.git'
'https://github.com/ciaranm/securemodelines.git'
'https://github.com/tpope/vim-commentary.git'
'https://github.com/dahu/SearchParty.git'
'https://github.com/dahu/vim-fanfingtastic.git'
'https://github.com/tpope/vim-repeat.git'
'https://github.com/scrooloose/syntastic.git'
'https://github.com/tpope/vim-surround.git'
'https://github.com/wting/rust.vim.git'
'https://github.com/tpope/vim-unimpaired.git'
'https://github.com/fatih/vim-go.git'
'https://github.com/editorconfig/editorconfig-vim.git'
)
for p in "${plugins[@]}"; do
if [[ ! -d ${p##*/} ]]; then
git clone "${p}"
fi
done
popd > /dev/null
# Update all other dotfiles
dotctl_diff
}
# Update all Git clone plugins and additions then diff config files
dotctl_update() {
pushd "${HOME}/.vim/bundle" > /dev/null
for b in *; do
pushd "${b}" > /dev/null
echo "[+] Updating ${b}..."
# Update failures are not fatal
git pull origin || echo "[!] Failed to update ${b}"
popd > /dev/null
done
popd > /dev/null
pushd "${HOME}/.shell" > /dev/null
for d in "zsh-syntax-highlighting"; do
if [[ -d "${d}" ]]; then
pushd "${d}" > /dev/null
echo "[+] Updating ${d}..."
# Update failures are not fatal
git pull origin || echo "[!] Failed to update ${d}"
popd > /dev/null
fi
done
popd > /dev/null
# Update all other dotfiles
dotctl_diff
}
dotctl_help() {
>&2 echo "Install and update dotfiles"
>&2 echo ""
>&2 echo "USAGE:"
>&2 echo " dotctl [SUBCOMMAND]"
>&2 echo ""
>&2 echo "SUBCOMMANDS:"
>&2 echo " install Install Bash, Zsh, Vim, Git, etc. configs"
>&2 echo " update Update Vim plugins and Zsh highligh Git repos"
>&2 echo " diff Diff and update dotfiles"
}
main() {
if [[ "${#}" -eq 0 ]]; then
dotctl_help
return
fi
case "${1}" in
"d" | "diff")
dotctl_diff ;;
"u" | "update")
dotctl_update ;;
"i" | "install")
dotctl_install "${@}";;
*)
>&2 echo "Uknown command!"
dotctl_help
exit 1 ;;
esac
echo "[+] Done!"
}
main "${@}"