-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.lua
594 lines (539 loc) · 20.3 KB
/
init.lua
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
vim.opt.runtimepath:append("c:/.local/share/nvim-data/site/")
local function fileExists(filePath)
local file = io.open(filePath, "r")
if file then
file:close()
return true
end
return false
end
local function getFileLastModified(filePath)
local fileInfo = vim.loop.fs_stat(filePath)
if fileInfo then
return fileInfo.mtime.sec
end
return nil
end
local function isFileOlderThanOneDay(filePath)
local lastModified = getFileLastModified(filePath)
-- vim.notify(filePath .. "LastModified: " .. vim.inspect(lastModified))
if lastModified then
local currentTime = os.time()
local oneDayInSeconds = 24 * 60 * 60
return lastModified < (currentTime - oneDayInSeconds)
end
return false
end
local function runCommandIfFileOlderThanOneDay(filePath, command)
if (not fileExists(filePath)) or isFileOlderThanOneDay(filePath) then
-- vim.notify("executing {" .. command .. "}")
vim.fn.system(command)
else
-- vim.notify("file {" .. filePath .. "} was last modified in the last day, keeping it. ")
end
end
local function extractPackageId(inputString)
local pattern = '<package id="([^"]-)"'
local packageName = inputString:match(pattern)
return packageName
end
local function ensureWingetSettings()
local settings = [[
{
"$schema": "https://aka.ms/winget-settings.schema.json",
// For documentation on these settings, see: https://aka.ms/winget-settings
// "source": {
// "autoUpdateIntervalInMinutes": 5
// },
"interactivity": {
"disable": true
},
"experimentalFeatures": {
"windowsFeature": true,
"configuration": true,
"directMSI": true,
"experimentalARG": true,
"experimentalCMD": true
}
}
]]
local wingetIsExecutable = vim.fn.executable("winget") == 1
vim.notify(vim.inspect(wingetIsExecutable))
local localAppDataPackages =
vim.fs.normalize((os.getenv("localappdata") or os.getenv("userprofile") .. "/AppData/local") .. "/Packages")
local defaultIsReadable = vim.fn.filereadable(
localAppDataPackages .. "/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe/LocalState/settings.json"
) == 1
if defaultIsReadable then
else
end
end
function UseChocoToInstallAllTheThings()
-- local currentPackagesExportPath = "c:\\temp\\packages.config"
local currentPackagesExportPath = "c:/temp/packages.config"
local currentPackagesConfig = vim.fs.find("packages.config", { path = "c:\\temp\\" })[1] or ""
if not currentPackagesConfig == currentPackagesExportPath then
-- vim.notify("running choco Export to " .. currentPackagesExportPath)
vim.fn.system("choco export " .. currentPackagesExportPath)
else
-- vim.notify("running choco export if the file is missing or older than a day " .. currentPackagesExportPath)
runCommandIfFileOlderThanOneDay(currentPackagesExportPath, "choco export " .. currentPackagesExportPath)
end
local chocoPackagesConfig = vim.fs.find("packages.config", { path = vim.fn.stdpath("config") })[1] or ""
-- vim.notify(
-- "found packages.config in config dir that had these packages:\n" .. vim.inspect(installsFromPackagesConfig)
-- )
local linesForMissingPackagesConfig = {
[[ <?xml version="1.0" encoding="utf-8"?>]],
[[<packages>]],
[[ <package id="7zip" />]],
[[ <package id="bottom" />]],
[[ <package id="chocolatey" />]],
[[ <package id="curl" />]],
[[ <package id="docker" />]],
[[ <package id="fzf" />]],
[[ <package id="gdu" />]],
[[ <package id="gh" />]],
[[ <package id="git" />]],
[[ <package id="github-desktop" />]],
[[ <package id="gzip" />]],
[[ <package id="ilspy" />]],
[[ <package id="lazygit" />]],
[[ <package id="llvm" />]],
[[ <package id="nerd-fonts-JetBrainsMono" />]],
[[ <package id="nodejs" />]],
[[ <package id="notepadplusplus" />]],
[[ <package id="powertoys" />]],
[[ <package id="pwsh" />]],
[[ <package id="ripgrep" />]],
[[ <package id="SQLite" />]],
[[ <package id="tree-sitter" />]],
[[ <package id="Wget" />]],
[[ <package id="zig" />]],
[[</packages>]],
}
if chocoPackagesConfig == "" then
vim.fn.writefile(linesForMissingPackagesConfig, vim.fn.stdpath("config") .. "/packages.config")
end
chocoPackagesConfig = vim.fn.stdpath("config") .. "/packages.config"
local allPackagesLinesFromDistro = {}
for i, p in ipairs(vim.fn.readfile(chocoPackagesConfig, "")) do
table.insert(allPackagesLinesFromDistro, extractPackageId(p))
end
local allPackagesLinesFromCurrent = {}
for i, p in ipairs(vim.fn.readfile(currentPackagesExportPath, "")) do
table.insert(allPackagesLinesFromCurrent, extractPackageId(p))
end
local differences = {}
for i, p in ipairs(allPackagesLinesFromDistro) do
if not vim.tbl_contains(allPackagesLinesFromCurrent, p) then
table.insert(differences, p)
end
end
-- for i, p in ipairs(allPackagesLinesFromCurrent) do
-- if not vim.tbl_contains(allPackagesLinesFromDistro, p) then
-- table.insert(differences, p)
-- end
-- end
if vim.tbl_count(differences) > 0 then
-- vim.notify("Not included in current choco packages :" .. vim.inspect(differences))
end
local packageToExecutableName = {
["7zip"] = "7z",
["autohotkey"] = "autohotkey",
["bottom"] = "btm",
["chocolatey"] = "choco",
["curl"] = "curl",
["docker"] = "docker",
["docker-cli"] = "docker",
["dotnet"] = "dotnet",
-- ["dotnet-6.0-desktopruntime"] = "dotnet ",
-- ["dotnet-7.0-desktopruntime"] = "dotnet-7.0-desktopruntime",
-- ["dotnet-7.0-sdk-4xx"] = "dotnet-7.0-sdk-2xx",
-- ["dotnet-desktopruntime"] = "dotnet-desktopruntime",
["drawio"] = "drawio",
["fzf"] = "fzf",
["gdu"] = "gdu",
["gh"] = "gh",
["gimp"] = "gimp",
["git"] = "git",
-- ["github-desktop"] = "github-desktop",
["groupy"] = "groupy",
["gzip"] = "gzip",
["ilspy"] = "ilspy",
-- ["jetbrainsmono"] = "jetbrainsmono",
["lazygit"] = "lazygit",
["llvm"] = "clang",
["messenger"] = "messenger",
["mingw"] = "gcc",
-- ["nerd-fonts-DelugiaMono-Powerline"] = "nerd-fonts-DelugiaMono-Powerline",
-- ["nerd-fonts-Hack"] = "nerd-fonts-Hack",
-- ["nerd-fonts-JetBrainsMono"] = "nerd-fonts-JetBrainsMono",
-- ["nerd-fonts-ProggyClean"] = "nerd-fonts-ProggyClean",
-- ["nerd-fonts-SpaceMono"] = "nerd-fonts-SpaceMono",
-- ["nerd-fonts-VictorMono"] = "nerd-fonts-VictorMono",
["nodejs"] = "npm",
["notepadplusplus"] = "notepad++",
["oh-my-posh"] = "oh-my-posh",
["opera-gx"] = "opera-gx",
["paint.net"] = "paint.net",
["powertoys"] = "powertoys",
["pwsh"] = "pwsh",
["python"] = "python",
["rainmeter"] = "rainmeter",
["ripgrep"] = "rg",
["SQLite"] = "SQLite3",
["steam"] = "steam",
-- ["sumatrapdf"] = "sumatra",
["terminal-icons.powershell"] = "terminal-icons.powershell",
["tree-sitter"] = "tree-sitter",
["vcredist140"] = "vcredist140",
["vlc"] = "vlc",
["vscode"] = "code",
["Wget"] = "Wget",
["wiztree"] = "wiztree",
["zig"] = "zig",
}
local installsThatGetCalledFromNeovim = {
"7zip",
"bottom",
"chocolatey",
"curl",
"docker",
"fd",
"fzf",
"gdu",
"gh",
"git",
"gzip",
"lazygit",
"llvm",
"nodejs",
"pwsh",
"python",
"ripgrep",
"SQLite",
"tree-sitter",
"unzip",
"Wget",
"zig",
}
local AllInstalled = true
local notInstalled = {}
for i, pack in ipairs(installsThatGetCalledFromNeovim) do
local p = (packageToExecutableName[pack] or pack)
-- vim.notify("checking for program: " .. p)
local installed = vim.fn.executable(p) == 1
-- local installed = vim.fn.system("choco " .. p) == 1
if installed then
-- vim.notify("program: " .. p .. " is installed and executable. ")
else
-- vim.notify(
-- "program named: {"
-- .. p
-- .. "} is not executable. If it's intalled, then it's possible that it's parent directory is simply not included in the PATH variable. Adding it to the list of things chocolatey will try to install."
-- )
table.insert(notInstalled, pack)
end
end
for i, pack in ipairs(differences) do
-- local p = pack
-- vim.notify("checking for program: " .. p)
-- local installed = vim.fn.executable(p) == 1
-- local installed = vim.fn.system("choco " .. p) == 1
-- if installed then
-- -- vim.notify("program: " .. p .. " is installed and executable. ")
-- else
-- vim.notify(
-- "program named: {"
-- .. p
-- .. "} is not executable. If it's intalled, then it's possible that it's parent directory is simply not included in the PATH variable. Adding it to the list of things chocolatey will try to install."
-- )
table.insert(notInstalled, pack)
-- end
end
if vim.tbl_count(notInstalled) > 0 then
-- vim.notify(
-- "Now going to call choco upgrade (which installs it if it's missing) on the following programs:\n"
-- .. table.concat(notInstalled, "\n")
-- )
-- vim.fn.system("choco upgrade " .. table.concat(installs, " ") .. " -y --whatif" )
-- local chocoCmd = "choco upgrade " .. table.concat(notInstalled, " ") .. " -y --whatif"
local chocoCmd = { "choco", "upgrade" }
vim.list_extend(chocoCmd, notInstalled)
-- vim.notify("going to run " .. chocoCmd)
-- vim.api.nvim
vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("ChocoInstall", { clear = true }),
-- filter = "",
once = true,
callback = function()
-- vim.notify(
-- "Not included in current choco packages :"
-- .. vim.inspect(differences)
-- .. "\nGoing to run : "
-- .. vim.inspect(chocoCmd)
-- )
local util = require("config.util")
-- util.float_term(chocoCmd)
---@type LazyFloatOptions
local fopts = {
border = "double",
noautocmd = true,
-- style = "",
persistent = true,
buf = (function()
local buf = vim.api.nvim_create_buf(true, true)
local currentBlank = vim.api.nvim_get_current_buf()
-- vim.api.nvim_set_current_buf(buf)
-- vim.api.nvim_buf_delete(currentBlank, { force = true })
-- vim.fn.bufload(buf)
-- vim.bo[buf].modifiable = false
return buf
end)(),
-- size = { row = 1, height = 10, width = 80 },
title = "Choco.nvim installer process",
title_pos = "center",
-- file = "C:/temp/chocoNvimLog.log",
}
util.float_term(chocoCmd, fopts)
-- util.float_term({
vim.fn.jobstart({
-- 'write-host "Chocolatey will now re-export the list of currently installed plugins to: \n"'
-- .. currentPackagesExportPath,
"choco",
"export",
currentPackagesExportPath,
})
end,
})
-- vim.fn.system(chocoCmd)
-- vim.fn.system("refreshenv")
else
-- vim.api.nvim_create_autocmd("BufEnter", {
-- group = vim.api.nvim_create_augroup("ChocoInstallAllGood", { clear = true }),
-- -- filter = "",
-- once = true,
-- callback = function()
-- -- vim.defer_fn(
-- vim.notify(
-- "\nAll Choco.nvim's listed programs are installed! Have a sweet day!... see what I did there?.. choco.. sweet.. cuz... it's. yeah nevermind.. I'll show myself out."
-- )
-- -- , 2000)
-- end,
-- })
end
end
function IsElevatedPowershell()
local result = false
result = string.match(
vim.fn.system(
"(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)"
),
"True"
) == "True"
-- result = vim.g["IsRunningElevatedPowershell"]
-- vim.notify("ResultAfterCallback: " .. vim.inspect(result))
if result == true then
-- vim.notify("Running Powershell with elevated permissions.. ")
else
vim.notify("NOT Running Powershell with elevated permissions.. ")
vim.notify("Current shell variable: " .. vim.inspect(vim.o.shell))
-- vim.no
end
return result
end
-- UseChocoToInstallAllTheThings()
-- vim.notify("elevated returned: " .. vim.inspect(isElevated()))
function SetUpExternalExecutables()
local isWindows = vim.fn.has("win32") == 1
-- and vim.fn.executable("explorer") == 1 then
if isWindows then
-- vim.notify("Windows Detected")
local shell = vim.o.shell
local shellcmdflag = vim.o.shellcmdflag
local shellredir = vim.o.shellredir
local shellpipe = vim.o.shellpipe
local shellquote = vim.o.shellquote
local shellxquote = vim.o.shellxquote
local pwshCoreAvailable = vim.fn.executable("pwsh")
local isPowershell = vim.o.shell == "pwsh"
or vim.o.shell == "pwsh.exe"
or vim.o.shell == "powershell"
or vim.o.shell == "powershell.exe"
if not isPowershell then
if pwshCoreAvailable then
vim.o.shell = "pwsh"
else
vim.o.shell = "powershell"
end
vim.o.shellcmdflag =
"-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;"
vim.o.shellredir = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode"
vim.o.shellpipe = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode"
vim.o.shellquote = ""
vim.o.shellxquote = ""
end
isPowershell = vim.o.shell == "pwsh"
or vim.o.shell == "pwsh.exe"
or vim.o.shell == "powershell"
or vim.o.shell == "powershell.exe"
if isPowershell then
-- vim.notify("powershell set as shell .. vim.o.shell: " .. vim.o.shell)
local isElevated = IsElevatedPowershell()
local hasChoco = vim.fn.executable("choco") == 1
if hasChoco == true then
-- vim.notify("chocolatey is installed, you rock.")
else
if isElevated then
local choice = (
vim.fn.inputlist({
"No chocolatey package manager installed, would you like to download it? ",
"1. Absolutely, take me there!",
"2. No I don't like convenient things like package managers, I prefer to suffer.",
})
)
vim.notify(type(choice))
if choice == 1 then
vim.notify(
"You've chosen to download chocolatey, thereby winning at everything forever.. lets do that automatcally shall we? "
)
vim.fn.system(
"Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"
)
local hasChoco2 = vim.fn.executable("choco") == 1
vim.notify(
"At this point choco should be installed! To really do this well, You're going to need to shut down the terminal, and restart this nvim distro. "
)
if hasChoco2 == true then
vim.notify(
"Nvim looked for choco as executable, and it looks great, continuing on to check all the needed installs for the system"
)
else
vim.notify(
"Nvim looked for choco as executable, couldn't find it, it looks like you really will have to restart your terminal before this continues so that environment variables can be reloaded."
)
end
hasChoco = hasChoco2
else
vim.notify(
"well... I guess you don't like nice things... do you perhaps put your shoes on the wrong feet for discomfort too?"
)
end
end
end
if hasChoco == true then
UseChocoToInstallAllTheThings()
end
else
vim.notify(
"not running powershell as main shell, currently set to: "
.. vim.inspect(vim.o.shell)
.. "\nfrankly I'm not able to do this choco install thing without elevated powershell.. so.. fix it."
)
end
vim.o.shell = shell
vim.o.shellcmdflag = shellcmdflag
vim.o.shellredir = shellredir
vim.o.shellpipe = shellpipe
vim.o.shellquote = shellquote
vim.o.shellxquote = shellxquote
end
end
-- bootstrap lazy.nvim, LazyVim and your plugins
if vim.g.vscode then
else
SetUpExternalExecutables()
if vim.g.fvim_loaded then
vim.o.guifont = "Iosevka NF:h17"
-- vim.o.guifont = "JetBrainsMono NF:h14"
vim.keymap.set(
{ "n", "x", "c", "i" },
"<F11>",
":FVimToggleFullScreen <CR>",
{ desc = "toggle fullscreen", silent = true }
)
-- Cursor tweaks
vim.cmd([[ FVimCursorSmoothMove v:true ]])
--Background composition
vim.cmd([[ FVimCursorSmoothBlink v:true ]])
vim.cmd([[ FVimBackgroundComposition 'blur']]) -- 'none', 'transparent', 'blur' or 'acrylic'
vim.cmd([[ FVimBackgroundOpacity 0.25 ]]) -- value between 0 and 1, default bg opacity.
-- vim.cmd([[ FVimBackgroundAltOpacity 0.25 ]]) -- value between 0 and 1, non-default bg opacity.
-- vim.cmd([[ FVimBackgroundImage 'C:/foobar.png' ]]) -- background image
-- vim.cmd([[ FVimBackgroundImageVAlign 'center' ]]) -- vertial position, 'top', 'center' or 'bottom'
-- vim.cmd([[ FVimBackgroundImageHAlign 'center' ]]) -- horizontal position, 'left', 'center' or 'right'
-- vim.cmd([[ FVimBackgroundImageStretch 'fill' ]]) -- 'none', 'fill', 'uniform', 'uniformfill'
-- vim.cmd([[ FVimBackgroundImageOpacity 0.01 ]]) -- value between 0 and 1, bg image opacity
-- Title bar tweaks
vim.cmd([[ FVimCustomTitleBar v:true ]]) -- themed with colorscheme
-- Debug UI overlay
-- vim.cmd([[ FVimDrawFPS v:true ]])
-- Font tweaks
vim.cmd([[ FVimFontAntialias v:true ]])
vim.cmd([[ FVimFontAutohint v:true ]])
vim.cmd([[ FVimFontHintLevel 'full' ]])
vim.cmd([[ FVimFontLigature v:true ]])
-- can be 'default', '14.0', '-1.0' etc.
-- vim.cmd([[ FVimFontLineHeight '+1.0' ]])
vim.cmd([[ FVimFontSubpixel v:true ]])
-- Disable built-in Nerd font symbols
vim.cmd([[ FVimFontNoBuiltinSymbols v:true ]])
-- Try to snap the fonts to the pixels, reduces blur
-- in some situations (e.g. 100% DPI).
vim.cmd([[ FVimFontAutoSnap v:true ]])
-- Font weight tuning, possible valuaes are 100..900
vim.cmd([[ FVimFontNormalWeight 400 ]])
vim.cmd([[ FVimFontBoldWeight 700 ]])
-- Font debugging -- draw bounds around each glyph
-- vim.cmd([[ FVimFontDrawBounds v:true ]])
-- UI options (all default to v:false)
-- external popup menu
vim.cmd([[ FVimUIPopupMenu v:true ]])
-- external wildmenu -- work in progress "
vim.cmd([[ FVimUIWildMenu v:false ]])
-- Keyboard mapping options
-- disable unsupported sequence <S-Space>
vim.cmd([[ FVimKeyDisableShiftSpace v:true ]])
-- Automatic input method engagement in Insert mode
vim.cmd([[ FVimKeyAutoIme v:true ]])
-- Recognize AltGr. Side effect is that <C-A-Key> is then impossible
vim.cmd([[ FVimKeyAltGr v:true ]])
-- Default options (workspace-agnostic)
-- Default window size in a new workspace
-- vim.cmd([[ FVimDefaultWindowWidth 1600]])
-- vim.cmd([[ FVimDefaultWindowHeight 900]])
-- Detach from a remote session without killing the server
-- If this command is executed on a standalone instance,
-- the embedded process will be terminated anyway.
-- vim.cmd([[ FVimDetach ]])
end
if vim.g.neovide then
vim.keymap.set({ "n", "x", "c", "i" }, "<F11>", function()
if vim.g.neovide_fullscreen == true then
vim.g.neovide_fullscreen = false
else
vim.g.neovide_fullscreen = true
end
end)
vim.g.transparency = 0.3
vim.opt.guifont = { "JetBrainsMono NF", "h14" }
vim.g.neovide_transparency = 0.5
-- vim.g.neovide_background_color = "#0f1117" .. alpha()
vim.g.neovide_floating_blur_amount_x = 22.0
vim.g.neovide_floating_blur_amount_y = 20.0
vim.g.neovide_scroll_animation_length = 0.3
vim.g.neovide_theme = "auto"
vim.g.neovide_refresh_rate = 75.0
vim.g.neovide_refresh_rate_idle = 5.0
vim.g.neovide_remember_window_size = true
--
vim.g.neovide_cursor_animation_length = 0.13
--
vim.g.neovide_cursor_antialiasing = true
vim.g.neovide_cursor_animate_command_line = true
--- vim redraw
vim.cmd.redraw()
end
end
require("config.lazy")