help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Saving/Recalling Shell Commands History?


From: Kevin Rodgers
Subject: Re: Saving/Recalling Shell Commands History?
Date: Wed, 23 Aug 2006 08:20:24 -0600
User-agent: Thunderbird 1.5.0.5 (Windows/20060719)

Peter Dyballa wrote:

Am 21.08.2006 um 23:32 schrieb Kevin Rodgers:

So leave it commented out, and put this in your ~/.emacs file:

(add-hook 'shell-mode-hook
          (lambda ()
        (setq comint-input-ring-file-name ; buffer-local
          (expand-file-name "history" desktop-dirname))))

The code above works, but it only works for GNU Emacs. The shell never gets knowledge of this!

Naturally :-)

I think the meaning of comint-input-ring-file-name is to let GNU Emacs know directly, for whatever reason or use, what the shell's history file is. Maybe it's useful in dumb shells that cannot provide their own history, maybe it's useful in TRAMP, i.e. working in a remote shell.

I think it's useful, in that the Emacs history commands have access to
the history of previous (or concurrent?) shells whose commands are
persisted in that file.

It seems redundant though, that both Emacs shell-mode and the inferior
shell it's running would write the same commands to that file.

For my purpose I extended your hook to make the shell know where the actual history file of the Emacs *shell* buffer is. Since I want to separate the different Emacs versions I am using I have created an intermediate and temporary file, ~/.emacs_tcsh-init, which contains a line that tells the shell which file to use for a history. For tcsh the file ~/.emacs_tcsh is executed in *shell* buffer. So ~/.emacs_tcsh needs to be extended by one line that loads the intermediate file – and removes it!

I don't understand why it needs to be so complicated.  What do you
mean by "separate the different Emacs versions [you] are using"?  None
of your code references emacs-version, emacs-major-version, or
emacs-minor-version.

Here is my extended hook:

    (add-hook 'shell-mode-hook
          (lambda ()
        (setq comint-input-ring-file-name
          (expand-file-name "history" desktop-dirname))
        (setq histfile_cmd (format
                "echo \"set histfile = %s\" > .emacs_tcsh-init"
                comint-input-ring-file-name))
        (shell-command histfile_cmd)
    ))

~/.emacs_tcsh-init will have a line like:

    set histfile = <some path name>

The extended version of ~/.emacs_tcsh has two more lines:

    sleep 1
if (-e ~/.emacs_tcsh-init) source ~/.emacs_tcsh-init && rm ~/.emacs_tcsh-init

The sleep is needed, otherwise the file's removal fails with an error message in *shell*. One cannot feel this one more second in GNU Emacs's start-up.

Why not get rid of all that, and just put this in your .login file:

set histfile=~/tcsh_history

and this in your .emacs file:

(add-hook 'shell-mode-hook
          (lambda ()
            (let ((shell (file-name-sans-extension
                          (file-name-nondirectory (or explicit-shell-file-name
                                                      shell-file-name)))))
              (setq comint-input-ring-file-name
                    (concat "~/" shell "_history")))))

For bash the history file is addressed by the environment variable $HISTFILE. It's probably OK to use the syntax

    HISTFILE=<some path name>

HISTFILE=~/bash_history

would work with the above shell-mode-hook.

without 'export.' The syntax for the ~/.emacs_bash file would be:

if [ -e ~/.emacs_bash-init ]; then . ~/.emacs_bash-init && rm ~/.emacs_bash-init; fi

There is one more disadvantage: an empty buffer *Shell Command Output* is created because of executing (shell-command histfile_cmd) ... Could be a kill-buffer in the hook removes it!

An emtpy *Shell Command Output* buffer isn't displayed, so what's the
harm?

--
Kevin





reply via email to

[Prev in Thread] Current Thread [Next in Thread]