-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtoggle-nvim-theme.lua
More file actions
58 lines (49 loc) · 1.6 KB
/
toggle-nvim-theme.lua
File metadata and controls
58 lines (49 loc) · 1.6 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
-- Define the path to the file
local configPath = os.getenv("NVIM_CONFIG_PATH")
local filePath = configPath .. "/lua/theme.lua"
-- Function to read the file content
local function readFile(filePath)
local file = io.open(filePath, "r")
if not file then
print("Could not open file " .. filePath)
os.exit(1)
end
local content = file:read("*all")
file:close()
return content
end
-- Function to write the file content
local function writeFile(filePath, content)
local file = io.open(filePath, "w")
if not file then
print("Could not open file " .. filePath)
os.exit(1)
end
file:write(content)
file:close()
end
-- Read the file content
local content = readFile(filePath)
-- Define the patterns to search for
local themesPattern = "-- THEMES:%s*([%w%-]+),%s*([%w%-]+)"
local flavourPattern = "flavour%s*=%s*'([%w%-]+)'"
-- Extract themes and current flavour
local theme1, theme2 = content:match(themesPattern)
local themes = { theme1, theme2 }
local currentFlavour = content:match(flavourPattern)
-- Determine the new flavour
local newFlavour
if #themes > 1 and currentFlavour then
for i, theme in ipairs(themes) do
if theme == currentFlavour then
newFlavour = themes[(i % #themes) + 1]
break
end
end
-- Update the file content with the new flavour
content = content:gsub(flavourPattern, "flavour = '" .. newFlavour .. "'")
end
-- Write the modified content back to the file
writeFile(filePath, content)
-- Output a message indicating success
print("File updated successfully to flavour: " .. newFlavour)