/
install.sh
executable file
·110 lines (93 loc) · 3.1 KB
/
install.sh
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
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Name :install.sh
# Description :Creates symbolic links from the 'dotfiles' repository location
# to the home of the current user on macOS. If a dotfile or
# directory already exists in the users home, the script prompts
# for confirmation before deleting and replacing the file (or
# or link) with a symbolic link.
# Author :Merlin Unterfinger <info@munterfinger.ch>
# Date :2020-05-17
# Version :0.1.1
# Usage :./install.sh
# Notes :Only files and links will be deleted and replaced. If there
# directories present in the users home, which should be
# replaced by a symbolic link, delete them manually.
# Bash :5.0.17(1)-release
# =============================================================================
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
confirm() {
# Source: https://mike632t.wordpress.com/2017/07/06/bash-yes-no-prompt/
local _prompt _default _response
if [ "$1" ]; then _prompt="${1}"; else _prompt="Are you sure"; fi
_prompt="${_prompt} [y/n] ?"
# Loop forever until the user enters a valid response (Y/N or Yes/No)
while true; do
read -r -p "${_prompt} " _response
case "${_response}" in
[Yy][Ee][Ss] | [Yy]) # Yes or Y (case-insensitive)
return 0
;;
[Nn][Oo] | [Nn]) # No or N (case-insensitive)
return 1
;;
*) # Anything else (including a blank) is invalid
;;
esac
done
}
function lns_home() {
echo "-> Linking: ${BASEDIR}/${1} <- ~/${1}"
# Omit -rf flag as it throws an error if it is a directory (safer)
ln -s "${BASEDIR}/${1}" "${HOME}/${1}"
}
function create_link() {
local filename="${1}"
echo "Configure: '~/${filename}'"
# Check if directory and not symbolic link to a directory exists
if [ -d "${HOME}/${filename}" ] && [ ! -h "${HOME}/${filename}" ]; then
echo -e "-> Warning: Directory '~/${filename}' already exists.
Please check directory content and remove manually."
echo "-> Linking: '~/${filename}' skipped."
else
# Check if file, link to a file or link to a directory exists
if [ -f "${HOME}/${filename}" ] || [ -d "${HOME}/${filename}" ]; then
# Remove and replace?
echo "-> Warning: File or link '~/${filename}' already exists."
if confirm " Replace with a symbolic link?"; then
rm "${HOME}/${filename}"
lns_home "${filename}"
else
echo "-> Linking: '~/${filename}' skipped."
fi
else
lns_home "${filename}"
fi
fi
}
# Create the symbolic links: Add manually, do not use loops!
# bin
create_link bin
# zsh
create_link .zshenv
create_link .zshrc
create_link .zprofile
create_link .zsh
# bash
create_link .bash_profile
# SSH
create_link .ssh/config
# vim
create_link .vimrc
create_link .vim
# starship
create_link .config/starship.toml
# hyper
create_link .hyper.js
# R
create_link .R/Makevars
# git
# create_link .gitconfig
# create_link .gitignore
# Restart SHELL
exec $SHELL