Update generated neovim config
This commit is contained in:
138
config/neovim/store/lazy-plugins/direnv.vim/autoload/direnv.vim
Normal file
138
config/neovim/store/lazy-plugins/direnv.vim/autoload/direnv.vim
Normal file
@ -0,0 +1,138 @@
|
||||
" direnv.vim - support for direnv <http://direnv.net>
|
||||
" Author: zimbatm <http://zimbatm.com/> & Hauleth <lukasz@niemier.pl>
|
||||
" Version: 0.3
|
||||
|
||||
scriptencoding utf-8
|
||||
|
||||
let s:direnv_cmd = get(g:, 'direnv_cmd', '/nix/store/1mrvvx2ygfyfz8sn3gg5f3qidvd9s8j1-direnv-2.34.0/bin/direnv')
|
||||
let s:direnv_interval = get(g:, 'direnv_interval', 500)
|
||||
let s:direnv_max_wait = get(g:, 'direnv_max_wait', 5)
|
||||
let s:direnv_auto = get(g:, 'direnv_auto', 1)
|
||||
let s:job_status = { 'running': 0, 'stdout': [], 'stderr': [] }
|
||||
|
||||
if !exists('g:direnv_silent_load')
|
||||
let g:direnv_silent_load = 0
|
||||
endif
|
||||
|
||||
function! direnv#auto() abort
|
||||
return s:direnv_auto
|
||||
endfunction
|
||||
|
||||
function! direnv#post_direnv_load() abort
|
||||
call direnv#extra_vimrc#load()
|
||||
doautocmd User DirenvLoaded
|
||||
endfunction
|
||||
|
||||
function! direnv#on_stdout(_, data, ...) abort
|
||||
if a:data != ['']
|
||||
call extend(s:job_status.stdout, a:data)
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! direnv#on_stderr(_, data, ...) abort
|
||||
if a:data != ['']
|
||||
call extend(s:job_status.stderr, a:data)
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! direnv#on_exit(_, status, ...) abort
|
||||
let s:job_status.running = 0
|
||||
|
||||
if !g:direnv_silent_load
|
||||
for l:m in s:job_status.stderr
|
||||
if l:m isnot# ''
|
||||
echom l:m
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
exec join(s:job_status.stdout, "\n")
|
||||
call direnv#post_direnv_load()
|
||||
endfunction
|
||||
|
||||
function! direnv#job_status_reset() abort
|
||||
let s:job_status['stdout'] = []
|
||||
let s:job_status['stderr'] = []
|
||||
endfunction
|
||||
|
||||
function! direnv#err_cb(_, data) abort
|
||||
call direnv#on_stderr(0, split(a:data, "\n", 1))
|
||||
endfunction
|
||||
|
||||
function! direnv#out_cb(_, data) abort
|
||||
call direnv#on_stdout(0, split(a:data, "\n", 1))
|
||||
endfunction
|
||||
|
||||
function! direnv#exit_cb(_, status) abort
|
||||
call direnv#on_exit(0, a:status)
|
||||
endfunction
|
||||
|
||||
if has('nvim')
|
||||
let s:job =
|
||||
\ {
|
||||
\ 'on_stdout': 'direnv#on_stdout',
|
||||
\ 'on_stderr': 'direnv#on_stderr',
|
||||
\ 'on_exit': 'direnv#on_exit'
|
||||
\ }
|
||||
else
|
||||
let s:job =
|
||||
\ {
|
||||
\ 'out_cb': 'direnv#out_cb',
|
||||
\ 'err_cb': 'direnv#err_cb',
|
||||
\ 'exit_cb': 'direnv#exit_cb'
|
||||
\ }
|
||||
endif
|
||||
|
||||
function! direnv#export() abort
|
||||
call s:export_debounced.do()
|
||||
endfunction
|
||||
|
||||
function! direnv#export_core() abort
|
||||
if !executable(s:direnv_cmd)
|
||||
echom 'No Direnv executable, add it to your PATH or set correct g:direnv_cmd'
|
||||
return
|
||||
endif
|
||||
|
||||
let l:cmd = [s:direnv_cmd, 'export', 'vim']
|
||||
if has('nvim')
|
||||
call jobstart(l:cmd, s:job)
|
||||
elseif has('job') && has('channel')
|
||||
if !has('timers')
|
||||
if s:job_status.running
|
||||
return
|
||||
endif
|
||||
let s:job_status.running = 1
|
||||
endif
|
||||
call direnv#job_status_reset()
|
||||
call job_start(l:cmd, s:job)
|
||||
else
|
||||
let l:tmp = tempname()
|
||||
echom system(printf(join(l:cmd).' '.&shellredir, l:tmp))
|
||||
exe 'source '.l:tmp
|
||||
call delete(l:tmp)
|
||||
call direnv#post_direnv_load()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let s:export_debounced = {'id': 0, 'counter': 0}
|
||||
|
||||
if has('timers')
|
||||
function! s:export_debounced.call(...)
|
||||
let self.id = 0
|
||||
let self.counter = 0
|
||||
call direnv#export_core()
|
||||
endfunction
|
||||
|
||||
function! s:export_debounced.do()
|
||||
call timer_stop(self.id)
|
||||
if self.counter < s:direnv_max_wait
|
||||
let self.counter = self.counter + 1
|
||||
let self.id = timer_start(s:direnv_interval, self.call)
|
||||
else
|
||||
call self.call()
|
||||
endif
|
||||
endfunction
|
||||
else
|
||||
function! s:export_debounced.do()
|
||||
call direnv#export_core()
|
||||
endfunction
|
||||
endif
|
||||
@ -0,0 +1,56 @@
|
||||
" direnv.vim - support for direnv <http://direnv.net>
|
||||
" Author: JINNOUCHI Yasushi <me@delphinus.dev>
|
||||
" Version: 0.2
|
||||
|
||||
let s:direnv_edit_mode = get(g:, 'direnv_edit_mode', 'edit')
|
||||
|
||||
function! direnv#edit#envrc() abort
|
||||
if $DIRENV_DIR !=# ''
|
||||
let l:envrc_dir = substitute($DIRENV_DIR, '^-', '', '')
|
||||
else
|
||||
let l:envrc_dir = getcwd()
|
||||
endif
|
||||
let l:envrc = l:envrc_dir . '/.envrc'
|
||||
if !filereadable(l:envrc)
|
||||
echom 'new .envrc file will be created:' l:envrc_dir
|
||||
endif
|
||||
call direnv#edit#execute(l:envrc)
|
||||
endfunction
|
||||
|
||||
function! direnv#edit#direnvrc() abort
|
||||
if $XDG_CONFIG_HOME ==# ''
|
||||
let l:direnvrc_dir = $HOME . '/.config/direnv'
|
||||
else
|
||||
let l:direnvrc_dir = $XDG_CONFIG_HOME . '/direnv'
|
||||
endif
|
||||
if filereadable(l:direnvrc_dir . '/direnvrc')
|
||||
let l:direnvrc = l:direnvrc_dir . '/direnvrc'
|
||||
elseif filereadable($HOME . '/.direnvrc')
|
||||
let l:direnvrc = $HOME . '/.direnvrc'
|
||||
else
|
||||
let l:direnvrc = l:direnvrc_dir . '/direnvrc'
|
||||
if !isdirectory(l:direnvrc_dir)
|
||||
let l:result = direnv#edit#mkdir(l:direnvrc_dir)
|
||||
if !l:result
|
||||
echoerr 'Vim cannot create the directory:' l:direnvrc_dir
|
||||
return
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
if !filereadable(l:direnvrc)
|
||||
echom 'new direnvrc file will be created:' l:direnvrc
|
||||
endif
|
||||
call direnv#edit#execute(l:direnvrc)
|
||||
endfunction
|
||||
|
||||
function! direnv#edit#mkdir(dir) abort
|
||||
if !exists('*mkdir')
|
||||
return 0
|
||||
endif
|
||||
let l:result = mkdir(a:dir, 'p', 0700)
|
||||
return l:result
|
||||
endfunction
|
||||
|
||||
function! direnv#edit#execute(file) abort
|
||||
execute ':' . s:direnv_edit_mode a:file
|
||||
endfunction
|
||||
@ -0,0 +1,28 @@
|
||||
" direnv.vim - support for direnv <http://direnv.net>
|
||||
" Author: JINNOUCHI Yasushi <me@delphinus.dev>
|
||||
" Version: 0.2
|
||||
|
||||
" load() sources local vimrc's described in $EXTRA_VIMRC
|
||||
function! direnv#extra_vimrc#load() abort
|
||||
let b:direnv_loaded_extra_vimrcs = get(b:, 'direnv_loaded_extra_vimrcs', {})
|
||||
if $DIRENV_EXTRA_VIMRC !=# ''
|
||||
for l:path in split($DIRENV_EXTRA_VIMRC, ':')
|
||||
if filereadable(l:path) && !has_key(b:direnv_loaded_extra_vimrcs, l:path)
|
||||
execute 'source' l:path
|
||||
let b:direnv_loaded_extra_vimrcs[l:path] = 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" check() checks $DIRENV_DIR and call load()
|
||||
function! direnv#extra_vimrc#check() abort
|
||||
if $DIRENV_DIR !=# ''
|
||||
let l:filedir = expand('%:p:h')
|
||||
let l:direnv_dir = substitute($DIRENV_DIR, '^-', '', '')
|
||||
" TODO think about Windows?
|
||||
if stridx(l:filedir, l:direnv_dir) == 0
|
||||
call direnv#post_direnv_load()
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
Reference in New Issue
Block a user