Wrapping the invocation of "ex -s ..." seems to work pretty well;
args can be processed by the wrapper script, passed to vim as globals.
In the following test, note the final "-c q", it is needed to prevent
vim waiting in exmode. The interesting thing is that if the vimscript
exits with an exception or :cquit, then after the bash shell
script exits, the return code is 1 (as hoped for), otherwise it
exits with 0. This seems to be undocumented behavior.
The only weirdness is that the last echo of the vimscript
does not have a trailing newline, but that's remedied
with an echo in the bash script.
ex -s -c "$arg" \
-c "redir >> /dev/stdout" \
-c "source $vimscript" \
-c q
echo
-ernie
On 23/03/28 12:15 PM, Ernie Rael wrote:
I want to run some vim stuff from a shell script.
Some issues I can think of
* passing arguments to vim
* don't draw a screen
* seeing output
* seeing errors
The following more or less works; it would be nice
if vim, on an error, automatically exited with an error;
"echo g:what" in this case.
Looking for suggestions and/or alternatives and/or doc ref?
Thanks,
-ernie
Doing:
ex -s -c 'let g:arg = 123' -c 'redir >> /dev/stdout' -c 'source t.vim'
where t.vim is
vim9script
echo g:arg
echo 'foo'
echo g:what
echo "\n"
q
produces the output
123
foo
Error detected while processing command line..script /.../t.vim:
line 4:
E121: Undefined variable: g:what
Entering Ex mode. Type "visual" to go to Normal mode.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google
Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/6443a0af-f327-43ec-b6ee-49f855466fe7%40raelity.com
<https://groups.google.com/d/msgid/vim_dev/6443a0af-f327-43ec-b6ee-49f855466fe7%40raelity.com?utm_medium=email&utm_source=footer>.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/7f360287-0059-dfe3-ed6f-3f17967e37de%40raelity.com.