-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymlink.sh
executable file
·37 lines (33 loc) · 1.11 KB
/
symlink.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
#!/bin/bash
files=$(find * -mindepth 2 -path 'home/t/.local/bin' -prune -o -print)
for f in $files; do
target=/$f
# Directories: don't symlink back to repo
if [ -d $f ]; then
# Make the target dir if it doesn't exist
if [ ! -d $target ]; then
echo \> mkdir $target
mkdir $target
else
echo "[$target] directory exists"
fi
fi
# if the target file doesn't exist _and_ is a symlink (aka broken symlink),
# remove it
if [ ! -f $target ] && [ -L $target ]; then
rm $target
fi
# If the target file doesn't exist (is neither file nor directory)
if [ ! -f $target ] && [ ! -d $target ]; then
echo \> ln -s $(pwd)/$f $target
ln -s $(pwd)/$f $target
else
echo "[$target] already linked, skipping"
fi
done
# .local/bin is an exception: it _should_ link back to this repo, so I don't
# have to add each new script
if [ ! -f /home/t/.local/bin ] && [ ! -L /home/t/.local/bin ]; then
echo \> ln -s $(pwd)/home/t/.local/bin /home/t/.local/bin
ln -s $(pwd)/home/t/.local/bin /home/t/.local/bin
fi