From: Glynn Clements <glynn.clements(a)virgin.net>
Date: Tue, 1 Jan 2002 06:58:53 +0000
Jeff Mincy wrote:
Just a W/A thought: bash, and maybe other shells, provide PS1,
PS2, etc codes
for "passing" various parameters to the "terminal" via escape
sequences.
Specifically, there are escapes that let me put the "\w" directory code
into the window title bar.
Could not the terminal emulator be programmed to respond to the escape sequences
by setting some variable and/or running a hook?
--
David A. Cobb, Software Engineer, Public Access Advocate.
Just to make sure that I understand, are you suggesting doing
something like this:
In bash, do
export PS1="[cd=\\w]\\s%"
Which causes the prompt to be something like:
[cd=/home/jeff/.xemacs]bash%
And then making comint strip off the [cd=...] stuff to track the
current directory, which, I think could be done by using a
comint-output-filter-function.
I had assumed that he was referring to using the xterm escape
sequence ("ESC]0;<title>BEL"), e.g.
export PS1=$(echo -e '\033]0;\\w\007[\\u@\\h \\W]\\$ ')
Ok, this might not be the most wacky idea I've heard all day...
It's the only way that directory tracking will survive stuff like:
$ ftp
foo.com
ftp> cd /pub/foo
ftp> quit
$
Well, I usually find it better to do M-x ftp, particularly since cd
in ftp is the remote directory. But your basic point that you can't
really keep up with the directory tracking is taken.
So just for amusement, I implemented what is a proof of concept hack.
I went to the bash shell, and did the following
bash% export PS1='\e]0;\w\a\s% '
This is pretty much equivalent to
export PS1=$(echo -e '\033]0;\\w\007[\\u@\\h \\W]\\$ ')
Except that I prefer a shorter prompt. Funny how I have completely
forgotten anything about term escape sequences. I reclaimed that
memory years ago.
Then I defined the following elisp hack that is copied from
comint-strip-ctrl-m.
(defun comint-strip-cd-hack (&optional string)
(interactive)
(let ((pmark (process-mark (get-buffer-process (current-buffer)))))
(save-excursion
(goto-char (if (interactive-p)
comint-last-input-end
comint-last-output-start))
(while (re-search-forward "^[\e][\]][0][;][^\a]+[\a]" pmark t)
(let ((match (match-string 0)))
(message "cd is %s" (subseq match 4 (1- (length match)))))
(replace-match "" t t)))))
(add-hook 'comint-output-filter-functions 'comint-strip-cd-hack)
The shell echoes something like
\033]0;~/.xemacs\007bash%
The comint-strip-cd-hack is run and matches the \033]0;~/.xemacs\007
and removes that out of the buffer, and prints out the message
that cd is ~/.xemacs, and leaves only 'bash% ' in the buffer.
So, this could be a useful hack, at least for comint shells that
support this type of prompt.
-jeff