[comp.sys.hp] CI.STK history function

ryan@sjuphil.uucp (Patrick M. Ryan) (02/20/90)

I have never been overly thrilled with the history capabilities of any
of the Un*x shells which I have used (csh, sh, ksh, tcsh, etc.).  One
history command I do like, though, is the one in HP's RTE-A running
on an HP 1000.  The way it works is this: Type '/' and the system
will display the last 10 (or so) commands you have executed (in
much the same way as csh's 'history').  One then simply moves the
cursor up the list of commands and hits RETURN on the one he or
she wishes to repeat.  The user also has the option, while perusing
the list, of editing a command in wordprocessor-like fashion before
executing it.  If the user types '//' instead of '/', just the last
command is displayed.  Easy, no?

The reason for this post is to see if anyone has a neat hack by which
I might emulate this RTE-A history capability in the Berkeley shell.
Suggestions and partial solutions are welcome.

Please email responses and I'll post a summary.

-- 
patrick m. ryan
  ryan%sjuphil.sju.edu@bpa.bell-atl.com
  {bpa|burdvax|princeton|rutgers}!sjuphil!ryan
  pmr@gemini.gsfc.nasa.gov

tml@hemuli.tik.vtt.fi (Tor Lillqvist) (02/20/90)

In article <1990Feb19.235123.5458@sjuphil.uucp> ryan@sjuphil.uucp (Patrick M. Ryan) writes:
>I have never been overly thrilled with the history capabilities of any
>of the Un*x shells which I have used (csh, sh, ksh, tcsh, etc.).  One
>history command I do like, though, is the one in HP's RTE-A running
>on an HP 1000.  The way it works is this: Type '/' and the system
>will display the last 10 (or so) commands you have executed (in
>much the same way as csh's 'history').  One then simply moves the
>cursor up the list of commands and hits RETURN on the one he or
>she wishes to repeat.  The user also has the option, while perusing
>the list, of editing a command in wordprocessor-like fashion before
>executing it.  If the user types '//' instead of '/', just the last
>command is displayed.  Easy, no?

\begin{flame}

This guy must be joking...  Has he really tried Emacs (or vi) editing
mode in ksh (or bash)?  I don't understand how he can claim that
RTE-A's pathetic command stack is better.

- CI: only works on HP terminals, and if EnqAck handshake
  enabled
- ksh: works on any terminal described by terminfo

- CI: only uses the terminal's local editing capabilities
  (wordprocessor-like fashion, sure...  if you call edit/1000 a
  wordprocessor) 
- ksh: you can move to end of line with Control-e, over a word with
  Meta-f, etc.  Numeric args (Control-U, Meta-[1-9] work, too.

- CI: no searching
- ksh: Control-R searches for command matching string

- CI: if the command line you want to re-execute was longer that 80
  chars, tough...
- ksh: scrolls horizontally

That said above for ksh also goes for bash (the GNU Bourne Again
Shell), only more so.  Let's hope the next version will compile and
work well on HP-UX systems, too.

\end{flame}
-- 
Tor Lillqvist,
working, but not speaking, for the Technical Research Centre of Finland

davem@hp-ptp.HP.COM (Dave_Medlicott) (02/21/90)

Tor Lillqvist writes:

> \begin{flame}
> 
> This guy must be joking...  Has he really tried Emacs (or vi) editing
> mode in ksh (or bash)?  I don't understand how he can claim that
> RTE-A's pathetic command stack is better.

  I'm not really sure why a flame is needed. He is merely stating a
  preference; one which I share.

> 
> - CI: only works on HP terminals, and if EnqAck handshake
>   enabled
> - ksh: works on any terminal described by terminfo

  This is true. The command stack reads what is written on the
  screen NOT what was in its input buffer. Thus a terminal that
  can send the entire line is required.

> - CI: only uses the terminal's local editing capabilities
>   (wordprocessor-like fashion, sure...  if you call edit/1000 a
>   wordprocessor) 
> - ksh: you can move to end of line with Control-e, over a word with
>   Meta-f, etc.  Numeric args (Control-U, Meta-[1-9] work, too.

  This is true for the most part, however, the CI command stack 
  can use ctrl A to position to the 1st character in a line and
  ctrl Z to position to the end of the line.

> - CI: no searching
> - ksh: Control-R searches for command matching string

  This is not true. Under CI you can use the /.pattern format to search for 
  patterns. Patterns can also have imbedded wildcards. You can also specify
  that the first command that matches the pattern be executed.

> - CI: if the command line you want to re-execute was longer that 80
>   chars, tough...
> - ksh: scrolls horizontally

    The CI command line buffer has been extended to 256 characters.

> That said above for ksh also goes for bash (the GNU Bourne Again
> Shell), only more so.  Let's hope the next version will compile and
> work well on HP-UX systems, too.
> 
> \end{flame}
> -- 
> Tor Lillqvist,
> working, but not speaking, for the Technical Research Centre of Finland

  Some of the other reasons why I like the CI stack better:

	1) Only one copy of a command is stored in the command stack i.e.
	   if I enter the same command twice in a row, only one copy is
	   saved.

	2) Placing the cursor on a line and then hitting ctrl K puts
	   the line into an execute buffer. Hitting ctrl Q then quits
	   screen mode and begins executing commands in the order they
	   were entered into the execute buffer.

	3) Hitting ctrl D deletes the line the cursor is on from your
	   command stack (thus preventing garbage from building up in
	   your stack).

	4) The CI / command displays an entire screen (size is user definable)
	   of commands, not just the most recent command. This makes it much
	   easier to find that one command you're looking for.


	Again, these are only my personal preferences. 

