Skip to content

Instantly share code, notes, and snippets.

@MRDGH2821
Created December 27, 2021 13:38
Show Gist options
  • Save MRDGH2821/a05aa96724484e3bce55c3c66855b933 to your computer and use it in GitHub Desktop.
Save MRDGH2821/a05aa96724484e3bce55c3c66855b933 to your computer and use it in GitHub Desktop.
A random oh-my-posh theme loader for Command Prompt
math.randomseed(os.time())
math.random()
math.random()
math.random()
function math.randomchoice(t) --Selects a random item from a table
local keys = {}
for key, value in pairs(t) do
keys[#keys + 1] = key --Store keys in another table
end
index = keys[math.random(1, #keys)]
return t[index]
end
-- Lua implementation of PHP scandir function
local i, themes, popen = 0, {}, io.popen
local pfile = popen('dir "%userprofile%\\AppData\\Local\\Programs\\oh-my-posh\\themes\\" /b')
for filename in pfile:lines() do
i = i + 1
themes[i] = filename
end
pfile:close()
local theme = math.randomchoice(themes)
local query =
string.format(
"oh-my-posh --config=%%userprofile%%\\AppData\\Local\\Programs\\oh-my-posh\\themes\\%s --init --shell cmd",
theme
)
print(theme) --This line can be removed if you don't want to know which theme is loaded.
load(io.popen(query):read("*a"))()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment