startify.vim 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. " Plugin: https://github.com/mhinz/vim-startify
  2. " Description: Start screen displaying recently used stuff.
  3. " Maintainer: Marco Hinz <http://github.com/mhinz>
  4. " Version: 1.4
  5. if exists('g:autoloaded_startify') || &cp
  6. finish
  7. endif
  8. let g:autoloaded_startify = 1
  9. function! startify#get_session_names(lead, ...) abort
  10. return map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")')
  11. endfunction
  12. function! startify#get_session_names_as_string(lead, ...) abort
  13. return join(map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")'), "\n")
  14. endfunction
  15. function! startify#escape(path) abort
  16. return !exists('+shellslash') || &shellslash ? fnameescape(a:path) : escape(a:path, '\')
  17. endfunction
  18. function! startify#get_sep() abort
  19. return !exists('+shellslash') || &shellslash ? '/' : '\'
  20. endfunction
  21. function! startify#is_in_skiplist(arg) abort
  22. for regexp in g:startify_skiplist
  23. if (a:arg =~# regexp)
  24. return 1
  25. endif
  26. endfor
  27. endfunction
  28. function! startify#save_session(...) abort
  29. if !isdirectory(g:startify_session_dir)
  30. if exists('*mkdir')
  31. echo 'The session directory does not exist: '. g:startify_session_dir .'. Create it? [y/n]' | redraw
  32. if (nr2char(getchar()) == 'y')
  33. call mkdir(g:startify_session_dir, 'p')
  34. else
  35. echo
  36. return
  37. endif
  38. else
  39. echo 'The session directory does not exist: '. g:startify_session_dir
  40. return
  41. endif
  42. endif
  43. let spath = g:startify_session_dir . startify#get_sep() . (exists('a:1')
  44. \ ? a:1
  45. \ : input('Save under this session name: ', '', 'custom,startify#get_session_names_as_string'))
  46. \ | redraw
  47. if !filereadable(spath)
  48. execute 'mksession '. spath | echo 'Session saved under: '. spath
  49. return
  50. endif
  51. echo 'Session already exists. Overwrite? [y/n]' | redraw
  52. if nr2char(getchar()) == 'y'
  53. execute 'mksession! '. spath | echo 'Session saved under: '. spath
  54. else
  55. echo 'Did NOT save the session!'
  56. endif
  57. endfunction
  58. function! startify#load_session(...) abort
  59. if !isdirectory(g:startify_session_dir)
  60. echo 'The session directory does not exist: '. g:startify_session_dir
  61. return
  62. endif
  63. let spath = g:startify_session_dir . startify#get_sep() . (exists('a:1')
  64. \ ? a:1
  65. \ : input('Load this session: ', '', 'custom,startify#get_session_names_as_string'))
  66. \ | redraw
  67. if filereadable(spath)
  68. execute 'source '. spath
  69. else
  70. echo 'No such file: '. spath
  71. endif
  72. endfunction
  73. " vim: et sw=2 sts=2