-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotfiles.sh
executable file
·61 lines (53 loc) · 1.45 KB
/
dotfiles.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
#!/bin/bash
#
# defaults
DOTFILES_MASTER="$HOME/dotfiles"
INSTALL_PATH="$HOME"
echo "================"
echo "Install dotfiles"
echo "================"
echo "Install a dotfile to the system."
echo
echo "Usage: $0 install dotfile [-p installpath]"
echo " -p installation path (default: $HOME)"
echo
echo "Example: install <dotfile> <path_to_install_to>"
echo
echo "--------------------------------------------"
install() {
local dotfile="$1"
local installpath="$INSTALL_PATH"
if [ "$#" -eq 2 ]; then
installpath="$2"
fi
if [ ! -d "$installpath" ]; then
echo "Install path '$installpath' does not exist. Aborting."
return 1
fi
SRC="$DOTFILES_MASTER/$dotfile"
if [ -e "$SRC-$HOSTNAME" ]; then
SRC="$SRC-$HOSTNAME"
fi
if [ -f "$dotfile" ]; then
echo "Installing $dotfile to $installpath/$(basename "
$dotfile")"
ln -sfv "$SRC" "$installpath/$(basename "$SRC")"
else
echo "Error: $dotfile does not exist"
return 1
fi
}
# this should fail:
# install nullfile
# ================
# Install dotfiles
# ================
# ${dotfile//$'\r'} removes any carriage return characters that may be present in the input file.
# This can happen if the input file was created on a Windows system or if it was edited with certain
# text editors.
#
# -r: read the last line of the file even if it does not end with a newline character
while read -r dotfile; do
dotfile="${dotfile//$'\r'/}"
install "$dotfile"
done <.dotfiles