repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim/lua/bugabinga/cmdline/format.lua

Raw
local icon = require 'std.icon'

local HELP_PATTERNS = { '^h$', '^he$', '^hel$', '^help$', '^h%s', '^help%s' }

return {
  detect = function(firstc, content, prompt)
    if prompt and prompt ~= '' then
      return { type = 'input', icon = icon.prompt_prefix, lang = nil }
    end
    if firstc == '/' then
      return { type = 'search_down', icon = icon.search, lang = 'regex' }
    end
    if firstc == '?' then
      return { type = 'search_up', icon = icon.search_up, lang = 'regex' }
    end
    if firstc == '!' or (firstc == ':' and content and content:match '^!') then
      return { type = 'shell', icon = icon.shell, lang = 'bash' }
    end
    if firstc == ':' and content then
      for _, pat in ipairs(HELP_PATTERNS) do
        if content:match(pat) then
          return { type = 'help', icon = icon.help, lang = nil }
        end
      end
      if content:match '^lua%s*' or content:match '^=' then
        return { type = 'lua', icon = icon.vim, lang = 'lua' }
      end
      return { type = 'cmdline', icon = icon.command, lang = 'vim' }
    end
    return { type = 'cmdline', icon = icon.command, lang = 'vim' }
  end,
}