mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-23 18:39:33 +08:00
42 lines
909 B
VimL
42 lines
909 B
VimL
"=============================================================================
|
|
" mkdir.vim --- auto mkdir when saving file
|
|
" Copyright (c) 2016-2017 Wang Shidong & Contributors
|
|
" Author: Wang Shidong < wsdjeg at 163.com >
|
|
" URL: https://spacevim.org
|
|
" License: GPLv3
|
|
"=============================================================================
|
|
|
|
let s:save_cpo = &cpo
|
|
set cpo&vim
|
|
|
|
function! SpaceVim#plugins#mkdir#CreateCurrent() abort
|
|
|
|
call s:CreateDirectory(expand('%:p:h'))
|
|
|
|
endfunction
|
|
|
|
fun! s:Mkdirp(dir) abort
|
|
if exists('*mkdir')
|
|
call mkdir(a:dir, 'p')
|
|
else
|
|
" @todo mkdir only exist in *nix os
|
|
call system('mkdir -p '.shellescape(a:dir))
|
|
end
|
|
endf
|
|
|
|
fun! s:CreateDirectory(dir) abort
|
|
let d = a:dir
|
|
|
|
" @todo do not skip files that have schemes
|
|
if d =~? '^[a-z]\+:/'
|
|
return
|
|
endif
|
|
|
|
if !isdirectory(d)
|
|
call s:Mkdirp(d)
|
|
end
|
|
endf
|
|
|
|
let &cpo = s:save_cpo
|
|
unlet s:save_cpo
|