TODO item: add \# which lists line numbers, and allows command execution
От | Sibte Abbas |
---|---|
Тема | TODO item: add \# which lists line numbers, and allows command execution |
Дата | |
Msg-id | bd6a35510709081224n39944b6bs87a52b2abb79b788@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: TODO item: add \# which lists line numbers, and allows command execution
|
Список | pgsql-hackers |
<br />Hi all,<br /><br clear="all" />Realizing that the mentioned TODO item discussed at <span style="text-decoration: underline;"><a href="http://archives.postgresql.org/pgsql-hackers/2006-12/msg00255.php">http://archives.postgresql.org/pgsql-hackers/2006-12/msg00255.php </a></span><ahref="http://archives.postgresql.org/pgsql-hackers/2006-12/msg00255.php" target="_blank"></a> can be usefulfor myself and others as well, I would like to go ahead and implement it. <br /><br />Synopsis:<br />======<br /><br/>Sticking to the syntax and semantics which Joshua already mentioned in the thread:<br /><br />\#: displays the commandhistory. Like \s but prefixes the lines with line numbers<br /><br />\# <line_no>: executes the command(if any)executed at the line specified by line_no <br /><br /><br />Display the history contents:<br />=================<br /><br/>Well the answer to this pretty much lies in the \s (without any filename) implementation. However \s simply writesthe contents of the history to the TTY while \# would prefix all the history lines with their respective line numbers.<br /><br />Because of this difference, we'll have to employ a more flexible approach rather than simply using thewrite_history() function.<br /><br />A solution to this is to use history_list() function to get a list of HIST_ENTRYstructures and simply display them as per our needs i.e. to prefix each line with incrementing numbers in our case.<br/><br />Execute a line based on line number:<br />======================<br /><br />For this we can simply use thehistory_get(int offset) function of the gnu history api to return a HIST_ENTRY structure corresponding to the given offset.<br /><br />The returned HIST_ENTRY can then be used to access the command that was executed at that specific linenumber.<br /><br />Comments are welcomed.<br /><br />regards,<br />-- <br />Sibte Abbas<br />
В списке pgsql-hackers по дате отправления: