-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_symlinks.sh
executable file
·105 lines (91 loc) · 2.96 KB
/
create_symlinks.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
#!/bin/bash
#
# Description:
# This script will create a symlink for all the files and folders
# in this repository in the $HOME folder.
################################################################################
################################################################################
# Constant Variables
################################################################################
SCRIPT=`basename $0`
IGNORE_LIST=(".DS_Store" "." ".." ".gitignore" ".git")
PWD=`pwd`
OVERRIDE_FILES=false
NUMARGS=$#
NOW=$(date +"%m_%d_%Y")
################################################################################
# Methods
################################################################################
# Print help message to STDOUT
help_message() {
echo ""
log "Help documentation for ${SCRIPT}"
log "Basic usage: ${SCRIPT}"
log "The following switches are recognized."
log "-o -- optional, override existing files"
log "-h -- Displays this help message."\\n
log "Example: ${SCRIPT}"\\n
exit 1
}
################################################################################
# Command line arguments
################################################################################
log () {
echo -e "${SCRIPT}_${NOW}: $@"
}
# Parse command line flags
while getopts oh flag; do
case $flag in
o) # Set the OVERRIDE_FILES variable to true
OVERRIDE_FILES=true
;;
h) # show help message
help_message
;;
\?) # unrecognized option - show help message
log -e \\n"Option -${OPTARG} not allowed." \\n\\n
help_message
;;
esac
done
################################################################################
# Start of script
################################################################################
# Exit on any failure
set -e
# Create Vim backup folder
mkdir -p ~/.vim/backup/
# Loop through the files in this repository
for file in .*; do
# Ignore any file from the ignore list
ignore_file_flag=false
for ignore_file in "${IGNORE_LIST[@]}"; do
if [[ "${ignore_file}" = "${file}" ]]; then
ignore_file_flag=true
break
fi
done
if [[ "${ignore_file_flag}" = true ]]; then
log Ignoring "${file}"
continue
fi
if [[ -e "${HOME}/${file}" && "${OVERRIDE_FILES}" = true ]]; then
mv -f "${HOME}/${file}" "/tmp/${file}-$(date '+%Y-%m-%d_%H:%M:%S')"
fi
if [[ -L "${HOME}/${file}" ]]; then
# Ignore if the file exists and is already a symlink
if [[ "${PWD}/${file}" = `readlink ${HOME}/${file}` ]]; then
log "Symlink already exists for ${file}"
else
log "Symlink already exists but have a different link."
fi
elif [[ -f "${HOME}/${file}" ]]; then
log "An existing file was found at ${HOME}/${file}"
elif [[ -d "${HOME}/${file}" ]]; then
log "An existing folder was found at ${HOME}/${file}"
else
# Create a symlink for the remaining files
log "Creating symlink for ${file}"
ln -s "${PWD}/${file}" "${HOME}/${file}"
fi
done