summaryrefslogtreecommitdiff
path: root/.local/bin/config-symlinks
blob: 7d889f0e3b0edc4850162cfd1dfb003894b6329f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash

declare -i ret=0

while read _target _link; do
	target="$(sed -rn 's|[^/]+/|../|g;s|/[^/]+$|/|p' <<<"$_link")${_target}"
	link="$HOME/$_link"
	if [[ -L "$link" ]]; then
		rm -f "$link"
	fi
	if [[ -e "$link" ]]; then
		echo "ERROR: file exists: $link" >> /dev/stderr
		ret=1
	else
		mkdir -p "${link%/*}"
		ln -s "$target" "$link"
	fi
done < <(sed -e '/^\s*$/d' -e '/#/d' "$XDG_CONFIG_HOME/symlinks")

exit $ret