-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
133 lines (115 loc) · 4.56 KB
/
init.lua
File metadata and controls
133 lines (115 loc) · 4.56 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
-- Create global table that can be accessed from any file
-- This will solve all cross platform path issues
OS = {}
---The file system path separator for the current platform.
OS.separator = '/'
if OS.OS == 'Windows' then
OS.separator = '\\'
end
---Split string into a table of strings using a separator.
---Found here https://www.reddit.com/r/neovim/comments/su0em7/comment/hx96ur0/?utm_source=share&utm_medium=web3x
---@param inputString string The string to split.
---@param sep string The separator to use.
---@return table table A table of strings.
OS.split = function(inputString, sep)
local fields = {}
local pattern = string.format('([^%s]+)', sep)
local _ = string.gsub(inputString, pattern, function(c)
fields[#fields + 1] = c
end)
return fields
end
---Joins arbitrary number of paths together.
---Found here https://www.reddit.com/r/neovim/comments/su0em7/comment/hx96ur0/?utm_source=share&utm_medium=web3x
---@vararg <string> The paths to join.
---@return string
OS.join_path = function(...)
local args = { ... }
if #args == 0 then
return ''
end
local all_parts = {}
if type(args[1]) == 'string' and args[1]:sub(1, 1) == OS.separator then
all_parts[1] = ''
end
for _, arg in ipairs(args) do
arg_parts = OS.split(arg, OS.separator)
vim.list_extend(all_parts, arg_parts)
end
return vim.fs.normalize(table.concat(all_parts, OS.separator))
end
if vim.loop.os_uname().sysname == 'Linux' then
OS['OS'] = 'Linux'
OS['home'] = vim.fs.normalize(os.getenv('HOME'))
OS['plover'] = OS.join_path(OS['home'], '.config', 'plover ')
OS['executable_extension'] = ''
OS['executable_extension_alt'] = ''
elseif vim.loop.os_uname().sysname == 'Windows_NT' then
OS['OS'] = 'Windows'
OS['home'] = vim.fs.normalize(os.getenv('USERPROFILE'))
OS['plover'] = OS.join_path(os.getenv('LOCALAPPDATA'), 'plover')
OS['executable_extension'] = '.exe'
OS['executable_extension_alt'] = '.cmd'
end
OS['init_lua'] = vim.fs.normalize(vim.env.MYVIMRC)
OS['nvim'] = vim.fs.normalize(vim.fn.stdpath('config'))
OS['my_plugins'] = OS.join_path(OS['home'], 'neovim_plugins')
OS['snippets'] = OS.join_path(OS.nvim, 'lua', 'luasnippets')
OS['stimpack'] = OS.join_path(OS.nvim, 'lua', 'stimpack')
OS['vimwiki'] = OS.join_path(OS['home'], '.mywiki')
OS['CrossPlatformDotfiles'] = OS.join_path(OS['home'], 'Scripts')
OS['wezterm'] = OS.join_path(OS['home'], '.config', 'wezterm ')
---Function to return telescope.utils command runner
---@param command string the single string input command
---@return table the table has the fields stdout,ret,and stderr
function Execute(command)
-- Format the input string to a table splitting on any space chars
local formatted_command, output = {}, {}
for match in string.gmatch(command, '[^%s]+') do
table.insert(formatted_command, match)
end
-- output.stdout, output.ret, output.stderr = require('telescope.utils').get_os_command_output(formatted_command)
local ok, output_or_err = pcall(function()
local utils = require('telescope.utils')
local stdout, ret, stderr = utils.get_os_command_output(formatted_command)
return { stdout = stdout, ret = ret, stderr = stderr }
end)
if ok then
output.stdout = output_or_err.stdout
output.ret = output_or_err.ret
output.stderr = output_or_err.stderr
else
print('Error executing command:', output_or_err)
end
return output
end
---This function extracts the package name of the current lua file. The files
---need to be named with names like telescope-settings.lua. The search returns
---all text before the '-settings'.
---@param nameOfCurrentFileToExtractPackageNamFrom any
---@return string|number
function GetPackageNameFromCurrentFile(nameOfCurrentFileToExtractPackageNamFrom)
return string.match(nameOfCurrentFileToExtractPackageNamFrom, '(%w+)-settings.lua')
end
-- Helpful function to print tables nicely instead of the address
function P(table_to_print)
print(vim.inspect(table_to_print))
end
-- Helpful function to print tables nicely to the vim.notify function
function V(...)
for key, value in ipairs({ ... }) do
vim.notify(vim.inspect(value), vim.log.levels.INFO, { title = 'Stimpack notification (' .. key .. ')' })
end
end
-- Help from here https://stackoverflow.com/a/4991602/9842112
function FileExists(filename)
local f = io.open(filename, 'r')
if f ~= nil then
io.close(f)
return true
else
return false
end
end
-- bootstrap lazy.nvim, LazyVim and your plugins
require('config.lazy')