Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

zsh: read with timeout?



Gurus and mere mortals,

Is there a way to give the read-command (in zsh) a timeout-value? 

When I log in to my workstation, I want my login-script to ask me
which window manager to run. If I don't answer anything, I want it to
run the default manager.

My present solution is a kludge: I spawn off a subprocess which sleeps
for a while and then sends a signal to the parent process. This signal
lets the script break out of the read.

Is there a better way?

This is the relevant part of my .zlogin file:

    -------------------------------------------------------
    if [[ $TTY = /dev/console && -a /dev/fb ]]
    then
        # Choose window manager. If no input within specified period of
        # time, a default is chosen. "Interesting" hack handles timeout
        # process.
    
        nop() { }                           # dummy func def
        trap nop INT                        # trap ^C
        ( sleep 15; kill -INT $$ 2>/dev/null ) &
        disown %%
    
        echo -n "Console, Fvwm, Motif, OpenWindows or SunView? "
        read answer
    
        # fvwm is my default window manager, hence "${answer:-f}".
        case ${answer:-f} in
            c|C) # this should leave us on the console
                ;;
            f|F) export XINITRC=.xinitrc.fvwm
                openwin -ar1 250 -ar2 25 -nobanner
                clear
                logout
                ;;
            m|M) export XINITRC=.xinitrc.mwm
                /usr/bin/X11/mwm
                clear
                logout
                ;;
            o|O) # kbd-def's in file .SverreKeys.ps
                export XINITRC=.xinitrc.olwm
                openwin
                clear
                logout
                ;;
            s|S) loadkeys ~/.setkbd.swe
                sunview
                clear
                logout
                ;;
            *)  # should we do something here?
                ;;
        esac
    
    fi
    -------------------------------------------------------
    

Sverre

----------------------------------------------------------------------------
Sverre Slotte                            Internet: sverre@xxxxxxxxxxxxxxxxxx
Nokia Research Center                    Phone:             + 358 0 43766208
P.O.Box 45, 00211 Helsingfors, Finland   Phax:              + 358 0 43766856
----------------------------------------------------------------------------
"Kajakken er uten sammenligning den ypperste enkeltmannsfarkost som finnes."
                                                      -- Fritjof Nansen 1891



Messages sorted by: Reverse Date, Date, Thread, Author