unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: Saving/Recalling Shell Commands History?
Date: Wed, 23 Aug 2006 08:20:24 -0600	[thread overview]
Message-ID: <echo8a$vnh$1@sea.gmane.org> (raw)
In-Reply-To: <85A5A4F0-4577-4C65-B855-C776F96FA6E3@web.DE>

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	other threads:[~2006-08-23 14:20 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-21 15:07 Saving/Recalling Shell Commands History? gamename
2006-08-21 16:35 ` Drew Adams
2006-08-21 20:09 ` Peter Dyballa
2006-08-21 20:17   ` Drew Adams
2006-08-21 21:08     ` Peter Dyballa
2006-08-21 21:30       ` Drew Adams
2006-08-21 21:32       ` Kevin Rodgers
2006-08-21 22:14         ` Peter Dyballa
2006-08-22 23:13         ` Peter Dyballa
2006-08-23 14:20           ` Kevin Rodgers [this message]
2006-08-23 15:20             ` Peter Dyballa
2006-08-21 20:19 ` Jesse Alama
2006-08-21 21:11   ` Peter Dyballa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='echo8a$vnh$1@sea.gmane.org' \
    --to=ihs_4664@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).