Skip to content

Commit c91d5fd

Browse files
committed
Source env file in started jobs
This is helpful to set up stuff for Lsp and Pty, e.g. pyright/ruff installed in a virtual environment.
1 parent 6385249 commit c91d5fd

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

bin/axec

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
if [ -r .env.sh ]; then
3+
. ./.env.sh
4+
elif [ -r x/env.sh ]; then
5+
. x/env.sh
6+
fi
7+
exec "$@"

plugin/acme.vim

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ endfunc
174174

175175
function s:Argv(cmd)
176176
return type(a:cmd) == type([]) ? a:cmd : [&shell, &shellcmdflag, a:cmd]
177+
endfunc
178+
179+
function s:ArgvAxec(cmd, cwd)
180+
let argv = s:Argv(a:cmd)
181+
return filereadable(a:cwd.'/.env.sh') || filereadable(a:cwd.'/x/env.sh')
182+
\ ? [s:avimdir.'/bin/axec'] + argv : argv
177183
endfunc
178184

179185
function s:JobEnv(buf)
@@ -205,8 +211,9 @@ function s:JobStart(cmd, outb, ctxb, opts, inp)
205211
\ 'out_msg': 0,
206212
\ }
207213
call extend(opts, a:opts)
214+
let cwd = get(a:opts, 'cwd', getcwd())
208215
let env = s:SetEnv(s:JobEnv(a:outb))
209-
let job = job_start(s:Argv(a:cmd), opts)
216+
let job = job_start(s:ArgvAxec(a:cmd, cwd), opts)
210217
call s:SetEnv(env)
211218
if job_status(job) == "fail"
212219
return
@@ -1207,7 +1214,8 @@ set completefunc=s:InsComplete
12071214
let &statusline = '%{AcmeStatusBox()}%<%{%AcmeStatusName()%}' .
12081215
\ '%{%AcmeStatusFlags()%}%{AcmeStatusJobs()}%=%{%AcmeStatusRuler()%}'
12091216

1210-
let s:ctrlexe = exepath(expand('<sfile>:p:h:h').'/bin/avim')
1217+
let s:avimdir = expand('<sfile>:p:h:h')
1218+
let s:ctrlexe = exepath(s:avimdir.'/bin/avim')
12111219
let s:ctrlrx = ''
12121220
let s:cwd = {}
12131221
let s:dirwidth = {}

0 commit comments

Comments
 (0)