forked from PegasusWang/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesystem.vim
43 lines (38 loc) · 1.1 KB
/
filesystem.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
" Helpers for dealing with the filesystem
" ---
"
" Behaviors:
" - Before writing file ensure directories exist
"
" Commands:
" - GitOpenDirty: Open all dirty files in repository
if exists('g:loaded_filesystemplugin')
finish
endif
let g:loaded_filesystemplugin = 1
augroup plugin_filesystem
autocmd!
autocmd BufWritePre * call s:mkdir(expand('<afile>:p:h'), v:cmdbang)
augroup END
function! s:mkdir(dir, force)
" Credits: https://github.com/Shougo/shougo-s-github
if ! isdirectory(a:dir) && empty(&l:buftype) &&
\ (a:force || input(printf('"%s" does not exist. Create? [y/N]',
\ a:dir)) =~? '^y\%[es]$')
call mkdir(a:dir, 'p')
endif
endfunction
command! -nargs=0 GitOpenDirty call s:git_open_dirty()
" Open a split for each dirty file in git
function! s:git_open_dirty()
silent only " Close all windows, unless they're modified
let status =
\ system('git status -s | grep "^ \?\(M\|A\|UU\)" | sed "s/^.\{3\}//"')
let filenames = split(status, "\n")
if ! empty(filenames)
exec 'edit ' . filenames[0]
for filename in filenames[1:]
exec 'sp ' . filename
endfor
endif
endfunction