[vim/vim] Add "fc" filetype when vim is opened from "fc" command (Issue #9861)

29 views
Skip to first unread message

SuperCuber

unread,
Feb 28, 2022, 11:11:00 AM2/28/22
to vim/vim, Subscribed

Is your feature request about something that is currently impossible or hard to do? Please describe the problem.
Detecting whether vim is currently opened by fc shell builtin is nontrivial - there's some logic described in filetype.vim around it (for example to detect zsh's /tmp/zsh* file but not something like zsh.vim), as well as needing to support more than one shell.

Describe the solution you'd like
The filetype can reflect this information - for example filetype=fc.zsh and filetype=fc.bash (I haven't considered other shells but they should be similar).

Describe alternatives you've considered
An alternative is for whoever needs it to add their own detection.

Additional context
This could be useful to develop plugins that enhance the fc experience.
It should be simple to implement by extracting the relevant patterns into a separate autocommand that will set the more specific filetype.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9861@github.com>

Bram Moolenaar

unread,
Feb 28, 2022, 12:39:39 PM2/28/22
to vim/vim, Subscribed


> **Is your feature request about something that is currently impossible or hard to do? Please describe the problem.**
> Detecting whether vim is currently opened by `fc` shell builtin is nontrivial - there's some logic described in `filetype.vim` around it (for example to detect zsh's `/tmp/zsh*` file but not something like `zsh.vim`), as well as needing to support more than one shell.
>
> **Describe the solution you'd like**

