startify.vim 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_separator() 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#delete_session(...) abort
  29. if !isdirectory(g:startify_session_dir)
  30. echo 'The session directory does not exist: '. g:startify_session_dir
  31. return
  32. endif
  33. let spath = g:startify_session_dir . startify#get_separator() . (exists('a:1')
  34. \ ? a:1
  35. \ : input('Delete this session: ', '', 'custom,startify#get_session_names_as_string'))
  36. \ | redraw
  37. echo 'Really delete '. spath .'? [y/n]' | redraw
  38. if (nr2char(getchar()) == 'y')
  39. if delete(spath) == 0
  40. echo 'Deleted session '. spath .'!'
  41. else
  42. echo 'Deletion failed!'
  43. endif
  44. else
  45. echo 'Deletion aborted!'
  46. endif
  47. endfunction
  48. function! startify#save_session(...) abort
  49. if !isdirectory(g:startify_session_dir)
  50. if exists('*mkdir')
  51. echo 'The session directory does not exist: '. g:startify_session_dir .'. Create it? [y/n]' | redraw
  52. if (nr2char(getchar()) == 'y')
  53. call mkdir(g:startify_session_dir, 'p')
  54. else
  55. echo
  56. return
  57. endif
  58. else
  59. echo 'The session directory does not exist: '. g:startify_session_dir
  60. return
  61. endif
  62. endif
  63. let spath = g:startify_session_dir . startify#get_separator() . (exists('a:1')
  64. \ ? a:1
  65. \ : input('Save under this session name: ', '', 'custom,startify#get_session_names_as_string'))
  66. \ | redraw
  67. if !filereadable(spath)
  68. execute 'mksession '. spath | echo 'Session saved under: '. spath
  69. return
  70. endif
  71. echo 'Session already exists. Overwrite? [y/n]' | redraw
  72. if nr2char(getchar()) == 'y'
  73. execute 'mksession! '. spath | echo 'Session saved under: '. spath
  74. else
  75. echo 'Did NOT save the session!'
  76. endif
  77. endfunction
  78. function! startify#load_session(...) abort
  79. if !isdirectory(g:startify_session_dir)
  80. echo 'The session directory does not exist: '. g:startify_session_dir
  81. return
  82. endif
  83. let spath = g:startify_session_dir . startify#get_separator() . (exists('a:1')
  84. \ ? a:1
  85. \ : input('Load this session: ', '', 'custom,startify#get_session_names_as_string'))
  86. \ | redraw
  87. if filereadable(spath)
  88. execute 'source '. spath
  89. else
  90. echo 'No such file: '. spath
  91. endif
  92. endfunction
  93. " vim: et sw=2 sts=2