startify.vim 3.4 KB

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