-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
81 lines (65 loc) · 2.3 KB
/
install
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
#!/usr/bin/env bash
# https://github.com/bradp/dotfiles/blob/main/misc/install
# Set up colors.
_colors_bold=$(tput bold)
_colors_red=$(tput setaf 1)
_colors_green=$(tput setaf 2)
_colors_cyan=$(tput setaf 6)
_colors_reset=$(tput sgr0)
# Get the dotfiles dir in case it's named something else.
_script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )";
# _dotfiles_dir="${_script_dir%/*}"
_dotfiles_dir="${_script_dir}"
# Confirm the path.
echo ""
echo -e "The dotfiles folder is set as ${_colors_bold}${_colors_cyan}${_dotfiles_dir}${_colors_reset}. Is this correct?"
read -r -p "(press enter to confirm or type in a new path) " confirm
# If a new path is passed in, confirm it.
if [ -n "$confirm" ]; then
if [[ ! -d "$confirm" ]]; then
echo -e "${_colors_red}Could not find ${_colors_bold}${confirm}${_colors_reset}, please re-run the script.${_colors_reset}"
exit 1
fi
# set to the new dir.
_dotfiles_dir="$confirm"
# Confirm the new path.
echo -e "The dotfiles folder is now set as ${_colors_bold}${_colors_cyan}${_dotfiles_dir}${_colors_reset}. Is this correct?"
read -r -p "(press enter to confirm) " confirm
if [ -n "$confirm" ]; then
echo -e "${_colors_red}Quitting, please re-run the script.${_colors_reset}"
exit 1
fi
fi
echo ""
echo -e "${_colors_green}Setting up dotfiles in ${_colors_bold}${_dotfiles_dir}${_colors_reset}..."
echo ""
_files_to_symlink="
.config/nvim
.config/wezterm
.zsh
.zshrc
.vimrc
.p10k.zsh
"
mkdir -p "$HOME/.config"
# Symlink them up
for f in $_files_to_symlink; do
echo "${_colors_cyan}${_dotfiles_dir}/${f}${_colors_reset} ${_colors_bold}→${_colors_reset} ${_colors_cyan}$HOME/${f}${_colors_reset}"
if [[ -L "$HOME/$f" ]]; then
# If it's already a symlink, skip it.
echo "${_dotfiles_dir}/$f is already symlinked, skipping..."
elif [[ ! -f "${_dotfiles_dir}/$f" && ! -d "${_dotfiles_dir}/$f" ]]; then
# Make sure the target file exists in the dotfiles before symlinking.
echo "Could not find ${_dotfiles_dir}/$f, skipping..."
else
# If the file already exists, back it up first.
if [[ -f "$HOME/$f" || -d "$HOME/$f" ]]; then
echo "$HOME/$f already exists, backing it up..."
mv "$HOME/$f" "$HOME/$f.backup"
fi
ln -nfsv "${_dotfiles_dir}/$f" "$HOME/$f" 1> /dev/null
fi
done
echo ""
echo "${_colors_green}Dotfiles symlinked.${_colors_reset}"
echo ""