-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.sh
executable file
·54 lines (42 loc) · 1.06 KB
/
sync.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
51
52
53
54
#!/usr/bin/env bash
# Silent pushd
pushd () {
command pushd "$@" > /dev/null
}
# Silent popd
popd () {
command popd > /dev/null
}
sync_folders() {
pushd configuration
echo "$(tput setaf 64)$(tput bold)SYNCING DIRECTORIES $(tput sgr0)"
for directory in $(find . -type d -maxdepth 1 -mindepth 1 | cut -c 3-); do
printf "%-15s %-15s %-15s %-15s\n" "[copying]" "$directory" "--->" "$HOME/.$directory"
command cp -R "$directory/." "$HOME/.$directory"
done
popd
}
sync_files() {
pushd files
echo "$(tput setaf 64)$(tput bold)SYNCING DOTFILES $(tput sgr0)"
for file in *; do
printf "%-15s %-15s %-15s %-15s\n" "[copying]" "$file" "--->" "$HOME/.$file"
command cp "$file" "$HOME/.$file"
done
popd
}
run() {
sync_folders
sync_files
# shellcheck source=/dev/null
source "$HOME"/.bash_profile
}
if [ "$1" == "--force" ] || [ "$1" == "-f" ]; then
run
else
read -rp "$(tput setaf 124)This may overwrite existing files in your home directory. Are you sure? (y/n) $(tput sgr0)" -n 1
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
run
fi
fi