-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup
More file actions
executable file
·77 lines (62 loc) · 1.48 KB
/
setup
File metadata and controls
executable file
·77 lines (62 loc) · 1.48 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
#!/bin/bash
#
# Script to setup dot files in $HOME.
#
# There are two mechanisms for creating the symlinks:
#
# * For files/dirs matching '_*', a symlink ('.*') is created int '$HOME'
# pointing back into this git repo.
#
# * For files/dirs matching 'cfg_*', a symlink ('*') is created in
# '$HOME/.config' pointing back into this git repo.
#
unalias ls 2>/dev/null
BASE="${PWD#${HOME}/}"
cd $HOME
function create_link() {
tgt="$1"
lnk="$2"
if [ ! -e "${tgt}" ]
then
# Don't create broken symlinks
echo "skip: missing target: ${tgt}"
return 1
fi
if [ -e "${lnk}" ]
then
if [ -L "${lnk}" ]
then
echo "skip: symlink exists: ${lnk}"
else
echo "skip: file exists (not a symlink): ${lnk}"
fi
return 1
fi
if [ -L "${lnk}" ]
then
# When `-e` fails and `-L` succeeds, the symlink is broken.
echo "Rmoving broken link: ${lnk}"
rm "${lnk}"
fi
echo ln -s "${tgt}" "${lnk}"
ln -s "${tgt}" "${lnk}"
}
# Stop globs from returning '${BASE}/_*' if nothing matches glob.
shopt -s nullglob
for tgt in ${BASE}/_*
do
lnk="$(basename ${tgt})"
lnk=".${lnk#_}"
create_link "${tgt}" "${lnk}"
done
create_link ${BASE}/LSP LSP
cfg_tgts=(
${BASE}/cfg_*
)
cd ${HOME}/.config
for tgt in "${cfg_tgts[@]}"
do
lnk="$(basename ${tgt})"
lnk="${lnk#cfg_}"
create_link "../${tgt}" "${lnk}"
done