mhinz / vim-startify

:link: The fancy start screen for Vim.
MIT License
5.31k stars 187 forks source link

How to list files in CWD #428

Closed vladdoster closed 4 years ago

vladdoster commented 4 years ago

It is listing the right dir, but the files in the list are the recent files... How can I get it to list the files in cwd? I have tried defining functions but to no avail. pic-selected-200617-2127-47

autocmd User Startified setlocal cursorline

let g:startify_custom_header = 'startify#pad(startify#fortune#boxed())'

let g:startify_enable_special      = 0
let g:startify_files_number        = 10
let g:startify_relative_path       = 1
let g:startify_change_to_dir       = 1
let g:startify_update_oldfiles     = 1
let g:startify_session_autoload    = 1
let g:startify_session_persistence = 1
let g:startify_session_dir = '~/.config/nvim/session'
let g:startify_session_delete_buffers = 1

hi! link StartifyHeader Normal
hi! link StartifyFile Directory
hi! link StartifyPath LineNr
hi! link StartifySlash StartifyPath
hi! link StartifyBracket StartifyPath
hi! link StartifyNumber Title

function! s:lsGithubDir()
let files = systemlist('ls -d ~/github/* 2>/dev/null')
    return map(files, "{'line': v:val, 'path': v:val}")
endfunction

function! s:lsCwd()
    let files = systemlist('function(getcwd())')
    return map(files, "{'line': v:val, 'path': v:val}")
endfunction

let g:startify_lists = [
          \ { 'type': 'files',                    'header': ['   Recent files']},
          \ { 'type': 'files',                    'header': ['   Current Directory: '.getcwd()]},
          \ { 'type': function('s:lsGithubDir'),  'header': ['   Github projects']},
          \ { 'type': 'sessions',                 'header': ['   Sessions']},
          \ { 'type': 'bookmarks',                'header': ['   Bookmarks']},
          \ ]

let g:startify_bookmarks = [
            \ { 'D': '~/documents/' },
            \ { 'c': '~/.config' },
            \ { 'd': '~/downloads/' },
            \ { 'i': '~/.config/nvim/init.vim' },
            \ { 's': '~/.local/src/' },
            \ { 'w': '~/.local/src/vimwiki.git/index.wiki' },
            \ { 'z': '~/.config/zsh/zshrc' },
            \ ]
vladdoster commented 4 years ago

Woah, information overload ya'll! Too many people commenting on this

mhinz commented 4 years ago

Hi,

I wasn't very active on GitHub the last months, but go through all the issues now.

   \ { 'type': 'files', 'header': ['   Recent files']},
   \ { 'type': 'files', 'header': ['   Current Directory: '.getcwd()]},

You use the internal files function to for both lists, so no wonder why you'd get the same output. The type for the second line should be 'dir' instead of 'files'.

If you wanted to use a custom function instead, your s:lsCwd() needs to be fixed, since systemlist() takes a shell command, not a Vim function. For simplicity I'll just use ls -1, but that might break in some cases.

function! s:lsCwd()
    let files = systemlist('ls -1')
    return map(files, "{'line': v:val, 'path': v:val}")
endfunction

let g:startify_lists = [
          \ { 'type': 'files',                    'header': ['   Recent files']},
          \ { 'type': function('s:lsCwd'),        'header': ['   Current Directory: '.getcwd()]},
          \ { 'type': 'sessions',                 'header': ['   Sessions']},
          \ { 'type': 'bookmarks',                'header': ['   Bookmarks']},
          \ ]