1

I use zsh with the EXTENDED_HISTORY option, which makes it so that in the shell history timestamps are stored which is useful for going back and diagnosing how you screwed up production. I'm trying to transition to using emacs for my terminal with shell-mode, but when I try to browse my previous commands they come up like this:

: 1423012245:0;ls

The first number is the timestamp, and the second number is the number of seconds the command took. This is exactly how the command looks in the history file too, but zsh is smart enough to filter it out when you press up to browse your previous commands in the real shell. So it appears that comint mode tries to read the history file separately, and doesn't know about the timestamp format.

How do I get shell-mode to ignore the timestamps while keeping the option on?

  • Something is abnormal. I use shell mode with EXTENDED_HISTORY, and it works fine for me. Try using emacs -Q and zsh -f (will need to setup the history manually) and see if there's still a problem. – PythonNut Feb 4 '15 at 5:32
  • Also, I would highly recommend ansi-term. It's superior to shell in many regards. – PythonNut Feb 4 '15 at 5:37
  • Tried it, it happens for me even with "emacs -Q" running a "zsh" shell where I've moved zshrc out of the way (I couldn't use -f because I could figure out a way to get emacs to pass it to zsh). To be clear, you are not seeing it when using shell-mode and if you type "setopt" extendedhistory appears in the list? And if you manually inspect ~/.zhistory you see the timestamps are present? – Joseph Garvin Feb 4 '15 at 15:46
  • I tried ansi-term but dropped it. I'm making a speech recognition mode for emacs, and want it to work with a terminal mode, and making all the code I've written so far work smoothly with ansi-term would be complicated because of it changing all the keybindings, read-only protection not working right out of the box for elisp functions editing the buffer, and generally the shell getting confused about actions taken by elisp funcs not specifically written with char mode in mind. Shell-mode just worked, so shell-mode it is until I have a chance to dig deeper. – Joseph Garvin Feb 4 '15 at 15:48
  • @PythonNut: I notice if I run zsh without extendedhistory on in a real terminal and go through my old history it exhibits the same behavior that emacs does. So my thinking is that at shell startup emacs asks zsh for the history, and zsh (because the option isn't right away) is giving the corrupt history to it (the emacs documentation seems to indicate that emacs uses the shell history to initialize its own separate copy). Where do you set extendedhistory? Maybe you set it in a file loaded earlier than .zshrc? – Joseph Garvin Feb 4 '15 at 16:07
2

Setting comint-input-ring-separator so that the whole timestamp is treated as part of the command separator worked for me. For example:

; Remember lots of previous commands in shell-mode
(setq comint-input-ring-size 100000)
(add-hook 'shell-mode-hook 'my-shell-mode-hook)
(defun my-shell-mode-hook ()
  (setq comint-input-ring-file-name "~/.zsh_history")
  ; Ignore timestamps in history file.  Assumes that zsh
  ; EXTENDED_HISTORY option is in use.
  (setq comint-input-ring-separator "\n: \\([0-9]+\\):\\([0-9]+\\);")
  (comint-read-input-ring t))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.