startify.vim 3.3 KB

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