-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotfiles.sh
executable file
·95 lines (73 loc) · 2.61 KB
/
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
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
#!/bin/bash
source .env
SESSION_NAME="dotfiles"
GITHUB_REPO="git@github.com:EdgeLimits/.dotfiles.git"
DIRECTORY="$HOME/.dotfiles"
PERSONAL_GITHUB_REPO="git@github.com:EdgeLimits/.dotfiles-personal.git"
PERSONAL_DIRECTORY="$HOME/.dotfiles-personal"
WORK_GITHUB_REPO="git@github.com:EdgeLimits/.dotfiles-work.git"
WORK_DIRECTORY="$HOME/.dotfiles-work"
UPDATE_FLAG=0
if [[ " $@ " == *" --update "* ]]; then
UPDATE_FLAG=1
fi
if [[ "$(pwd)" != "$DIRECTORY" ]]; then
cd "$DIRECTORY" || {
echo "Failed to change directory to $DIRECTORY"
exit 1
}
fi
if [ ! -d "$DIRECTORY" ]; then
git clone $GITHUB_REPO "$DIRECTORY"
fi
if [[ "$DOTFILES_ENABLE_PERSONAL" == "True" ]] && [ ! -d "$PERSONAL_DIRECTORY" ]; then
git clone $PERSONAL_GITHUB_REPO "$PERSONAL_DIRECTORY"
fi
if [[ "$DOTFILES_ENABLE_WORK" == "True" ]] && [ ! -d "$WORK_DIRECTORY" ]; then
git clone $WORK_GITHUB_REPO "$WORK_DIRECTORY"
fi
if ! pgrep -x "tmux" >/dev/null; then
echo "Starting tmux server"
tmux start-server
fi
if ! tmux has-session -t $SESSION_NAME 2>/dev/null; then
echo "Creating new session: $SESSION_NAME"
tmux new-session -d -s $SESSION_NAME -n source
tmux send-keys -t $SESSION_NAME "cd $DIRECTORY" C-m
tmux send-keys -t $SESSION_NAME "nvim ." C-m
tmux new-window -t $SESSION_NAME -n shell
if [[ "$DOTFILES_ENABLE_PERSONAL" == "True" ]]; then
tmux new-window -t $SESSION_NAME -n personal-source
sleep 0.5
tmux send-keys -t $SESSION_NAME:personal-source "cd $PERSONAL_DIRECTORY" C-m
tmux send-keys -t $SESSION_NAME:personal-source "nvim ." C-m
tmux new-window -t $SESSION_NAME -n personal-shell
sleep 0.5
tmux send-keys -t $SESSION_NAME:personal-shell "cd $PERSONAL_DIRECTORY && clear" C-m
fi
if [[ "$DOTFILES_ENABLE_WORK" == "True" ]]; then
tmux new-window -t $SESSION_NAME -n work-source
sleep 0.5
tmux send-keys -t $SESSION_NAME:work-source "cd $WORK_DIRECTORY" C-m
tmux send-keys -t $SESSION_NAME:work-source "nvim ." C-m
tmux new-window -t $SESSION_NAME -n work-shell
sleep 0.5
tmux send-keys -t $SESSION_NAME:work-shell "cd $WORK_DIRECTORY && clear" C-m
fi
fi
if [[ "$UPDATE_FLAG" == "1" ]]; then
tmux send-keys -t $SESSION_NAME:shell "git pull && git submodule update --remote --merge" C-m
if [[ "$DOTFILES_ENABLE_PERSONAL" == "True" ]]; then
tmux send-keys -t $SESSION_NAME:personal-shell "git pull" C-m
fi
if [[ "$DOTFILES_ENABLE_WORK" == "True" ]]; then
tmux send-keys -t $SESSION_NAME:work-shell "git pull" C-m
fi
fi
if [[ -z $TMUX ]]; then
tmux attach-session -t $SESSION_NAME
tmux select-window -t :1
else
tmux switch-client -t $SESSION_NAME
fi
exit 0