-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.sh
192 lines (169 loc) · 4.45 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
# shellcheck disable=SC1091
#==================================
# Source utilities
#==================================
. "$HOME/.dotfiles/scripts/utils/utils.sh"
df_main() {
OPT_1="Directory"
OPT_2="Edit"
OPT_3="Generate"
OPT_4="Sync"
OPT_9="Help"
OPT_0="Exit"
CHOICE=$(gum choose --height 10 "$OPT_1" "$OPT_2" "$OPT_3" "$OPT_4" "$OPT_9" "$OPT_0")
if [ "$CHOICE" == "$OPT_1" ]; then
df_sub_dir
elif [ "$CHOICE" == "$OPT_2" ]; then
df_sub_edit
elif [ "$CHOICE" == "$OPT_3" ]; then
df_sub_generate
elif [ "$CHOICE" == "$OPT_4" ]; then
df_sub_sync
elif [ "$CHOICE" == "$OPT_9" ]; then
df_sub_help
elif [ "$CHOICE" == "$OPT_0" ]; then
print_in_green " Bye!\n"
exit 0
fi
}
df_sub_dir() {
OPT_1="Open Directory"
OPT_2="CD Into Directory"
OPT_0="Back"
os_name="$(get_os)"
if [ "$os_name" == "macos" ]; then
OPT_1="Open Directory In Finder"
elif [ "$os_name" == "ubuntu" ]; then
OPT_1="Open Directory In File Browser"
fi
CHOICE=$(gum choose --height 10 "$OPT_1" "$OPT_2" "$OPT_0")
if [ "$CHOICE" == "$OPT_1" ]; then
printf " Opening .dotfiles directory\n"
open_dir "$HOME/.dotfiles"
exit 0
elif [ "$CHOICE" == "$OPT_2" ]; then
cd "$HOME/.dotfiles" || exit 1
elif [ "$CHOICE" == "$OPT_0" ]; then
df_main
fi
}
df_sub_edit() {
OPT_1="Compare Changes"
OPT_2="Launch In Editor"
OPT_0="Back"
CHOICE=$(gum choose --height 10 "$OPT_1" "$OPT_2" "$OPT_0")
if [ "$CHOICE" == "$OPT_1" ]; then
printf " Comparing config changes with upstream\n"
current_dir=$(pwd)
cd ~/.dotfiles && \
fish <<'END_FISH'
gd
END_FISH
cd "$current_dir" || exit 1
exit 0
elif [ "$CHOICE" == "$OPT_2" ]; then
printf " Launching .dotfiles project in code editor\n"
code ~/.dotfiles
exit 0
elif [ "$CHOICE" == "$OPT_0" ]; then
df_main
fi
}
df_sub_generate() {
OPT_1="Generate Symlinks"
OPT_2="Generate SSH"
OPT_3="Generate GPG"
OPT_0="Back"
CHOICE=$(gum choose --height 10 "$OPT_1" "$OPT_2" "$OPT_3" "$OPT_0")
if [ "$CHOICE" == "$OPT_1" ]; then
gum confirm "Do You Want To $CHOICE?"
if [ $? -eq 0 ]; then
bash ~/.dotfiles/system/symlink.sh
else
df_sub_generate
fi
elif [ "$CHOICE" == "$OPT_2" ]; then
gum confirm "Do You Want To $CHOICE?"
if [ $? -eq 0 ]; then
bash ~/.dotfiles/scripts/utils/generate_ssh.sh "--skip"
else
df_sub_generate
fi
elif [ "$CHOICE" == "$OPT_3" ]; then
gum confirm "Do You Want To $CHOICE?"
if [ $? -eq 0 ]; then
bash ~/.dotfiles/scripts/utils/generate_gpg.sh "--skip"
else
df_sub_generate
fi
elif [ "$CHOICE" == "$OPT_0" ]; then
df_main
fi
}
df_sub_sync() {
OPT_1="Initialize Repo"
OPT_2="Set Upstream"
OPT_3="Pull From Repo"
OPT_0="Back"
CHOICE=$(gum choose --height 10 "$OPT_1" "$OPT_2" "$OPT_3" "$OPT_0")
if [ "$CHOICE" == "$OPT_1" ]; then
if ! is_git_repository; then
cd "$HOME/.dotfiles" || exit 1
git init
else
print_warning "Git repository already initialized"
fi
elif [ "$CHOICE" == "$OPT_2" ]; then
if ! repo_has_remote_url; then
print_question "Paste your dotfiles repo\n"
GIT_ORIGIN=$(gum input --placeholder "[email protected]:excalith/.dotfiles.git")
git remote add origin "$GIT_ORIGIN"
else
print_warning "Git repository already has remote url"
fi
elif [ "$CHOICE" == "$OPT_3" ]; then
if ! is_git_repository; then
print_warning "Not a git repository"
else
git fetch --all 1> /dev/null \
&& git stash > /dev/null \
&& git pull \
&& git pop > /dev/null
fi
elif [ "$CHOICE" == "$OPT_0" ]; then
df_main
fi
}
df_sub_help() {
OPT_1="Terminal"
OPT_2="NeoVim"
OPT_3="Yabai"
OPT_0="Back"
os_name="$(get_os)"
if [ "$os_name" == "macos" ]; then
CHOICE=$(gum choose --height 10 "$OPT_1" "$OPT_2" "$OPT_3" "$OPT_0")
elif [ "$os_name" == "ubuntu" ]; then
CHOICE=$(gum choose --height 10 "$OPT_1" "$OPT_2" "$OPT_0")
else
CHOICE=$(gum choose --height 10 "$OPT_1" "$OPT_2" "$OPT_0")
fi
if [ "$CHOICE" == "$OPT_1" ]; then
cat < ~/.dotfiles/bin/dotfiles/alacritty.txt | gum filter
elif [ "$CHOICE" == "$OPT_2" ]; then
cat < ~/.dotfiles/bin/dotfiles/neovim.txt | gum filter
elif [ "$CHOICE" == "$OPT_3" ]; then
cat < ~/.dotfiles/bin/dotfiles/yabai.txt | gum filter
elif [ "$CHOICE" == "$OPT_0" ]; then
df_main
fi
}
main () {
gum style \
--foreground 212 --border-foreground 212 --border rounded \
--align center --width 40 --margin "0 0" --padding "0 0" \
'Excalith Dotfiles' 'Maintenance'
print_in_green "\n Select an option\n"
df_main
}
main