TODO item: add \# which lists line numbers, and allows command execution

Started by Sibte Abbasover 18 years ago2 messages
#1Sibte Abbas
sibtay@gmail.com

Hi all,

Realizing that the mentioned TODO item discussed at
http://archives.postgresql.org/pgsql-hackers/2006-12/msg00255.php<http://archives.postgresql.org/pgsql-hackers/2006-12/msg00255.php>can
be useful for myself and others as well, I would like to go ahead and
implement it.

Synopsis:
======

Sticking to the syntax and semantics which Joshua already mentioned in the
thread:

\#: displays the command history. Like \s but prefixes the lines with line
numbers

\# <line_no>: executes the command(if any) executed at the line specified by
line_no

Display the history contents:
=================

Well the answer to this pretty much lies in the \s (without any filename)
implementation. However \s simply writes the contents of the history to the
TTY while \# would prefix all the history lines with their respective line
numbers.

Because of this difference, we'll have to employ a more flexible approach
rather than simply using the write_history() function.

A solution to this is to use history_list() function to get a list of
HIST_ENTRY structures and simply display them as per our needs i.e. to
prefix each line with incrementing numbers in our case.

Execute a line based on line number:
======================

For this we can simply use the history_get(int offset) function of the gnu
history api to return a HIST_ENTRY structure corresponding to the given
offset.

The returned HIST_ENTRY can then be used to access the command that was
executed at that specific line number.

Comments are welcomed.

regards,
--
Sibte Abbas

#2Sibte Abbas
sibtay@gmail.com
In reply to: Sibte Abbas (#1)
Re: TODO item: add \# which lists line numbers, and allows command execution

On 9/8/07, Sibte Abbas <sibtay@gmail.com> wrote:

Hi all,

Realizing that the mentioned TODO item discussed at http://archives.postgresql.org/pgsql-hackers/2006-12/msg00255.php
<http://archives.postgresql.org/pgsql-hackers/2006-12/msg00255.php&gt; can be
useful for myself and others as well, I would like to go ahead and implement
it.

Synopsis:
======

Sticking to the syntax and semantics which Joshua already mentioned in the
thread:

\#: displays the command history. Like \s but prefixes the lines with line
numbers

\# <line_no>: executes the command(if any) executed at the line specified
by line_no

Display the history contents:
=================

Well the answer to this pretty much lies in the \s (without any filename)
implementation. However \s simply writes the contents of the history to the
TTY while \# would prefix all the history lines with their respective line
numbers.

Because of this difference, we'll have to employ a more flexible approach
rather than simply using the write_history() function.

A solution to this is to use history_list() function to get a list of
HIST_ENTRY structures and simply display them as per our needs i.e. to
prefix each line with incrementing numbers in our case.

Execute a line based on line number:
======================

For this we can simply use the history_get(int offset) function of the gnu
history api to return a HIST_ENTRY structure corresponding to the given
offset.

The returned HIST_ENTRY can then be used to access the command that was
executed at that specific line number.

Comments are welcomed.

regards,
--
Sibte Abbas

Patch submitted to pgsql-patches.

regards,
--
Sibte Abbas