Add some utility functions for changing directories for commands

This commit is contained in:
w0rp 2017-03-21 13:09:02 +00:00
parent 6550cdfbd0
commit 2d1d6fb850
2 changed files with 22 additions and 0 deletions

View File

@ -144,3 +144,16 @@ endfunction
function! ale#util#ClockMilliseconds() abort function! ale#util#ClockMilliseconds() abort
return float2nr(reltimefloat(reltime()) * 1000) return float2nr(reltimefloat(reltime()) * 1000)
endfunction endfunction
" Output 'cd <directory> && '
" This function can be used changing the directory for a linter command.
function! ale#util#CdString(directory) abort
return 'cd ' . fnameescape(a:directory) . ' && '
endfunction
" Output 'cd <buffer_filename_directory> && '
" This function can be used changing the directory for a linter command.
function! ale#util#BufferCdString(buffer) abort
return ale#util#CdString(fnamemodify(bufname(a:buffer), ':p:h'))
endfunction

View File

@ -0,0 +1,9 @@
Before:
silent! cd /testplugin/test/util
Execute(CdString should output the correct command string):
AssertEqual 'cd /foo\ bar/baz && ', ale#util#CdString('/foo bar/baz')
Execute(BufferCdString should output the correct command string):
Assert match(ale#util#BufferCdString(bufnr('')), '^cd .*test/util && $') >= 0,
\ 'String didn''t match regex: ' . ale#util#BufferCdString(bufnr(''))