-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinks.sh
executable file
·49 lines (37 loc) · 987 Bytes
/
links.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
#!/bin/env zsh
PREFIX="/home/$USER/config/apps"
CFG_PATH=$(realpath .. | sed "s#/home/$USER/##")
ENV_NAME=$([[ "$(hostname)" =~ "$(cat work_hostname.priv).*" ]] && echo work || echo personal)
echo "env: $ENV_NAME"
# all paths are relative to ~/
if [ -f mappings.priv ]; then
source mappings.priv
else
echo 'please define path mappings'
fi
################################################################################
# create links
echo "prefix: $PREFIX"
cd ~/
# create link ~/config -> ${CFG_PATH}
CFG_DIR=$( basename "$CFG_PATH" )
echo "cfg_dir: $CFG_DIR"
if [ ! -r"$CFG_DIR" ]; then
ln -sv "$CFG_PATH" .
else
echo "cfg path link already exists"
fi
echo
for src dest in "${PATHS[@]}"; do
if [ -f "$dest" ] || [ -d "$dest" ]; then
if [ ! -e "$dest" ]; then
echo 'broken symlink, removing'
rm -v "$dest"
else
echo "File '$dest' already exists, skip"
continue
fi
else
ln -vs "$src" "$dest"
fi
done