Garrett D'Amore wrote:
> 
> Sorry if this is a FAQ.
> 
> I've switched to ksh93 as my default interactive shell.  But one more
> behavior is bugging me.
> 
> I often have numerous command windows up at a time.  I do different
> kinds of things in them -- e.g. one window is on a host doing testing,
> while another is a directory doing compilation.
> 
> For these things, I prefer to have my shell history *not* be shared with
> all windows... but each window (or each shell process) to have its own
> history.
> 
> Is there a way I can get this behavior with ksh93, instead of the
> default "all windows share a common history file" behavior?  (Note: as a
> consequence of this, I don't care if I don't have history saved to a
> file -- in fact I prefer it *not* to be.)

That's the difference between ksh's writing immediately to the history
file vs. bash's write-at-shell-exit mode.

Try adding this to /etc/ksh.kshrc:
-- snip --
function merge_hist
{
        (
                unset seperate_history
                hist -l -n |
                        sed $'s/^\t//' |
                        (unset HISTFILE ; ksh93 -c 'IFS="" ; while read -s i ; 
do printf "#
adding %s\n" "$i" ; done')
        )
        rm "${seperate_history.filename}"
}

if [[ -z "$HISTFILE" || ! -w "$HISTFILE" ]] ; then
        typeset -C seperate_history=(
filename="/tmp/.ksh_hist_${LOGNAME}.${PPID}.$$" )
        export HISTFILE="${seperate_history.filename}"
fi

trap "merge_hist seperate_history.filename" EXIT
-- snip --

This sets-up a seperate history file at interactive shell startup and
merges them back to ~/.sh_history when the shell exists.

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.mainz at nrubsig.org
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)

Reply via email to