Skip to content

Instantly share code, notes, and snippets.

@kylo252
Last active May 25, 2022 07:21
Show Gist options
  • Save kylo252/c541f19752900afd83c3c32f0908b108 to your computer and use it in GitHub Desktop.
Save kylo252/c541f19752900afd83c3c32f0908b108 to your computer and use it in GitHub Desktop.
generate missing filetypes for neovim
local fmt = string.format
local function write_file(path, txt, flag)
local data = type(txt) == "string" and txt or vim.inspect(txt)
local uv = vim.loop
uv.fs_open(path, flag, 438, function(open_err, fd)
assert(not open_err, open_err)
uv.fs_write(fd, data, -1, function(write_err)
assert(not write_err, write_err)
uv.fs_close(fd, function(close_err)
assert(not close_err, close_err)
end)
end)
end)
end
local function read_file(path)
local uv = vim.loop
local fd = assert(uv.fs_open(path, "r", 438))
local fstat = assert(uv.fs_fstat(fd))
local contents = assert(uv.fs_read(fd, fstat.size, 0))
assert(uv.fs_close(fd))
return contents
end
local filetype_lua_url = "https://raw.githubusercontent.com/neovim/neovim/9e1ee9fb1d747facb6fa97a32dc5e22c7dfcb346/runtime/lua/vim/filetype.lua"
local languages_yaml_url = "https://raw.githubusercontent.com/github/linguist/master/lib/linguist/languages.yml"
local language_stats_url = "https://raw.githubusercontent.com/oprogramador/github-languages/master/1000-pushed-after-2020-06-07.json"
local awk_script = [['NR==33, NR==1010; NR==1011 {print; exit}']]
vim.fn.system(fmt("curl -LSs '%s' | yq > %s", languages_yaml_url, "languages.json"))
vim.fn.system(fmt("curl -LSs '%s' | awk '{print tolower($0)}' > %s", language_stats_url, "stats.json"))
vim.fn.system(fmt("curl -LSs '%s' | awk %s | xargs -0 echo 'return {' > %s", filetype_lua_url, awk_script, "lua/scratch/defaults.lua"))
local lang_maps = vim.json.decode(read_file("languages.json"))
local stats = vim.json.decode(read_file("stats.json"))
local collection = {}
for lang, v in pairs(lang_maps) do
if v.extensions and type(v.extensions) == "table" then
for _, entry in ipairs(v.extensions) do
collection[string.gsub(entry, "%.", "")] = lang:lower()
end
end
end
table.sort(collection)
write_file("lua/scratch/imported.lua", "return " .. vim.inspect(collection), "w")
write_file("lua/scratch/stats.lua", "return " .. vim.inspect(stats), "w")
local function is_top_language(name)
-- check that the language exists and has more than 5 stars
return stats[name] and stats[name] > 5
end
local defaults = require("scratch.defaults")
local missing = {}
for ext, lang in pairs(collection) do
if is_top_language(lang) and not defaults[ext] then
missing[ext] = lang
end
end
table.sort(missing)
write_file("lua/scratch/missing.lua", "return " .. vim.inspect(missing), "w")
return {
_coffee = "coffeescript",
_js = "javascript",
a51 = "assembly",
appsrc = "erlang",
aux = "tex",
aw = "php",
bats = "shell",
bbx = "tex",
bones = "javascript",
boot = "clojure",
cake = "c#",
cats = "c",
cbx = "tex",
cgi = "perl",
cjsx = "coffeescript",
cl2 = "clojure",
cljscm = "clojure",
cljshl = "clojure",
cmakein = "cmake",
cmd = "batchfile",
coffee = "coffeescript",
command = "shell",
cp = "c++",
cr = "crystal",
dfm = "pascal",
di = "d",
dockerfile = "dockerfile",
eliom = "ocaml",
eliomi = "ocaml",
emacs = "emacs lisp",
emacsdesktop = "emacs lisp",
es6 = "javascript",
escript = "erlang",
eye = "ruby",
fcgi = "lua",
fp = "glsl",
frag = "javascript",
frg = "glsl",
fsh = "glsl",
fshader = "glsl",
geo = "glsl",
geom = "glsl",
glslf = "glsl",
glslv = "glsl",
god = "ruby",
grt = "groovy",
gshader = "glsl",
gtpl = "groovy",
gvy = "groovy",
gyp = "python",
gypi = "python",
["h++"] = "c++",
handlebars = "handlebars",
hic = "clojure",
hta = "html",
htmlhl = "html",
hx = "haxe",
hxsl = "haxe",
iced = "coffeescript",
idc = "c",
ins = "tex",
ixx = "c++",
jade = "pug",
jake = "javascript",
jbuilder = "ruby",
jsb = "javascript",
jscad = "javascript",
jsfl = "javascript",
jslib = "javascript",
jsm = "javascript",
jsonnet = "jsonnet",
jspre = "javascript",
jss = "javascript",
kojo = "scala",
lbx = "tex",
libsonnet = "jsonnet",
linq = "c#",
lmi = "python",
make = "makefile",
makefile = "makefile",
matlab = "matlab",
mdx = "markdown",
me = "roff",
mkdown = "markdown",
mkfile = "makefile",
ml4 = "ocaml",
mspec = "ruby",
nasm = "assembly",
njs = "javascript",
nomad = "hcl",
ny = "common lisp",
p8 = "lua",
pascal = "pascal",
pd_lua = "lua",
perl = "perl",
pgsql = "plpgsql",
ph = "perl",
php3 = "php",
php4 = "php",
php5 = "php",
phps = "php",
pm = "perl",
podsl = "common lisp",
podspec = "ruby",
prawn = "ruby",
py3 = "python",
pyde = "python",
pyp = "python",
pyt = "python",
rabl = "ruby",
rbi = "ruby",
rbuild = "ruby",
rbx = "ruby",
rbxs = "lua",
rchit = "glsl",
re = "c++",
rmiss = "glsl",
ronn = "markdown",
rpy = "python",
rsin = "rust",
rsx = "r",
ruby = "ruby",
shader = "glsl",
shin = "shell",
sjs = "javascript",
sls = "scheme",
smk = "python",
sps = "scheme",
ssjs = "javascript",
t = "perl",
tac = "python",
tesc = "glsl",
tese = "glsl",
thor = "ruby",
tmux = "shell",
tool = "shell",
vapi = "vala",
vert = "glsl",
vimrc = "vim script",
vmb = "vim script",
vrx = "glsl",
vsh = "glsl",
vshader = "glsl",
watchr = "ruby",
wlua = "lua",
workbook = "markdown",
workflow = "hcl",
wsgi = "python",
xpy = "python",
xrl = "erlang",
xsjs = "javascript",
xsjslib = "javascript",
yrl = "erlang",
["zsh-theme"] = "shell"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment