blob: f103090e00e161a75e0e1cb5729db3ddf6929955 (
plain) (
blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/bin/bash
set -e
dir="$(cd "$(dirname "$0")" && pwd)"
os=$(uname --operating-system)
CMD=$SYSTEMROOT/System32/cmd.exe
filter() {
fname="files/$(basename "$@")"
if [[ "$fname" == "files/." || "$fname" == "files/.." ]] ; then
return 0
fi
return 1
}
create_windows_link() {
fp=$1
tp=$2
opt=""
if [ -d "$fp" ] ; then
opt="/D"
fi
if [[ 1 = $OVERRIDE ]] ; then
rm --recursive --force "$tp"
else
rm --force "$tp"
fi
$CMD /c mklink $opt $(cygpath --windows "$tp") $(cygpath --windows "$fp") >/dev/null
}
create_link() {
while read fp tp ; do
case "$os" in
"Cygwin") create_windows_link "$fp" "$tp" ;;
*) ln --symbolic --force --no-target-directory "$fp" "$tp" ;;
esac
done
}
check_command() {
if ! $(which "$1" >/dev/null 2>&1) ; then
echo "No $1." >&2
if $(which "command-not-found" >/dev/null 2>&1) ; then
command-not-found "$1"
fi
fi
}
check_fzf() {
if [ ! -d $HOME/.fzf ] ; then
read -p "Install fzf? (y/n): "
if [ "y" == "$REPLY" ] ; then
git clone --depth 1 https://github.com/junegunn/fzf.git $HOME/.fzf
$HOME/.fzf/install --all --no-update-rc
fi
fi
}
after_install() {
mkdir -p $HOME/tmp/vim-undo $HOME/tmp/vim-backup
mkdir -p $HOME/.mutt/cache
touch $HOME/.mutt/aliases
check_fzf
check_command ag
}
check_override() {
while read filename ; do
fp=$dir/files/$filename
tp=$HOME/$filename
if [[ 1 != $OVERRIDE ]] ; then
rp=$(readlink -f "$tp")
if [[ -e "$rp" && "$rp" != "$fp" ]] ; then
echo "Skip: $filename" >&2
continue
fi
fi
echo "$fp" "$tp"
done
}
if [[ "-f" = "$1" ]] ; then
OVERRIDE=1
fi
cd && \
( ls --format=single-column --almost-all "$dir/files" | check_override | create_link ) && \
after_install
|