startify.vim 4.1 KB

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