-
Notifications
You must be signed in to change notification settings - Fork 1
/
add
executable file
·57 lines (49 loc) · 1.04 KB
/
add
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
51
52
53
54
55
56
57
#!/bin/bash
dir=$(readlink -f $(dirname $0))
locations=$dir/locations
function indent {
echo ":: $*"
}
function loc {
dir=$1
cat $locations | while read line; do
set -- $line
source="$1"
dest=$(eval echo $2)
if [ "$dir" = "$dest" ]; then
echo "$source"
exit 0
fi
done
exit 1
}
# Check that each argument is a file
for file in $*; do
if [[ -h $file ]]; then
echo "$0: $file is a link"
exit 1
fi
if [[ ! -e $file ]]; then
echo "$0: $file is not a file"
exit 1
fi
done
for file in $*; do
# Check if the file's parent directory
# is in the dotfiles location list
source=$(readlink -f $(dirname $1))
dest=$(loc $source)
# dir is not in locations, ask to add it.
if [ -z $dir ]; then
# TODO: support adding new locations
echo "$dir doesn't exist in dotfiles locations"
exit 1
else
set -o errexit
name=$(basename $file)
mv $file $dir/$dest/
ln -s $dir/$dest/$name $name
set +o errexit
indent "$name added to $dir, but not committed to git"
fi
done