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

Re: multiline ZLE w/ bash-like single line .zsh_history...?



On Dec 7, 11:46am, zsh@xxxxxxxx wrote:
}
} I tried your second zshaddhistory example to create a parallel history
} file that has the bash-format:
} 
}   zshaddhistory() {
}     fc -p ${HISTFILE}_bash_format $HISTSIZE $SAVEHIST
}     print -sr "${(z)1%%$'\n'}"
}     return 0
}   }
} 
} Unfortunately, it's not working for me...  It creates the file but
} never writes any lines to it.  Even worse, the normal history file
} ($HISTFILE) is no longer written to either.

Ah; I copied/edited the example from the zshaddhistory entry in the
manual page, but it has a small bug.  Change "fc -p" to "fc -ap".
 
} Because maintaining a parallel history file is not super-optimal to
} me, and based on inspiration from the above, I took an alternate route
} and it seems to be working for me at the moment.  It uses a little
} perl hack (sorry it's not in ZSH!):
} 
} ---------------------------------
} 
} #!/usr/bin/perl
} #
} # zsh_cook_history

This won't work if you have the extended_history option set.

Here's the same in zsh:

zsh_cook_history() {
  # Save values because fc -p will reset them
  local histfile=$HISTFILE histsize=$HISTSIZE
  # Start a new temporary history we won't save anywhere
  fc -ap
  HISTSIZE=$histsize
  SAVEHIST=0
  # Read in the file
  fc -R $histfile
  # Now print it all out again
  zmodload -i zsh/parameter
  local entry
  for entry in ${(nok)history}
  do print -r -- "${(z)history[$entry]}"
  done
}

As previously noted, (z) has a small problem with here-documents
(it converts the embedded newlines to semicolons).  I'm not sure
what your perl solution does with here-documents.  Neither the perl
version nor this version will deal well with history written with
interactivecomments ...

-- 



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