-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauto-configure-vim-tmux.js
More file actions
198 lines (181 loc) · 7.1 KB
/
auto-configure-vim-tmux.js
File metadata and controls
198 lines (181 loc) · 7.1 KB
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
193
194
195
196
197
198
// --------------------------------------------------------------------------
// -- auto-configure-vim-tmux.js
// --------------------------------------------------------------------------
//Helped by Github Copilot
//Helped by BardAI
const fs = require('fs');
// let link = "https://renickbell.net/vim/.vimrc"
async function fetchText(link) {
let response = await fetch(link);
let text = await response.text();
return text;
}
// let vimrc = await fetchText(link);
// //generated by BardAI: https://g.co/bard/share/8fab0ab55061
// //Modified by Steve
//
let homePath = process.env.HOME
// //helped by BardAI
//
// if (
// if (fs.existsSync(homePath + '.vimrc')
// //helped by BardAI
//
//Write a function that detects current operating system.
function detectOS() {
let os = process.platform;
return os;
}
async function createVimrcUnix() {
let vimrc = await fetchText("https://renickbell.net/vim/.vimrc")
fs.writeFileSync(homePath + '/.vimrc', vimrc);
}
async function createVimrcWindows() {
let vimrc = await fetchText("https://renickbell.net/vim/.vimrc")
fs.writeFileSync(homePath + '/_vimrc', vimrc);
}
function addTmuxConfig(vimrcPath) {
let contents = fs.readFileSync(vimrcPath, 'utf8');
contents += '\n"--------------------------'
contents += '\n"tmux config\n'
if (contents.includes('map <F3>') === false){
contents += '\nmap <F3> :call Tmux_Vars()<CR>'
console.log('Tmux_Vars() binded to <F3> added to vimrc')
}
if (contents.includes('map <F8>') === false){
contents += '\nmap <F8> V"by:call Send_to_Tmux(@b)<CR>'
console.log('Send_to_Tmux() binded to <F8> added to vimrc')
}
if (contents.includes('map <F9>') === false && contents.includes('map <F10>') === false){
contents += '\nmap <F10> vip'
contents += '\nmap <F9> <F10><CR>'
console.log('vip binded to <F10> and <F9> added to vimrc')
}
if (contents.includes('map <F11>') === false){
contents += '\nmap <F11> :call Send_to_Tmux(":{\n")<CR>vip:normal @g<CR>:call Send_to_Tmux(":}\n")<CR>k'
console.log('Send_to_Tmux binded to <F10> and <F9> added to vimrc')
}
if (contents.includes('map <F12>') === false){
contents += '\nmap <F12> :call Send_to_Tmux("withSC3 Sound.SC3.ID.reset\n")<CR>'
console.log('withSC3 Sound.SC3.ID.reset binded to <F12> added to vimrc')
}
if (contents.includes('map \-') === false){
contents += '\nmap \- :call Send_to_Tmux(":{\n")<CR>vip:normal @g<CR>:call Send_to_Tmux(":}\n")<CR>k'
console.log('Send_to_Tmux() binded to \- added to vimrc')
}
if (contents.includes('map \;') === false){
contents += '\nmap \; :call Send_to_Tmux(":{\n")<CR>vip:normal @g<CR>:call Send_to_Tmux(":}\n")<CR>k'
console.log('Send_to_Tmux() binded to \; added to vimrc')
}
if (contents.includes('map <CR>') === false){
contents += '\nmap <CR> V"by:call Send_to_Tmux(@b)<CR>'
console.log('Send_to_Tmux() binded to <CR> added to vimrc')
}
if (contents.includes('vmap \<CR\>') === false){
contents += 'vmap <CR> "by:call Send_to_Tmux(@b)<CR>'
console.log('Send_to_Tmux() vmap to <CR> added to vimrc')
}
fs.writeFileSync(vimrcPath, contents);
}
function findVimrcOnUnix() {
let homePath = process.env.HOME;
if (fs.existsSync(homePath + '/.vimrc') === false && fs.existsSync(homePath + '/.vim/vimrc') === false) {
console.log('vimrc not found')
createVimrcUnix()
return true
}
else if (fs.existsSync(homePath + '/.vimrc')){
console.log('Checking if add tmux conf to vimrc')
addTmuxConfig(homePath + '/.vimrc')
}
else if (fs.existsSync(homePath + '/.vim/vimrc')){
console.log('Checking if add tmux conf to vimrc')
addTmuxConfig(homePath + '/.vimrc')
}
else if (fs.existsSync(homePath + '/.vim/vimrc')){
addTmuxConfig(homePath + '/.vim/vimrc')
}
return false
}
function findVimrcOnWindows() {
let homePath = process.env.HOME;
if (fs.existsSync(homePath + '/_vimrc') === false || fs.existsSync(homePath + '/vimfiles/vimrc') === false){
console.log('vimrc found')
createVimrcWindows()
return true
}
else if (fs.existsSync(homePath + '/_vimrc')){
console.log('Checking if add tmux conf to vimrc')
addTmuxConfig(homePath + '/_vimrc')
}
else if (fs.existsSync(homePath + '/vimfiles/vimrc')){
console.log('Checking if add tmux conf to vimrc')
addTmuxConfig(homePath + '/vimfiles/vimrc')
}
return false
}
//vimrc locations: https://stackoverflow.com/a/60932757/19515980
async function createTslimeUnix() {
let tslime = await fetchText("https://renickbell.net/vim/plugin/tslime.vim")
//Check if the .vim directory exists if it does not create it in the homepath:
if (fs.existsSync(homePath + '/.vim') === false){
fs.mkdirSync(homePath + '/.vim')
console.log('.vim directory created')
}
//check if the plugin directory exists if it does not create it in the .vim directory:
if (fs.existsSync(homePath + '/.vim/plugin') === false){
fs.mkdirSync(homePath + '/.vim/plugin')
console.log('.vim/plugin directory created')
}
fs.writeFileSync(homePath + '/.vim/plugin/tslime.vim', tslime);
console.log('tslime.vim created for Unix')
}
async function createTslimeWindows() {
let vimrc = await fetchText("https://renickbell.net/vim/plugin/tslime.vim")
//Check if the .vim directory exists if it does not create it in the homepath:
if (fs.existsSync(homePath + '/vimfiles') === false){
fs.mkdirSync(homePath + '/vimfiles')
console.log('vimfiles directory created')
}
//check if the plugin directory exists if it does not create it in the .vim directory:
if (fs.existsSync(homePath + '/vimfiles/plugin') === false){
fs.mkdirSync(homePath + '/vimfiles/plugin')
console.log('vimfiles/plugin directory created')
}
fs.writeFileSync(homePath + '/vimfiles/plugin/tslime.vim', vimrc);
console.log('tslime.vim created for Windows')
}
function findTslimeOnUnix() {
if (fs.existsSync(homePath + '/.vim/plugin/tslime.vim') === false){
console.log('creating tslime for Unix')
createTslimeUnix()
return true
}
console.log('Tslime already exists')
return false
}
function findTslimeOnWindows() {
if (fs.existsSync(homePath + '/vimfiles/plugin/tslime.vim') === false){
console.log('creating tslime for windows')
createTslimeWindows()
return true
}
console.log('Tslime already exists')
return false
}
//https://superuser.com/questions/1391565/how-to-install-vim-plugin-in-windows-10
// function installSuperColliderPlugins() {
let platform = detectOS();
if (platform === 'linux' || platform === 'darwin'){
findVimrcOnUnix();
findTslimeOnUnix();
}
else if (platform === 'win32'){
findVimrcOnWindows();
findTslimeOnWindows();
}
if (platform === 'darwin'){
installSuperColliderPlugins()
}
//Meaning of process.os(): https://stackoverflow.com/a/8684009/19515980
//VIM does not come witha .vimrc: https://g.co/bard/share/d3ace3c4963d