How to execute a program as part of the prompt

How to execute a program as part of the prompt

Post by Orville R. Weyri » Tue, 03 Sep 1991 04:04:41



I asked the net previously a question like this, and the silence was
sort of numbing. :-) I'll try again in different words.

I am using Microport System V/386 3.2, but would like as portable of a solution
as I can get.

What I would like to do is to get have a hook in the PROMPT-READ-EXECUTE
loop of the "sh" shell so that I get the loop HOOK-PROMPT-READ-EXECUTE
where HOOK executes a program or shell script of the user's choice
before each prompt.

The best I can come up with is to write a short C program with pseudo-code
as follows:

        main
        {
                for (;;;)
                {
                        fork
                                if child
                                        execl /bin/sh sh cmd hook null
                        prompt
                        read cmd
                        fork
                                if child
                                        excecl /bin/sh sh cmd null
                }
        }

This program would be invoked by the last line of the .profile. I am pretty
sure that it will sort-of work, but it seems rather clumsy and inefficient.
Is there a better way? Are there any hidden gottchas?

(I would consider changing to another shell, but my impression is that "sh" is
the most portable).

Thanks in advance for the help,

Orville.

--------------------------------------           ******************************
Orville R. Weyrich, Jr., Ph.D.                   Certified Systems Professional

Voice:    (602) 391-0821                         POB 5782, Scottsdale, AZ 85261
Fax:      (602) 391-0023                              (Yes! I'm available)
--------------------------------------           ******************************

 
 
 

How to execute a program as part of the prompt

Post by Mike O'Conn » Tue, 03 Sep 1991 23:00:35



Quote:(Orville R. Weyrich) writes:

:
:(I would consider changing to another shell, but my impression is that "sh" is
:the most portable).
:

tcsh does what you want as basically a built-in feature.  You alias
precmd to a program that you wish to execute, and that program will
execute before he printing of every prompt.  It is available for
anonymous FTP from tesla.ee.cornell.edu, and I am fairly sure that
there are other menas of getting it if anonymous FTP is not available

 Mike O'Connor                            | "I need a vacation."
 NIC Database:  MJO17                     |  

 UUCP:  ...!ttardis!mjo                   |

 
 
 

How to execute a program as part of the prompt

Post by Jean-Jacques More » Thu, 05 Sep 1991 02:51:14


Quote:> tcsh does what you want as basically a built-in feature.  You alias
> precmd to a program that you wish to execute, and that program will
> execute before the printing of every prompt.

This method is also possible with zsh (zsh is a superset of a lot of
existing shells, including ksh and tcsh; it is freely available and
seems to me rather portable).

Jean-Jacques Moreau.