-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·113 lines (95 loc) · 2.3 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·113 lines (95 loc) · 2.3 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
# vim: et sw=2 ft=sh
# Symlink-based Installer/syncer script to keep
# dotfiles easily editable and up-to-date.
set -e
BOOTSTRAP=0
VERBOSE=0
BKPDIR="$HOME/.dot-backups/bkp-`date +'%b-%d-%y_%H:%M:%S'`"
while (( $# )); do
case $1 in
--bootstrap | -b)
BOOTSTRAP=1
;;
--verbose | -v)
VERBOSE=1
;;
*)
echo "Error: Unrecognized option!"
exit 1
;;
esac
shift
done
msg() {
if (( VERBOSE )); then
printf "%s\n" "$*" >&2
fi
}
backup_dot() {
local src=$1
local dstdir="${BKPDIR}/${src##$HOME/}"
mkdir -p $dstdir
mv $src $dstdir
echo "${dstdir}/$(basename $src)"
}
sync_dot_file() {
local file=$1
local link=${2:-$file}
local src="${PWD}/${file}"
local tgt="${HOME}/${link}"
if [[ -L "$tgt" && "$(readlink -f $tgt)" == "$(readlink -f $src)" ]]; then
#msg "Skipping ${file} -> ${link} [already installed]"
return 0
fi
mkdir -pv "$(dirname "$tgt")"
if [[ -f "$tgt" || -d "$tgt" ]]; then
msg "Replacing ${file} -> ${link} [bkp: $(backup_dot $tgt)]"
else
msg "Linking ${file} -> ${link}"
fi
ln -sf $src $tgt
}
install_vim_plugins() {
# install the Vundle plugins configured in .vimrc
msg "Installing vim plugins..."
command vim -u vim/plugins.vim +PlugInstall +qall
command nvim -u vim/lua/config/lazy.lua '+Lazy sync' +qall
}
install_tmux_plugins() {
msg "Installing tmux plugins..."
tmux/plugins/tpm/scripts/install_plugins.sh
}
# Install submodules
if (( BOOTSTRAP )); then
msg "Fetching submodules..."
git submodule update --init --recursive
fi
# Sync plain/simple dot files/dirs
for d in * config/*; do
case "$d" in
config/*)
sync_dot_file "$d" ".config/${d##config/}"
;;
config)
continue
;;
*)
sync_dot_file "$d" ".${d}"
;;
esac
done
platform_name="$(uname | tr '[:upper:]' '[:lower:]')"
platform_config_dir="config-${platform_name}"
msg "Installing ${platform_name}-specific dot files.."
while IFS= read -r file; do
link=".config/${file##"$platform_config_dir/"}"
sync_dot_file "$file" "$link"
done < <(find "${platform_config_dir}" -type f)
# Install vim plugins (using Plug for now)
install_vim_plugins
install_tmux_plugins
# TODO: Check how to install pacman hooks without root access
# Reload shell
echo "Done." >&2
exec $SHELL -l