forked from puppetlabs/puppetlabs-rcfiles
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoverwritelinks.sh
More file actions
executable file
·87 lines (71 loc) · 1.53 KB
/
overwritelinks.sh
File metadata and controls
executable file
·87 lines (71 loc) · 1.53 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
#!/bin/bash
# Find the script dir
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P )"
RCFILES="bashrc minttyrc vimrc vim muttrc mutt screenrc tmux.conf gemrc ackrc gitconfig"
# ANSI COLOR CODES
CL="\e[0m"
BO="\e[1m"
UN="\e[4m"
BL="\e[5m"
IN="\e[7m"
HI="\e[8m"
RE="\e[27m"
FK="\e[30m"
FR="\e[31m"
FG="\e[32m"
FY="\e[33m"
FB="\e[34m"
FP="\e[35m"
FC="\e[36m"
FW="\e[37m"
BK="\e[40m"
BR="\e[41m"
BG="\e[42m"
BY="\e[43m"
BB="\e[44m"
BP="\e[45m"
BC="\e[46m"
BW="\e[47m"
WARNING="${IN}${FY}${BK}Warning:${CL}"
INFO="${IN}${BK}${FG}Info :${CL}"
ERROR="${IN}${BK}${FR}Error :${CL}"
function overwrite_link() {
SOURCE="$1"
FILE="$2"
if [ ! -h ~/.${FILE} ]
then
echo -e "${WARNING} ~/.${FILE} is not a symlink already. Skipping it." 2> /dev/stderr
return 1
fi
echo -e "${INFO} Creating symlink ~/.${FILE} => ${SOURCE}/${FILE}"
ln -sfn ${SOURCE}/${FILE} ~/.${FILE}
return $?
}
function do_it() {
if [ $# != 1 ]
then
echo -e "${ERROR} Expected 1 argument. Got $#"
exit 1
fi
RCFILES="$1"
count=0
for f in ${RCFILES}
do
overwrite_link ${SRCDIR} $f
test $? == 0 && let count++
done
echo -e "${INFO} Files modified: ${count}"
}
echo -e "${WARNING} You're about to replace the following symlinks: ~/.${RCFILES// /, ~\/.}"
echo -e "${INFO} The script will only replace symlinks. It will not touch files or directories."
echo -en "${INFO} Do you want to proceed (yes/NO)? "
read -n 1 ANSWER
echo
case ${ANSWER} in
y|Y)
do_it "${RCFILES}"
;;
*)
echo -e "${ERROR} Cancelled"
;;
esac