Enhancement idea: "vim --get-vimruntime"

24 views
Skip to first unread message

Peter Whittaker

unread,
Jun 12, 2020, 5:34:12 AM6/12/20
to vim...@vim.org
Folks, posting here to gauge interest before adding an issue on
GitHub: What interest is there in adding a command line option that
causes vim to return the current value of VIMRUNTIME?

The use case is to find macros, etc., dynamically, e.g., in one's
.bashrc, et al, with minimum hardcoding. Example: I have the following
lines in one of my BASH dotfiles (lines broken and \ added for
readability):

# if available, use a better less - warning, this is gross but unavoidable
vimrntm=$(vim --not-a-term -T dumb --cmd 'echo $VIMRUNTIME' --cmd quit | \
tr -d '\n\r' |sed -E 's,[^/]+,,')
vimless=${vimrntm}/macros/less.sh
[[ -x ${vimless} ]] && alias less=${vimless} || { \
echo; echo You may want to find less.sh manually, using pure less
for now.; \
echo; }

What I'd really like is "vimrntm=$(vim --get-vimruntime)", which would
simply print out an appropriately terminated string containing the
value, e.g., /usr/share/vim/vim81.

Note that I don't set VIMRUNTIME anywhere, I am simply trying to
retrieve it in the most efficient way. On the various platforms I work
on, it may be /usr/share/vim/vim74, ...81, ...82, etc., or absent.

Thoughts?

Thanks,

P

Peter Whittaker

Bram Moolenaar

unread,
Jun 12, 2020, 1:36:37 PM6/12/20
to vim...@googlegroups.com, Peter Whittaker, vim...@vim.org
I think you already found a way that works:
vi --not-a-term -c 'echo $VIMRUNTIME' -c q

Perhaps add "-e" to make it a little faster.

Why would a command line argument be needed that would do the same
thing?

--
GUARD #2: Wait a minute -- supposing two swallows carried it together?
GUARD #1: No, they'd have to have it on a line.
GUARD #2: Well, simple! They'd just use a standard creeper!
GUARD #1: What, held under the dorsal guiding feathers?
GUARD #2: Well, why not?
The Quest for the Holy Grail (Monty Python)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Peter Whittaker

unread,
Jun 15, 2020, 2:44:25 PM6/15/20
to Bram Moolenaar, vim...@googlegroups.com, vim...@vim.org
On Fri, Jun 12, 2020 at 1:36 PM Bram Moolenaar <Br...@moolenaar.net> wrote:
> Peter Whittaker wrote:
>
> > vimrntm=$(vim --not-a-term -T dumb --cmd 'echo $VIMRUNTIME' --cmd quit | \
> > tr -d '\n\r' |sed -E 's,[^/]+,,')
> >
> > What I'd really like is "vimrntm=$(vim --get-vimruntime)"
>
> I think you already found a way that works:
> vi --not-a-term -c 'echo $VIMRUNTIME' -c q
>
> Why would a command line argument be needed that would do the same
> thing?

It's not exactly doing the same thing: The existing capability
requires post-processing to remove extraneous characters, which isn't
surprising, since those characters aren't extraneous for vim's default
behaviour, which is managing a graphical display. Based on a 10+ year
old example I found online, I hacked together a double pipeline of tr
and sed to remove those characters, but that's definitely ugly, and it
also feels fragile: I'm hardcoding in knowledge of what those
characters are; it works everywhere I need it to right now, but it
feels iffy.

So the difference is that --get-default-runtime would just spit out
exactly that, no screen driving characters; this would be directly
assignable without further filtering.

There should be difference between what is displayed on the screen or
what is written to a file; right now, with the "echo" method, there
is.

My first, simplest thought was to add an appropriate function to
version.c, since version.c already has code to do this it's done as
part of list_version(): list_version() doesn't add the extraneous
format controls (unless it is called as a vim function, e.g., as
":version", not on the command line). It occurs to me we do define a
vim function for this as well.

I started pulling together the list of files that should be changed,
e.g., code, documentation, for both cases. If we decide this is
worthwhile, I'll create a github issue and add the design thoughts and
file list therein, and then bash away at it a while.

Thoughts?

P


Peter Whittaker
EdgeKeep Inc.
www.edgekeep.com

Gary Johnson

unread,
Jun 15, 2020, 3:39:22 PM6/15/20
to vim...@googlegroups.com
On 2020-06-15, Peter Whittaker wrote:
> On Fri, Jun 12, 2020 at 1:36 PM Bram Moolenaar <Br...@moolenaar.net> wrote:
> > Peter Whittaker wrote:
> >
> > > vimrntm=$(vim --not-a-term -T dumb --cmd 'echo $VIMRUNTIME' --cmd quit | \
> > > tr -d '\n\r' |sed -E 's,[^/]+,,')
> > >
> > > What I'd really like is "vimrntm=$(vim --get-vimruntime)"
> >
> > I think you already found a way that works:
> > vi --not-a-term -c 'echo $VIMRUNTIME' -c q
> >
> > Why would a command line argument be needed that would do the same
> > thing?
>
> It's not exactly doing the same thing: The existing capability
> requires post-processing to remove extraneous characters, which isn't
> surprising, since those characters aren't extraneous for vim's default
> behaviour, which is managing a graphical display. Based on a 10+ year
> old example I found online, I hacked together a double pipeline of tr
> and sed to remove those characters, but that's definitely ugly, and it
> also feels fragile: I'm hardcoding in knowledge of what those
> characters are; it works everywhere I need it to right now, but it
> feels iffy.

I just threw this together and saw no extraneous characters.

$ vim -u NONE -es -c '!echo $VIMRUNTIME' -c q

Regards,
Gary

Peter Whittaker

unread,
Jun 16, 2020, 9:56:51 AM6/16/20
to vim...@googlegroups.com
On Mon, Jun 15, 2020 at 3:39 PM Gary Johnson <gary...@spocom.com> wrote:
>
> I just threw this together and saw no extraneous characters.
>
> $ vim -u NONE -es -c '!echo $VIMRUNTIME' -c q

Brilliant! Much simpler, thanks.
Reply all
Reply to author
Forward
0 new messages