<div dir="ltr">Maybe tmux or screen could be of use.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Jan 5, 2014 at 8:50 PM, Mike Miller <span dir="ltr"><<a href="mailto:mbmiller+l@gmail.com" target="_blank">mbmiller+l@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Sun, 5 Jan 2014, Erik Anderson wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm curious to hear about *why* you are separating your HISTFILEs, though. My guess is that you have a set of different ssh session "types", and you want to be able to isolate history entries for each function. Is that correct?<br>

</blockquote>
<br>
<br></div>
I'll have maybe 10 connections open to the server at once and each of them will be for my work on some project.  So every connection is of its own type -- there is no sort of classification scheme, if that's what you were asking.<br>

<br>
Every time the command prompt returns, it writes the previous command to the HISTFILE:<br>
<br>
export PROMPT_COMMAND='history -a'<br>
<br>
So I have to use separate HISTFILEs or else the commands from different projects will be interlaced.  If I don't write every command immediately to a histfile, when the sessions are killed by power failure or network outage, I'll lose all the command histories.<br>

<br>
I have ways to work around the tty issue using history commands, copying files, etc.  But I can also get the tty I want, if it is unused, by occupying the lower /dev/pts/ numbers.<br>
<br>
This is working great for me, and I would recommend it strongly to others. I'm sharing the relevant lines from my .bashrc below.  It would be great if anyone has anything to add or to correct.  Thanks.<br>
<br>
Mike<br>
<br>
<br>
<br>
# Use multi_history?  Change to "yes" if you will often have multiple<br>
# interactive bash shells running simultaneously on this system.  This<br>
# will cause you to save multiple history files, one per shell -- see<br>
# HISTFILE info below.<br>
multi_history=yes<br>
<br>
<br>
##############################<u></u>################<br>
#<br>
# HISTORY settings<br>
#<br>
##############################<u></u>################<br>
<br>
# append to the history file on exit, don't overwrite it<br>
shopt -s histappend<br>
<br>
<br>
# If $multi_history=yes, then tty is used to create a different<br>
# $HISTFILE for every tty.  This will be a big advantage for people<br>
# who have multiple interactive bash shells running simultaneously.<br>
# It is not recommended for people who only run one at a time.<br>
<br>
# if requested, add the tty to the name of the history file<br>
if [ "$multi_history" = "yes" ]; then<div class="im"><br>
   export HISTFILE=~/.bash_history$(tty | sed 's|/|_|g')<br></div>
   if [ ! -s $HISTFILE ] ; then<br>
      if [ -s ~/.bash_history_init ] ; then<br>
         cp -fp ~/.bash_history_init $HISTFILE<br>
      else<br>
         echo -e "#1\ncd" >> ~/.bash_history_init<br>
         chmod 600 ~/.bash_history_init<br>
         cp -fp ~/.bash_history_init $HISTFILE<br>
      fi<br>
   fi<br>
fi<br>
<br>
# immediately write every new command to the history file<br>
export PROMPT_COMMAND='history -a'<br>
<br>
# don't put duplicate lines in the history nor lines beginning with a space<br>
export HISTCONTROL=ignoreboth<br>
<br>
# For setting history length see HISTSIZE and HISTFILESIZE in bash(1)<br>
# Save 10,000 lines of history but 100,000 lines in the history file:<br>
export HISTSIZE=10000<br>
export HISTFILESIZE=100000<br>
<br>
# commands to ignore and not add to history (recommendation: do not<br>
# add "cd" to this list because doing so makes it hard to track the<br>
# default directory where commands were executed)<br>
HISTIGNORE='ls:laf:jobs:bg:fg'<br>
<br>
# set time format for history file display<br>
# in saved file, it uses seconds since 1/1/1970, but those can be converted<br>
# for viewing using this command (where 1234567890 is the date in seconds):<br>
# date +"%F %T" -d @1234567890<br>
export HISTTIMEFORMAT="%F %T%t"<br>
<br>
<br>
<br>
##############################<u></u>################<br>
#<br>
# Prompt settings<br>
#<br>
##############################<u></u>################<br>
<br>
# somone wrote, "color prompt is turned off by default to not distract<br>
# the user: the focus in a terminal window should be on the output of<br>
# commands, not on the prompt"<br>
# Mike Miller disagrees -- when looking at the scrollback in the<br>
# command window, the focus often is on the prompt because the prompt<br>
# shows where the commands are.<br>
force_color_prompt=yes<br>
<br>
if [ -n "$force_color_prompt" ]; then<br>
   if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then<br>
      # We have color support; assume it's compliant with Ecma-48<br>
      # (ISO/IEC-6429). (Lack of such support is extremely rare, and such<br>
      # a case would tend to support setf rather than setaf.)<br>
      color_prompt=yes<br>
   else<br>
      color_prompt=no<br>
   fi<br>
fi<br>
<br>
if [ "$color_prompt" = yes ]; then<br>
   if [ "$multi_history" = "yes" ]; then<br>
      # add tty info to prompt for multi_history<br>
      PS1="\[\e]0;\u@\h : $(tty) : \w\a\]\n\[\e[32m\]\u@\h\[\e[<u></u>34m\]:\[\e[36m\]$(tty) \[\e[33m\]\w\[\e[0m\]\n\$ "<br>
   else<br>
      PS1='\[\e]0;\u@\h: \w\a\]\n\[\e[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ '<br>
   fi<br>
else<br>
   if [ "$multi_history" = "yes" ]; then<br>
      # add tty info to prompt for multi_history<br>
      PS1='\n\u@\h $(tty) \w\n\$ '<br>
   else<br>
      PS1='\n\u@\h \w\n\$ '<br>
   fi<br>
fi<br>
unset color_prompt force_color_prompt<div class="HOEnZb"><div class="h5"><br>
______________________________<u></u>_________________<br>
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota<br>
<a href="mailto:tclug-list@mn-linux.org" target="_blank">tclug-list@mn-linux.org</a><br>
<a href="http://mailman.mn-linux.org/mailman/listinfo/tclug-list" target="_blank">http://mailman.mn-linux.org/<u></u>mailman/listinfo/tclug-list</a><br>
</div></div></blockquote></div><br></div>