-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.sh
executable file
·117 lines (93 loc) · 2.3 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
111
112
113
114
115
116
117
#!/bin/bash
print_usage() {
cat >&2 <<_END_
Copy or symlink .ycm_extra_conf.py and related files to a target directory.
Usage: $0 -h
$0 [-l] target
Options:
-h This help message.
-l Symlink all files.
-L flags Symlink selected files:
y = .ycm_extra_conf.py
c = ycm_jsondb_core.py
C = ycm_jsondb_config.py
-s dir The source directory to get files from. If not given or a
particular file does not exist in the source directory, the file
in the directory of the script is copied.
_END_
}
usage_error() {
print_usage
exit 2
}
get_source_file() {
local filename="$1"
if [ -n "$source_dir" -a -e "${source_dir}/${filename}" ]; then
echo "${source_dir}/${filename}"
else
echo "${script_dir}/${filename}"
fi
}
# -------- Main body --------
symlink=
source_dir=
while getopts "hlL:s:" Option; do
case $Option in
h)
print_usage
exit
;;
l)
symlink=ycC
;;
L)
symlink="$OPTARG"
;;
s)
source_dir="$OPTARG"
;;
*)
usage_error
;;
esac
done
shift $(($OPTIND - 1))
target_directory="$1"
if [ -z "$target_directory" ]; then
usage_error
fi
set -e
readlink=greadlink
# No greadlink, so we are probably on Linux
hash greadlink 2>/dev/null || { readlink=readlink; }
script_dir=$($readlink -ev "$(dirname "$(which "$0")")")
target_directory=$($readlink -ev "$target_directory")
if [ -n "$source_dir" ]; then
source_dir=$($readlink -ev "$source_dir")
fi
ln_command="ln -s"
cp_command="cp -u"
if [[ "$symlink" == *y* ]]; then
ycm_command="$ln_command"
else
ycm_command="$cp_command"
fi
if [[ "$symlink" == *c* ]]; then
core_command="$ln_command"
else
core_command="$cp_command"
fi
if [[ "$symlink" == *C* ]]; then
config_command="$ln_command"
else
config_command="$cp_command"
fi
set +e
error=0
$ycm_command "$(get_source_file ycm_extra_conf.jsondb.py)" "$target_directory/.ycm_extra_conf.py"
((error+=$?))
$core_command "$(get_source_file ycm_jsondb_core.py)" "$target_directory/ycm_jsondb_core.py"
((error+=$?))
$config_command "$(get_source_file ycm_jsondb_config.py)" "$target_directory/ycm_jsondb_config.py"
((error+=$?))
exit $error