> The filetype can reflect this information - for example `filetype=fc.zsh` and `filetype=fc.bash` (I haven't considered other shells but they should be similar).
>
> **Describe alternatives you've considered**

> An alternative is for whoever needs it to add their own detection.
>
> **Additional context**

> This could be useful to develop plugins that enhance the `fc` experience.
> It should be simple to implement by extracting the relevant patterns into a separate autocommand that will set the more specific filetype.

Does this really require using a different filetype? When using "fc"
from bash, shouldn't the filetype be "bash"?

When I try it, the file name appears to be "/tmp/bash-fc.ID".
So maybe wen can match "/tmp/bash-fc.*" to set 'filetype' to "bash"?

What is the file name when using "fc" from zsh?

Any other shells that support the "fc" command?

--
I'm writing a book. I've got the page numbers done.

/// Bram Moolenaar -- ***@***.*** -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9861/1054501486@github.com>

SuperCuber

unread,
Feb 28, 2022, 2:03:53 PM2/28/22
to vim/vim, Subscribed

Does this really require using a different filetype? When using "fc"
from bash, shouldn't the filetype be "bash"?

I would like to add the more specific filetype as well (as far as I can understand filetype=fc.zsh would trigger both of the filetypes) for making plugins when launched by fc specifically, not just for a generic shell script. (think for example one that would preview output of the command)

other shells

Zsh opens /tmp/zshXXXXXX where X is some random letters (which is correctly recognized as zsh).
Seems like sh doesn't have fc.
Ksh creates a /tmp/ast.XXXXXX file which doesn't get recognized as any filetype.
Tcsh doesn't have a fc builtin
Fish doesn't appear to either

Also it seems like bash's fc file gets recognized as sh even though https://github.com/vim/vim/blob/5de4c4372d4366bc85cb66efb3e373439b9471c5/runtime/filetype.vim#L2444 looks like it should set it to bash


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9861/1054569254@github.com>

Gary Johnson

unread,
Feb 28, 2022, 2:21:25 PM2/28/22
to reply+ACY5DGBLYMDDKYWXCX...@reply.github.com, vim...@googlegroups.com
On 2022-02-28, SuperCuber wrote:
> Does this really require using a different filetype? When using "fc"
> from bash, shouldn't the filetype be "bash"?
>
> I would like to add the more specific filetype as well (as far as I can
> understand filetype=fc.zsh would trigger both of the filetypes) for making
> plugins when launched by fc specifically, not just for a generic shell script.
> (think for example one that would preview output of the command)
>
> other shells
>
> Zsh opens /tmp/zshXXXXXX where X is some random letters (which is correctly
> recognized as zsh).
> Seems like sh doesn't have fc.
> Ksh creates a /tmp/ast.XXXXXX file which doesn't get recognized as any
> filetype.
> Tcsh doesn't have a fc builtin
> Fish doesn't appear to either
>
> Also it seems like bash's fc file gets recognized as sh even though https://
> github.com/vim/vim/blob/5de4c4372d4366bc85cb66efb3e373439b9471c5/runtime/
> filetype.vim#L2444 looks like it should set it to bash

The filetype for bash files is sh. If Vim determines that it is
a bash file, then it sets b:is_bash = 1. (See
$VIMRUNTIME/autoload/dist/ft.vim.)

What I use for doing special things in fc buffers is this in my
~/.vim/after/ftplugin/sh.vim file:

if argv(0) =~ '^/tmp/bash-fc[-.]\w\+$'
" Stuff for fc buffers
endif

I use only bash, so I don't need to identify the shell or allow for
other shells.

Regards,
Gary

vim-dev ML

unread,
Feb 28, 2022, 2:21:44 PM2/28/22
to vim/vim, vim-dev ML, Your activity


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9861/1054584255@github.com>

Bram Moolenaar

unread,
Feb 28, 2022, 4:47:58 PM2/28/22
to vim/vim, vim-dev ML, Comment

Not sure if "fc" should be a separate filetype. Matching the filename yourself is the other end.
How about setting "b:is_fc" when appropriate?


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you commented.Message ID: <vim/vim/issues/9861/1054696532@github.com>

SuperCuber

unread,
Feb 28, 2022, 4:49:26 PM2/28/22
to vim/vim, vim-dev ML, Comment

How about setting "b:is_fc" when appropriate?

Seems reasonable to me.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you commented.Message ID: <vim/vim/issues/9861/1054697592@github.com>

SuperCuber

unread,
Mar 2, 2022, 3:32:25 AM3/2/22
to vim/vim, vim-dev ML, Comment

So I'm looking through this https://github.com/vim/vim/blob/f6b0c79742727948edee78cb1a3a9a4e3be8b0fd/runtime/autoload/dist/ft.vim#L579 and I guess the b:is_fc = 1 should go somewhere there. I wonder how the information would be passed to the function though... Adding another argument doesn't look like the way to go to me (backwards compat). Maybe the flag should just be set right in filetype.vim? Or perhaps a new function SetFileTypeShellFC could be created.


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you commented.Message ID: <vim/vim/issues/9861/1056564458@github.com>

Gary Johnson

unread,
Mar 2, 2022, 4:03:39 AM3/2/22
to reply+ACY5DGEU6KJUCUDDO3...@reply.github.com, vim...@googlegroups.com
On 2022-03-02, SuperCuber wrote:
> So I'm looking through this https://github.com/vim/vim/blob/
> f6b0c79742727948edee78cb1a3a9a4e3be8b0fd/runtime/autoload/dist/ft.vim#L579 and
> I guess the b:is_fc = 1 should go somewhere there. I wonder how the information
> would be passed to the function though... Adding another argument doesn't look
> like the way to go to me (backwards compat). Maybe the flag should just be set
> right in filetype.vim? Or perhaps a new function SetFileTypeShellFC could be
> created.

Notice near the top of that function this test:

if expand("<amatch>") =~ g:ft_ignore_pat
return
endif

It uses <amatch>, which ":help <amatch>" explains,

... is replaced with the match for which this autocommand was
executed. ... When the match is with a file name, it is
expanded to the full path.

So, you can match the expansion of <amatch> against the pattern of
an fc file name to determine whether to set b:is_fc. For example,

if expand("<amatch>") =~ '^/tmp/bash-fc[-.]\w\+$'
b:is_fc = 1
endif

Regards,
Gary

vim-dev ML

unread,
Mar 2, 2022, 4:03:59 AM3/2/22
to vim/vim, vim-dev ML, Your activity


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/9861/1056623320@github.com>

SuperCuber

unread,
Mar 2, 2022, 4:43:32 AM3/2/22
to vim/vim, vim-dev ML, Comment

Ah, I see. By the way, the pattern shouldn't include /tmp since this for example will fail to detect in Windows environments like mine :P


Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you commented.Message ID: <vim/vim/issues/9861/1056698473@github.com>

Reply all
Reply to author
Forward
0 new messages