-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlink.sh
executable file
·50 lines (43 loc) · 1.18 KB
/
link.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
50
#! /usr/bin/env bash
if [ "$1" == "-d" ]; then
echo "WARNING: Delete mode"
mode="-D"
elif [ "$1" == "-r" ]; then
echo "WARNING: Restow mode"
mode="-R"
else
#default mode (create links)
mode=""
fi
cd "$(dirname "$0")"
dirs="$(ls -d */)"
target="$HOME"
if ! [ -d ~/.vim ]; then
# create as dir, avoid symlinking by stow
mkdir ~/.vim
fi
# check for office environment
if getent passwd | grep -q "ffritzer"; then
echo "Office environment, removing target 'xfce-full'"
dirs="$(echo "$dirs" | sed "s/xfce-full\/ \?//")"
else
echo "Non-office environment, removing target 'office'"
dirs="$(echo "$dirs" | sed "s/office\/ \?//")"
fi
# verbose dry-run
echo "Dry-run for setup to \"$target\" of dirs: "$dirs
stow -vn $mode -t "$target" $dirs
if [ $? != 0 ]; then
if output=$(git status --porcelain) && [ -z "$output" ]; then
# Working directory clean
echo "There are conflicts, adopting repository - Check git status and resolve all issues afterwards!"
modflag="--adopt"
else
# Uncommitted changes
echo "There are conflicts and the local repository is not clean, cannot continue!"
exit 1
modflag=""
fi
fi
read -p "Press enter to continue..."
stow -v $mode $modflag -t "$target" $dirs