1

I'm trying to migrate my vimrc configuration to lua, and I'm stuck on migrating my vim-startify configuration. In particular, how can I write the gitModified and gitUntracked lists?

vimscript:

function! s:gitModified()
    let files = systemlist('git ls-files -m 2>/dev/null')
    return map(files, "{'line': v:val, 'path': v:val}")
endfunction

function! s:gitUntracked()
    let files = systemlist('git ls-files -o --exclude-standard 2>/dev/null')
    return map(files, "{'line': v:val, 'path': v:val}")
endfunction

let g:startify_lists = [
        \ { 'type': 'dir',       'header': ['   MRU '. getcwd()] },
        \ { 'type': 'sessions',  'header': ['   Sessions']       },
        \ { 'type': 'bookmarks', 'header': ['   Bookmarks']      },
        \ { 'type': function('s:gitModified'),  'header': ['   git modified']},
        \ { 'type': function('s:gitUntracked'), 'header': ['   git untracked']},
        \ { 'type': 'commands',  'header': ['   Commands']       },
        \ ]

My current lua:

vim.g.startify_lists = {
  { type = "commands", header = { "    Commands" } }, -- Commands from above
  { type = "dir", header = { "    MRU " .. vim.fn.getcwd() } }, -- MRU files from CWD
  { type = "sessions",  header = {"   Sessions"} },
  { type = "bookmarks", header = {"   Bookmarks"} },
}

Here I'm missing the two Git related items.

1 Answer 1

2

Here's what I did:

function CommandToStartifyTable(command)
    return function()
        local cmd_output = vim.fn.systemlist(command .. " 2>/dev/null")
        local files =
            vim.tbl_map(
            function(v)
                return {line = v, path = v}
            end,
            cmd_output
        )
        return files
    end
end

vim.g.startify_lists = {
    {type = "dir", header = {"   MRU " .. vim.fn.fnamemodify(vim.fn.getcwd(), ":t")}},
    {type = CommandToStartifyTable("git ls-files -m"), header = {"   Git modified"}},
    {type = CommandToStartifyTable("git ls-files -o --exclude-standard"), header = {"   Git untracked"}}
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.