diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-30 20:49:45 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-06-30 20:49:45 +1200 |
commit | 738d24cf91849cae54e81d5f1b461d8c27e61bb8 (patch) | |
tree | eff34069ccf8351d257df1546e4f08ac60723ee4 | |
parent | Revert "Remove accidentally committed backup" (diff) | |
download | vim-auto-cache-dirs-738d24cf91849cae54e81d5f1b461d8c27e61bb8.tar.gz vim-auto-cache-dirs-738d24cf91849cae54e81d5f1b461d8c27e61bb8.zip |
Remove actual .bak file
-rw-r--r-- | plugin/auto_cache_dirs.vim.bak | 134 |
1 files changed, 0 insertions, 134 deletions
diff --git a/plugin/auto_cache_dirs.vim.bak b/plugin/auto_cache_dirs.vim.bak deleted file mode 100644 index b94b511..0000000 --- a/plugin/auto_cache_dirs.vim.bak +++ /dev/null @@ -1,134 +0,0 @@ -" -" auto_cache_dirs.vim: Configure 'backupdir', 'directory', and 'undodir' -" automatically, including trying hard to create them, and leaving the options -" untouched if we can't. -" -" Author: Tom Ryder <tom@sanctum.geek.nz> -" License: Same as Vim itself -" -if exists('g:loaded_auto_cache_dirs') || &compatible - finish -endif -if v:version < 600 - finish -endif -let g:loaded_auto_cache_dirs = 1 - -" Try hard to create a directory with the given expanded name -function! s:EstablishDir(dir) - - " If it's already a directory, we have nothing to do - if isdirectory(a:dir) - return 1 - endif - - " Try Vim's native mkdir() first - if exists('*mkdir') - silent! call mkdir(a:dir, 'p', 0700) - - " Failing that, try to use an OS-dependent command - " (Fortunately, Unix and Windows are the only OS types in the world) - else - if has('unix') - let l:mkdir = '!mkdir -m 0700 -p' - elseif has('win32') || has('win64') - let l:mkdir = '!mkdir' - endif - silent! execute l:mkdir . ' ' . s:ShellEscape(a:dir) - endif - - " Return whether the directory exists now - return isdirectory(a:dir) - -endfunction - -" Wrapper around shellescape(), with fallback backport if not available -function! s:ShellEscape(string) - - " Use native function if we can - if has('*shellescape') - return shellescape(a:string) - - " If not, manually write out what the :help for shellescape() says it does - else - if (has('win32') || has('win64')) && !&shellslash - return '"' . substitute(a:string, '"', '""', 'g') . '"' - else - return "'" . substitute(a:string, "'", "'\\\\''", 'g') . "'" - endif - endif - -endfunction - -" If we can find or create a directory for it, set an option and its related -" path option -function! s:SetDir(option_bool, option_path, subdir, name_path) - - " Build full path - let l:dir = s:root . '/' . a:subdir - - " Verify or create the dir - let l:exp = expand(l:dir) - if !s:EstablishDir(expand(l:exp)) - echoerr 'Could not create ' . l:exp - return - endif - - " Set bool option (e.g. 'backup') - execute 'set ' . a:option_bool - - " Determine element to add to accompanying path option; escape spaces and - " backslashes, and append double-slash if requested - let l:item = substitute(l:dir, '[ ,\\]', '\\&', 'g') - if a:name_path - let l:item = l:item . '//' - endif - - " Set path option (e.g. 'backupdir') - execute 'set ' . a:option_path . '^=' . l:item - -endfunction - -" If the root directory hasn't been specified with a global variable, we'll -" try to figure out a sensible value for it -if exists('g:auto_cache_dirs_root') - let s:root = g:auto_cache_dirs_root -else - - " If $XDG_CACHE_HOME is set, it's likely that using that is what the user - " will be least surprised by - if exists('$XDG_CACHE_HOME') - let s:root = '$XDG_CACHE_HOME/vim' - - " If there's no explicit cache dir, but we are running some sort of Unix, - " try to put it in ~/.cache - elseif has('unix') - let s:root = '~/.cache/vim' - - " If not, we'll try putting the directory into the first element of the - " 'runtimepath' value, so they'll at least be findable - else - let s:root = strpart(&runtimepath, 0, stridx(&runtimepath, ',')) - endif - -endif - -" Decide whether to append double-slash for supported options -let s:name_path = exists('g:auto_cache_dirs_name_path') - \ ? g:auto_cache_dirs_name_path - \ : 1 - -" Set backup, swap, and undo data directories as configured -if !exists('g:auto_cache_dirs_backup') || g:auto_cache_dirs_backup - call s:SetDir('backup', 'backupdir', 'backup', - \ 0) -endif -if !exists('g:auto_cache_dirs_swap') || g:auto_cache_dirs_swap - call s:SetDir('swapfile', 'directory', 'swap', - \ s:name_path) -endif -if (!exists('g:auto_cache_dirs_undo') || g:auto_cache_dirs_undo) - \ && has('persistent_undo') - call s:SetDir('undofile', 'undodir', 'undo', - \ s:name_path) -endif |