[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Only set VISUAL for edit-and-execute-command
From: |
Mike |
Subject: |
Re: Only set VISUAL for edit-and-execute-command |
Date: |
Thu, 30 May 2024 12:23:09 -0400 |
Thanks for the info!
I agree EDIT_AND_EXECUTE_COMMAND is not a great name 😂. Is there a place
that I can track if this functionality is added in the future?
I think for simplicity I am going with the approach mentioned by Koichi for
now.
#!/usr/bin/env bash
if [[ $1 == *bash-fc* ]]; then
exec script-to-be-invoked-by-edit-and-execute "$@"
else
exec nvim "$@"
fi
and put it in VISUAL
VISUAL=custom-visual-selector
On Wed, May 29, 2024 at 10:50 AM Chet Ramey <chet.ramey@case.edu> wrote:
> On 5/23/24 11:11 PM, Mike wrote:
> > I am working on a script that I'd like to be invoked
> > by edit-and-execute-command. Currently, it works fine if I set the VISUAL
> > environment variable and press C-xC-e. However, I don't want to set
> VISUAL
> > to this script globally because I only want it to run in the context of
> > C-xC-e. I'd like to keep VISUAL set to nvim so that other applications
> can
> > still use VISUAL as expected.
> >
> > I see the source for edit_and_execute_command looks for VISUAL and then
> > EDITOR.
> >
> > #define VI_EDIT_COMMAND "fc -e \"${VISUAL:-${EDITOR:-vi}}\""
> > #define EMACS_EDIT_COMMAND "fc -e \"${VISUAL:-${EDITOR:-emacs}}\""
> > #define POSIX_VI_EDIT_COMMAND "fc -e vi"
> >
> > Is there a way to create a binding that could in a local scope set VISUAL
> > to my script and then trigger edit-and-execute-command?
>
> There isn't. Not in the current version of bash, at least. There are a
> couple of things you can do without changes to bash (I have not tested
> either approach).
>
> If you don't use `fc' for anything else, write a shell function to replace
> it and call `builtin fc -e whatever' from within the function. For
> completeness, you might want to have this function handle a single digit
> argument and operate on that history list entry instead of the current
> line.
>
> You could also write a shell function, bind it with bind -x, and use it to
> replace the default binding. You'd have to perform temp file management
> yourself, then eval the edited contents of the file manually, and clear
> READLINE_LINE, but it would probably work just fine.
>
> > Ideally, there would be another environment variable that I could hook
> into
> > just for this specific case. For example if the source had something like
> > this:
> >
> > ${EDIT_AND_EXECUTE_COMMAND:-${VISUAL:-${EDITOR:-emacs}}}
>
> That's not a great name, but I'll consider this functionality for a future
> bash version.
>
> Chet
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> ``Ars longa, vita brevis'' - Hippocrates
> Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
>
>