Dave Medlicott 
davem@hpdstma

jmorris@hpsemc.HP.COM (John V. Morris) (02/22/90)

With csh, you can simulate CI's / and // commands by adding the following 
statements to your .cshrc file.

-----------------------------------
set history = 20
alias / 'history -h \!*; line>/dev/null; /bin/echo "\033J\033R\033A\033d\021\c"'
alias // 'history -h 2 | head -1;         /bin/echo "\033A\c"; line > /dev/null; /bin/echo "\033J\033R\033A\033d\021\c"'
--------------------------------------

I don't think it would be difficult to translate these into equivalent commands
for sh or ksh.

John Morris
HP VAB Partners Lab

mck@hpcuhc.HP.COM (Doug McKenzie) (02/22/90)

> / hpcuhc:comp.sys.hp / ryan@sjuphil.uucp (Patrick M. Ryan) /  3:51 pm  Feb 19, 1990 /
> I have never been overly thrilled with the history capabilities of any
> of the Un*x shells which I have used (csh, sh, ksh, tcsh, etc.).  One
> history command I do like, though, is the one in HP's RTE-A running
> on an HP 1000.  The way it works is this: Type '/' and the system
> will display the last 10 (or so) commands you have executed (in
> much the same way as csh's 'history').  One then simply moves the
> cursor up the list of commands and hits RETURN on the one he or
> she wishes to repeat.  The user also has the option, while perusing
> the list, of editing a command in wordprocessor-like fashion before
> executing it.  If the user types '//' instead of '/', just the last
> command is displayed.  Easy, no?
> 
> The reason for this post is to see if anyone has a neat hack by which
> I might emulate this RTE-A history capability in the Berkeley shell.
> Suggestions and partial solutions are welcome.


For what it's worth, here's an alias that will do what you want.
It was great, until I switched to the ksh.  I'm afraid I agree with
all Tor's comments in his response, too.

Note that ^[ is two chars here, but should be one (escape).

alias hi 'echo -n ^[J;h -h;set ss=$<;echo -n ^[R^[J^[A^[d^Q;unset ss;sleep 1'


Doug McKenzie
HP-UX Support
mck@hpcugsya.cup.hp.com

dhb@hpcupt1.HP.COM (Dan Barnes) (02/23/90)

Here is a set of alias's that I have.  This may seem long.
The reason it seems long is that it tries to move the cursor
up to the specified line if you tell it do display a particular
number of lines.

Note:	The characters ^[ are a two character representation
	for the escape character.

alias	/	'csc_p1 \!:*'
alias	//	'csc_p1 2'
alias	/5	'csc_p1 6'
alias	/11	'csc_p1 12'
alias	/22	'csc_p1 23'
alias	csc_p1	'echo ^[J--- Commands ---;\\
	@ csc = \!:*;if (\!:* ==  )@ csc = $history;history -h $csc;\\
	if (\!:* !=   )repeat \!:* echo -n ^[A;set csc = $<;\\
	echo -n ^[R^[J^[A^[d;sleep 1'

alias	x	'set csc = $<;echo -n ^[R^[J^[A^[d;sleep 1'


Dan Barnes

eugene@hpfcmgw.HP.COM (Gene Dick) (02/24/90)

>> 
>> - CI: only works on HP terminals, and if EnqAck handshake
>>   enabled
>> - ksh: works on any terminal described by terminfo

>  This is true. The command stack reads what is written on the
>  screen NOT what was in its input buffer. Thus a terminal that
>  can send the entire line is required.

  Again I agree that this is true, except the requirement of
  having EnqAck.  In my HP-UX environment I can be using any HP terminal,
  or Hpterm window in X11 (I have not tried an xterm window) to use a
  psuedo CI command mode edit (in csh).  This method will not work
  directly on a bit-mapped display outside a window environment.

  The only features implemented are the / and // without any search
  capability.

  I have since switched to ksh and the vi mode of editing commands,
  but the / and // CI method normally requires less keystrokes to
  accomplish the same editing.

  So, here are the two csh aliases I have used.  I have seen other
  methods which also work.  The line length is rather long so I have
  broken them up into 5 lines.  Lines 1 & 2 as well as 3-5 should
  be concatenated.

1) alias /  'history | sed -e "s/.......//" -e "\~^//* *"\$"~d" |
2)   tail -\!*; line > /dev/null; /bin/echo "\033J\033R\033A\033d\021\c"'

3) alias // 'history | sed -e "s/.......//" -e "\~^//* *"\$"~d" |
4)     tail -1; /bin/echo "\033A\c"; line > /dev/null; 
5)     /bin/echo "\033J\033R\033A\033d\021\c"'


The key to this working is exactly what the CI process does, at the end
of the last echo command are the characters \033d and \021.  The escape
sequence of \033d puts the "terminal" into a transmit line mode and the
\021 starts the transfer.  The other escape sequences put the cursor
at the start of the line being edited.

***CAUTION NOTE****>>  When used on an hpterm window:  if during editing
		       you place the cursor on a blank line, the hpterm
		       window will *HANG*.  So at least move the cursor
		       to some "safe" command or type one in *BEFORE*
		       hitting the return key.

#include Standard-disclaimer

Gene Dick
eugene@hpfcmr

rclark@speclab.bgp-usgs.gov (Roger N. Clark) (02/27/90)

> 1) alias /  'history | sed -e "s/.......//" -e "\~^//* *"\$"~d" |
> 2)   tail -\!*; line > /dev/null; /bin/echo "\033J\033R\033A\033d\021\c"'
> 
> 3) alias // 'history | sed -e "s/.......//" -e "\~^//* *"\$"~d" |
> 4)     tail -1; /bin/echo "\033A\c"; line > /dev/null; 
> 5)     /bin/echo "\033J\033R\033A\033d\021\c"'

It would be more efficient (and it seems from the conversation on
this note that some don't know all the features of history) that
instead of using tail, to say how many history lines you want.  For
example:
         history | tail -1

is the same as:

         history 1

To save typing, try:

alias history 'h'
h 1

Similarly, instead of

         history | sed ... | tail -\!*

use
         history \!* | sed ...

(It will also execute slightly faster).

Roger N. Clark
rclark%speclab.uucp@csm9a.colorado.edu                      # Internet