-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·95 lines (81 loc) · 2.52 KB
/
install.sh
File metadata and controls
executable file
·95 lines (81 loc) · 2.52 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
#!/bin/bash
# abort on error
set -e
INSTALL_DEPS=0
INSTALL_FORCE=0
DOTFILES_REPO_DIR="${DOTFILES_REPO_DIR:-${HOME}/dotfiles}"
# Function to display help message
function display_help() {
cat <<EOF
Usage: $0 [OPTIONS]
Options:
--deps Install also the additional packages required by some functions and aliases.
--force Force the installation of all dotfiles [WARNING: this command backs all old files under ${DOTFILES_REPO_DIR}/backup].
-h, --help Display this help message and exit.
Examples:
$0
$0 --skip-deps
EOF
}
function parse_script_args() {
while [[ "$#" -gt 0 ]]; do
case "$1" in
--deps)
INSTALL_DEPS=1
;;
--force)
INSTALL_FORCE=1
;;
-h | --help)
display_help
exit 0
;;
*)
echo "Unknown option: $1"
;;
esac
shift
done
}
parse_script_args "$@"
echo "🕒 Installing dotfiles..."
if [[ INSTALL_DEPS -eq 1 ]]; then
# install all the additional dependencies using brew
"${DOTFILES_REPO_DIR}/brew.sh"
# source brew env
if [ -f /opt/homebrew/bin/brew ]; then
# typical path where resides on macOS
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [ -f /home/linuxbrew/.linuxbrew/bin/brew ]; then
# typical path where resides on linux
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
fi
if [[ INSTALL_FORCE -eq 1 ]]; then
# move all conflicting files under ~/.dot-backup
mkdir -p "${DOTFILES_REPO_DIR}/backup"
# Preview stow actions to find conflicting files
CONFLICTS=$(
stow -n -v -d "$DOTFILES_REPO_DIR" -t "${HOME}" . 2>&1 \
| grep 'neither a link nor a directory' \
| awk -F'over existing target ' '{print $2}' \
| awk -F' since' '{print $1}' \
| xargs
)
if [[ -n "$CONFLICTS" ]]; then
mkdir -p "${DOTFILES_REPO_DIR}/backup"
for file in $CONFLICTS; do
if [[ -e "${HOME}/${file}" ]]; then
mv "${HOME}/${file}" "${DOTFILES_REPO_DIR}/backup/"
echo "💾 Backup conflicting file ${file} to ${DOTFILES_REPO_DIR}/backup"
fi
done
fi
fi
# install dotfiles
# shellcheck disable=SC1091
source "${DOTFILES_REPO_DIR}/.functions"
stow -d "${DOTFILES_REPO_DIR}" -t "${HOME}" .
dot-add-env --local DOTFILES_REPO_DIR="${DOTFILES_REPO_DIR}"
echo "✅ Dotfiles successfully installed!"
echo "Run 'dot-install' to sync the dotfiles in your current shell."