-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-dotfiles
executable file
·99 lines (82 loc) · 2.51 KB
/
install-dotfiles
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
#!/bin/bash
export TERM=xterm-256color
DOTFILES_DIRECTORY="${HOME}/dotfiles"
DOTFILES_GIT_REMOTE="https://github.com/mmcintire96/dotfiles.git"
# Helper Functions
# Header logging
e_header() {
printf "\n$(tput setaf 7)%s$(tput sgr0)\n" "$@"
}
# Success logging
e_success() {
printf "$(tput setaf 64)✓ %s$(tput sgr0)\n" "$@"
}
# Error logging
e_error() {
printf "$(tput setaf 1)x %s$(tput sgr0)\n" "$@"
}
# Warning logging
e_warning() {
printf "$(tput setaf 136)! %s$(tput sgr0)\n" "$@"
}
# Test whether we're in a git repo
is_git_repo() {
$(git rev-parse --is-inside-work-tree &> /dev/null)
}
# Test whether a command exists
# $1 - cmd to test
type_exists() {
if [ $(type -P $1) ]; then
return 0
fi
return 1
}
## Main Code
# If missing, download and extract the dotfiles repository
if [[ ! -d ${DOTFILES_DIRECTORY} ]]; then
printf "$(tput setaf 7)Downloading dotfiles...\033[m\n"
git clone ${DOTFILES_GIT_REMOTE}
mv dotfiles ${DOTFILES_DIRECTORY}
fi
cd ${DOTFILES_DIRECTORY}
# Conditionally sync with the remote repository
if [[ $no_sync ]]; then
printf "Skipped dotfiles sync.\n"
else
e_header "Syncing dotfiles..."
# Pull down the latest changes
git pull --rebase origin master
# Update submodules
git submodule update --recursive --init --quiet
fi
link() {
# Force create/replace the symlink.
ln -fs "${DOTFILES_DIRECTORY}/${1}" "${HOME}/${2}"
}
mirrorfiles() {
# Copy `.gitconfig`.
# Any global git commands in `~/.bash_profile.local` will be written to
# `.gitconfig`. This prevents them being committed to the repository.
#rsync -avz --quiet ${DOTFILES_DIRECTORY}/git/gitconfig ${HOME}/.gitconfig
# Force remove the vim directory if it's already there.
if [ -e "${HOME}/.vim" ]; then
rm -rf "${HOME}/.vim"
fi
# Create the necessary symbolic links between the `.dotfiles` and `HOME`
# directory. The `bash_profile` sources other files directly from the
# `.dotfiles` repository.
link "bash/bashrc" ".bashrc"
link "bash/profile" ".profile"
link "bash/bash_profile" ".bash_profile"
link "zsh/zshrc" ".zshrc"
#link "input/inputrc" ".inputrc"
#link "git/gitattributes" ".gitattributes"
link "git/gitignore" ".gitignore"
link "vim" ".vim"
#link "vim" ".vim"
link "vim/vimrc" ".vimrc"
link "tmux/tmux.conf" ".tmux.conf"
e_success "Dotfiles update complete!"
}
mirrorfiles
source ${HOME}/.bash_profile