-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·97 lines (83 loc) · 1.97 KB
/
install.sh
File metadata and controls
executable file
·97 lines (83 loc) · 1.97 KB
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
#!/usr/bin/env bash
# ----------------------------------------------------------------------------
# DESCRIPTION
# Installs the project dotfiles on the local system
#
# EXAMPLES
# install.sh
#
# OPTIONS
# -c Copy the dotfiles instead of using symlinks (Windows)
#
# ----------------------------------------------------------------------------
# --- Env --------------------------------------------------------------------
export DOTFILES="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
readonly BACKUP="$HOME/.dotbackup"
# --- Strict Mode ------------------------------------------------------------
set -euo pipefail
# --- Options ----------------------------------------------------------------
copy_flag=''
OPTIND=1
while getopts 'c' flag; do
case "${flag}" in
c) copy_flag='true' ;;
*) error "Unexpected option ${flag}" ;;
esac
done
# --- Data -------------------------------------------------------------------
set -euo pipefail
INSTALL_FILES=(
'.aliases'
'.bash_profile'
'.bashrc'
'.env'
'.functions'
'.vimrc'
'.zshrc'
)
# --- Functions --------------------------------------------------------------
init() {
echo 'Setting up ...'
source "$DOTFILES/.env"
mkdir -p $BACKUP
}
# Creates the dev directory structure
create_dirs() {
echo
echo 'Creating directories ...'
for i in "${DEV_PATHS[@]}"
do
:
echo " → $i"
mkdir -p $i
done
}
# Installs a single dotfile, backing up any existing file
install_dotfile() {
echo " → $1"
SRC="$DOTFILES/$1"
DEST="$HOME/$1"
if [[ -f $DEST ]]; then
cp $DEST $BACKUP
fi
rm -f $DEST
if [[ $copy_flag == 'true' ]]; then
cp $SRC $DEST
else
ln -s $SRC $DEST
fi
}
# Installs all the configured dotfiles as symlinks
install_dotfiles() {
echo
echo 'Installing dotfiles ...'
for i in "${INSTALL_FILES[@]}"
do
:
install_dotfile $i
done
}
# --- Body -------------------------------------------------------------------
init
create_dirs
install_dotfiles