-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack_dotfiles.sh
executable file
·62 lines (50 loc) · 1.38 KB
/
pack_dotfiles.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
55
56
57
58
59
60
61
62
#!/bin/bash
COMMAND=$1
if [[ "$COMMAND" == "pack" ]]; then
HOME_DIR="$HOME"
DOTFILES_DIR="$HOME/dotfiles"
PLUGIN_DIR="$HOME_DIR/.config/.vim/plugged"
TMUX_DIR="$HOME_DIR/.tmux"
nvim -c "PlugUpdate"
cd /tmp
mkdir dotfiles; cd dotfiles
cp -R $PLUGIN_DIR .
cp -R $DOTFILES_DIR .
cp -R $TMUX_DIR .
date > "sync_date.txt"
find dotfiles -name ".git" | xargs rm -Rf
cd ..
tar -cvf $HOME/dotfiles.tar ./dotfiles
rm -Rf /tmp/dotfiles
cd $HOME
elif [[ "$COMMAND" == "unpack" ]]; then
if [[ -z $2 ]]; then
TARGET_OS="linux"
else
TARGET_OS=$2
fi
# Linux
if [[ -n "$WSL_DISTRO_NAME" ]]; then
export WIN_USER=$(powershell.exe '$env:USERNAME' | tr -d '\r')
if [[ "$TARGET_OS" == "win" ]]; then
# Windows dirs via WSL
HOME_DIR="/mnt/c/Users/$WIN_USER"
PLUGIN_DIR="$HOME_DIR/.config/nvim/plugged"
DOTFILES_DIR="$HOME_DIR/dotfiles"
else
#All linux distros
HOME_DIR="$HOME"
PLUGIN_DIR="$HOME_DIR/.config/.vim/plugged"
DOTFILES_DIR="$HOME_DIR/dotfiles"
TMUX_DIR="$HOME_DIR/.tmux"
fi
fi
CURRENT_DIR=$(basename "$PWD")
if [[ "$CURRENT_DIR" == "dotfiles" && "$PWD" != "$DOTFILES_DIR" ]]; then
rsync -av ../plugged/ "$PLUGIN_DIR/"
rsync -av ../dotfiles/ "$DOTFILES_DIR/"
echo "Unpacked completed"
else
echo "ERROR - Cannot unpack from current location"
fi
fi