-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsymlink.sh
More file actions
executable file
·47 lines (41 loc) · 1.19 KB
/
Copy pathsymlink.sh
File metadata and controls
executable file
·47 lines (41 loc) · 1.19 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
#!/bin/bash
function symlink() {
source=$1
target=$2
# Make directories, but don't link them.
if [ -d $source ]; 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
else
# If the target file appears to be a broken symlink (is a symlink but
# the file doesn't exist), remove it.
if [ ! -e $target ] && [ -h $target ]; then
echo "[$target] appears broken, removing..."
rm $target
fi
# If the target file doesn't exist, link it.
if [ ! -f $target ] && [ ! -d $target ]; then
echo \> ln -s $(pwd)/$source $target
ln -s $(pwd)/$source $target
else
echo "[$target] already linked, skipping"
fi
fi
}
# Symlink configuration files
cd config
files=$(find .)
for f in $files; do
target=$HOME/$f
symlink $f $target
done
cd ..
# Entire scripts directory gets symlinked back to this repo (so I don't have to
# link when writing new scripts).
rm $HOME/.local/bin
ln -s $(pwd)/localbin $HOME/.local/bin