startify.vim 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 {{{1
  10. function! startify#get_session_names(lead, ...) abort
  11. return map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")')
  12. endfunction
  13. " Function: startify#get_session_names_as_string {{{1
  14. function! startify#get_session_names_as_string(lead, ...) abort
  15. return join(map(split(globpath(g:startify_session_dir, '*'.a:lead.'*', '\n')), 'fnamemodify(v:val, ":t")'), "\n")
  16. endfunction
  17. " Function: startify#escape {{{1
  18. function! startify#escape(path) abort
  19. return !exists('+shellslash') || &shellslash ? fnameescape(a:path) : escape(a:path, '\')
  20. endfunction
  21. " Function: startify#get_separator {{{1
  22. function! startify#get_separator() abort
  23. return !exists('+shellslash') || &shellslash ? '/' : '\'
  24. endfunction
  25. " Function: startify#is_in_skiplist {{{1
  26. function! startify#is_in_skiplist(arg) abort
  27. for regexp in g:startify_skiplist
  28. if (a:arg =~# regexp)
  29. return 1
  30. endif
  31. endfor
  32. endfunction
  33. " Function: startify#delete_session {{{1
  34. function! startify#delete_session(...) abort
  35. if !isdirectory(g:startify_session_dir)
  36. echo 'The session directory does not exist: '. g:startify_session_dir
  37. return
  38. elseif empty(startify#get_session_names_as_string(''))
  39. echo 'There are no sessions...'
  40. return
  41. endif
  42. let spath = g:startify_session_dir . startify#get_separator() . (exists('a:1')
  43. \ ? a:1
  44. \ : input('Delete this session: ', '', 'custom,startify#get_session_names_as_string'))
  45. \ | redraw
  46. echo 'Really delete '. spath .'? [y/n]' | redraw
  47. if (nr2char(getchar()) == 'y')
  48. if delete(spath) == 0
  49. echo 'Deleted session '. spath .'!'
  50. else
  51. echo 'Deletion failed!'
  52. endif
  53. else
  54. echo 'Deletion aborted!'
  55. endif
  56. endfunction
  57. " Function: startify#save_session {{{1
  58. function! startify#save_session(...) abort
  59. if !isdirectory(g:startify_session_dir)
  60. if exists('*mkdir')
  61. echo 'The session directory does not exist: '. g:startify_session_dir .'. Create it? [y/n]' | redraw
  62. if (nr2char(getchar()) == 'y')
  63. call mkdir(g:startify_session_dir, 'p')
  64. else
  65. echo
  66. return
  67. endif
  68. else
  69. echo 'The session directory does not exist: '. g:startify_session_dir
  70. return
  71. endif
  72. endif
  73. let spath = g:startify_session_dir . startify#get_separator() . (exists('a:1')
  74. \ ? a:1
  75. \ : input('Save under this session name: ', '', 'custom,startify#get_session_names_as_string'))
  76. \ | redraw
  77. if !filereadable(spath)
  78. execute 'mksession '. spath | echo 'Session saved under: '. spath
  79. return
  80. endif
  81. echo 'Session already exists. Overwrite? [y/n]' | redraw
  82. if nr2char(getchar()) == 'y'
  83. execute 'mksession! '. spath | echo 'Session saved under: '. spath
  84. else
  85. echo 'Did NOT save the session!'
  86. endif
  87. endfunction
  88. " Function: startify#load_session {{{1
  89. function! startify#load_session(...) abort
  90. if !isdirectory(g:startify_session_dir)
  91. echo 'The session directory does not exist: '. g:startify_session_dir
  92. return
  93. elseif empty(startify#get_session_names_as_string(''))
  94. echo 'There are no sessions...'
  95. return
  96. endif
  97. let spath = g:startify_session_dir . startify#get_separator() . (exists('a:1')
  98. \ ? a:1
  99. \ : input('Load this session: ', '', 'custom,startify#get_session_names_as_string'))
  100. \ | redraw
  101. if filereadable(spath)
  102. execute 'source '. spath
  103. else
  104. echo 'No such file: '. spath
  105. endif
  106. endfunction
  107. " vim: et sw=2 sts=2