Обсуждение: [PATCH] Add support to psql for edit-and-execute-command

Поиск
Список
Период
Сортировка

[PATCH] Add support to psql for edit-and-execute-command

От
"Joe Wildish"
Дата:
Hi hackers,

Attached is a small patch for adding "edit-and-execute-command" readline 
support to psql. Bash has this concept and I miss it when using psql. It 
allows you to amend the current line in an editor by pressing "v" (when 
in vi mode) or "C-x C-e" (when in emacs mode). Those are the default 
bindings from bash although of course they can be amended in inputrc.

Most of the patch is actually shifting "do_edit" from "command.c" to 
"common.c". There is a small amendment to that function to allow vi to 
launch at the correct column offset.

I noticed that there is some logic in configure for detecting certain 
readline functions. I assume this is for compatibility sake with 
libedit/editline? Rather than testing for each rl_* function I hid the 
functionality behind HAVE_READLINE_READLINE_H .. don't know if this is 
acceptable?

-Joe
Вложения

Re: [PATCH] Add support to psql for edit-and-execute-command

От
Oleksandr Shulgin
Дата:
On Mon, May 18, 2020 at 1:30 AM Joe Wildish <joe@lateraljoin.com> wrote:

Attached is a small patch for adding "edit-and-execute-command" readline
support to psql. Bash has this concept and I miss it when using psql. It
allows you to amend the current line in an editor by pressing "v" (when
in vi mode) or "C-x C-e" (when in emacs mode). Those are the default
bindings from bash although of course they can be amended in inputrc.

The only difference from \e is that you don't need to jump to the end of input first, I guess?

--
Alex

Re: [PATCH] Add support to psql for edit-and-execute-command

От
"Joe Wildish"
Дата:

On 18 May 2020, at 7:08, Oleksandr Shulgin wrote:

The only difference from \e is that you don't need to jump to the end of
input first, I guess?

AIUI, \e will edit the last thing in history or a specific line number from history, whereas the patch will allow the current line to be edited. That is 99% of the time what I want.

My work flow is typically "Run some queries" => "Go back to some recent query by searching history, often not the most recent" => "Edit query". To do the edit in an editor (without the patch), I've been deliberately nobbling the query once found from history. This allows it to execute (and fail) but places it as the most recent thing in history. Then I hit "\e".

-Joe

Re: [PATCH] Add support to psql for edit-and-execute-command

От
Pavel Stehule
Дата:


po 18. 5. 2020 v 12:05 odesílatel Joe Wildish <joe@lateraljoin.com> napsal:

On 18 May 2020, at 7:08, Oleksandr Shulgin wrote:

The only difference from \e is that you don't need to jump to the end of
input first, I guess?

AIUI, \e will edit the last thing in history or a specific line number from history, whereas the patch will allow the current line to be edited. That is 99% of the time what I want.

My work flow is typically "Run some queries" => "Go back to some recent query by searching history, often not the most recent" => "Edit query". To do the edit in an editor (without the patch), I've been deliberately nobbling the query once found from history. This allows it to execute (and fail) but places it as the most recent thing in history. Then I hit "\e".


\e is working with not empty line too.You can check

select 1\e

Your patch just save skip on end line and \e

Personally I think so it is good idea

Pavel


-Joe

Re: [PATCH] Add support to psql for edit-and-execute-command

От
"Joe Wildish"
Дата:

On 18 May 2020, at 11:09, Pavel Stehule wrote:

\e is working with not empty line too.You can check

select 1\e

Your patch just save skip on end line and \e

Personally I think so it is good idea

Thanks. I did not realise that \e at the end of a line would edit that line. (although you do need to remove the terminator I notice).

-Joe

Re: [PATCH] Add support to psql for edit-and-execute-command

От
Pavel Stehule
Дата:


po 18. 5. 2020 v 12:16 odesílatel Joe Wildish <joe@lateraljoin.com> napsal:

On 18 May 2020, at 11:09, Pavel Stehule wrote:

\e is working with not empty line too.You can check

select 1\e

Your patch just save skip on end line and \e

Personally I think so it is good idea

Thanks. I did not realise that \e at the end of a line would edit that line. (although you do need to remove the terminator I notice).


it is different method with little bit different usage - both method can be supported


-Joe