-
Notifications
You must be signed in to change notification settings - Fork 15
/
symlink.sh
executable file
·164 lines (142 loc) · 3.89 KB
/
symlink.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
#!/bin/sh
# vars
parent_dir=$(basename "$(pwd)")
msg=$(git log -1 --pretty=%B)
_CONFIG_DIR="config"
_COC_FILE="config/coc-settings.json"
_WIKI_FILE="config/Wim.wiki"
_CHEAT_FILE="config/cheat40.txt"
_VIMRC_FILE="wim-vim"
_VIMWIKI_INDEX="index.wiki"
_VIMRC_FILE_DEST="$HOME/.vim/vimrc"
_COC_FILE_DEST="$HOME/.vim/coc-settings.json"
_WIKI_FILE_DEST="$HOME/.vim/vimwiki/Wim.wiki"
_CHEAT_FILE_DEST="$HOME/.vim/cheat40.txt"
_VIM_PATH="$HOME/.vim"
_WIKI_DIR="$_VIM_PATH/vimwiki"
_VIM_BK_PATH="$HOME/vim-bk"
_ARCHIVE_NAME="uctags-2024.06.20-linux-x86_64.tar.gz"
_ARCHIVE_EXTRACTED_NAME="uctags-2024.06.20-linux-x86_64"
# backup
backup()
{
if [ -d "$_VIM_PATH" ]; then
mv "$_VIM_PATH" "$_VIM_BK_PATH"
mkdir -p "$_VIM_PATH"
mkdir -p "$_WIKI_DIR"
else
mkdir -p "$_VIM_PATH"
mkdir -p "$_WIKI_DIR"
fi
}
# download ctags
downloadCtags()
{
ctags_url="https://github.com/universal-ctags/ctags-nightly-build/releases/download/2024.06.20%2B8976ec3d2c48ec862593910388ae3e55f0e20a3f/uctags-2024.06.20-linux-x86_64.tar.gz"
curl -Lo "$_ARCHIVE_NAME" "$ctags_url"
tar -xzf "$_ARCHIVE_NAME"
mkdir -p "$_VIM_PATH/uctags"
mv "$_ARCHIVE_EXTRACTED_NAME"/* "$_VIM_PATH/uctags/"
rm -rf "$_ARCHIVE_EXTRACTED_NAME"
rm "$_ARCHIVE_NAME"
}
# Check parent wim dir exists
checkWimExist()
{
if [ "$parent_dir" = "wim" ]; then
printf "Wim Directory Exists!\nProceeding ...\n"
else
printf "Wim Directory Does Not Exists!\nBreaking! ...\n"
exit 1
fi
if [ -d "$_CONFIG_DIR" ]; then
printf "Config Directory Exists!\nProceeding ...\n"
else
printf "Config Directory Does Not Exists!\nBreaking! ...\n"
exit 1
fi
}
# link the files
linkFiles()
{
printf "\e[42;30mSymlinking Latest Vimrc\e[0m\n"
ln -sf "$(pwd)/$_VIMRC_FILE" "$_VIMRC_FILE_DEST"
printf "\e[42;30mSymlinking Latest CoC Settings\e[0m\n"
ln -sf "$(pwd)/$_COC_FILE" "$_COC_FILE_DEST"
printf "\e[42;30mCopying Latest Wim Wiki\e[0m\n"
cp "$(pwd)/$_WIKI_FILE" "$_WIKI_FILE_DEST"
printf "\e[42;30mSymlinking Latest Cheat File\e[0m\n"
ln -sf "$(pwd)/$_CHEAT_FILE" "$_CHEAT_FILE_DEST"
echo ""
echo "[[Wim]]" >> "$_WIKI_DIR/$_VIMWIKI_INDEX"
}
createUpdateScript()
{
cat << 'EOF' > update.sh
#!/bin/sh
# vars
parent_dir=$(basename "$(pwd)")
msg=$(git log -1 --pretty=%B)
_CONFIG_DIR="config"
_COC_FILE="config/coc-settings.json"
_WIKI_FILE="config/Wim.wiki"
_CHEAT_FILE="config/cheat40.txt"
_VIMRC_FILE="wim-vim"
_VIMWIKI_INDEX="index.wiki"
_VIMRC_FILE_DEST="$HOME/.vim/vimrc"
_COC_FILE_DEST="$HOME/.vim/coc-settings.json"
_WIKI_FILE_DEST="$HOME/.vim/vimwiki/Wim.wiki"
_CHEAT_FILE_DEST="$HOME/.vim/cheat40.txt"
_VIM_PATH="$HOME/.vim"
_WIKI_DIR="$_VIM_PATH/vimwiki"
# Check parent wim dir exists
checkWimExist()
{
if [ "$parent_dir" = "wim" ]; then
printf "Wim Directory Exists!\nProceeding ...\n"
else
printf "Wim Directory Does Not Exists!\nBreaking! ...\n"
exit 1
fi
if [ -d "$_CONFIG_DIR" ]; then
printf "Config Directory Exists!\nProceeding ...\n"
else
printf "Config Directory Does Not Exists!\nBreaking! ...\n"
exit 1
fi
}
# link the files
linkFiles()
{
printf "\e[42;30mSymlinking Latest Vimrc\e[0m\n"
ln -sf "$(pwd)/$_VIMRC_FILE" "$_VIMRC_FILE_DEST"
printf "\e[42;30mSymlinking Latest CoC Settings\e[0m\n"
ln -sf "$(pwd)/$_COC_FILE" "$_COC_FILE_DEST"
printf "\e[42;30mCopying Latest Wim Wiki\e[0m\n"
cp "$(pwd)/$_WIKI_FILE" "$_WIKI_FILE_DEST"
printf "\e[42;30mSymlinking Latest Cheat File\e[0m\n"
ln -sf "$(pwd)/$_CHEAT_FILE" "$_CHEAT_FILE_DEST"
echo ""
}
checkWimExist
linkFiles
printf "\e[43;30mMessage From Woland: %s\e[0m\n" "$msg"
EOF
chmod +x update.sh
echo "Update Script Generated!"
}
main()
{
backup
downloadCtags
checkWimExist
linkFiles
createUpdateScript
}
main
printf "\e[43;30mPress Enter To Continue...\e[0m\n"
printf "\e[44;30mWhen CoC finishes installing a few extensions, you can exit Vim.\e[0m\n"
vim
# Get latest commit msg and show to user
printf "\e[43;30mMessage From Woland: %s\e[0m\n" "$msg"
printf "\e[42;30mAll Done! Enjoy!\e[0m\n"