all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* shell mode, changing directory
@ 2003-03-19 16:22 Phillip Lord
  2003-03-21 16:18 ` Kevin Rodgers
  2003-03-21 18:23 ` Alan Shutko
  0 siblings, 2 replies; 11+ messages in thread
From: Phillip Lord @ 2003-03-19 16:22 UTC (permalink / raw)






Can anyone tell me how to force a *shell* buffer to change it's
current working directory? Effectively I want to fake typing "cd
blah", but I can't see a good way to do this. 

Cheers

Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: shell mode, changing directory
  2003-03-19 16:22 Phillip Lord
@ 2003-03-21 16:18 ` Kevin Rodgers
  2003-03-21 17:56   ` Phillip Lord
  2003-03-21 18:23 ` Alan Shutko
  1 sibling, 1 reply; 11+ messages in thread
From: Kevin Rodgers @ 2003-03-21 16:18 UTC (permalink / raw)


Phillip Lord wrote:

> Can anyone tell me how to force a *shell* buffer to change it's
> current working directory? Effectively I want to fake typing "cd
> blah", but I can't see a good way to do this. 

M-x cd RET blah RET


-- 
<a href="mailto:&lt;kevin.rodgers&#64;ihs.com&gt;">Kevin Rodgers</a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: shell mode, changing directory
  2003-03-21 16:18 ` Kevin Rodgers
@ 2003-03-21 17:56   ` Phillip Lord
  2003-03-21 18:11     ` Barry Margolin
  2003-03-21 21:15     ` Kevin Rodgers
  0 siblings, 2 replies; 11+ messages in thread
From: Phillip Lord @ 2003-03-21 17:56 UTC (permalink / raw)


>>>>> "Kevin" == Kevin Rodgers <kevin.rodgers@ihs.com> writes:

  Kevin> Phillip Lord wrote:

  >> Can anyone tell me how to force a *shell* buffer to change it's
  >> current working directory? Effectively I want to fake typing "cd
  >> blah", but I can't see a good way to do this.


  Kevin> M-x cd RET blah RET



This appears to change the default directory of the buffer, not the
current working directory of the shell, which is not really what I
want. Both need to happen. 

Cheers

Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: shell mode, changing directory
  2003-03-21 17:56   ` Phillip Lord
@ 2003-03-21 18:11     ` Barry Margolin
  2003-03-21 21:15     ` Kevin Rodgers
  1 sibling, 0 replies; 11+ messages in thread
From: Barry Margolin @ 2003-03-21 18:11 UTC (permalink / raw)


In article <vffzpgbo3b.fsf@rpc71.cs.man.ac.uk>,
Phillip Lord  <p.lord@russet.org.uk> wrote:
>>>>>> "Kevin" == Kevin Rodgers <kevin.rodgers@ihs.com> writes:
>
>  Kevin> Phillip Lord wrote:
>
>  >> Can anyone tell me how to force a *shell* buffer to change it's
>  >> current working directory? Effectively I want to fake typing "cd
>  >> blah", but I can't see a good way to do this.
>
>
>  Kevin> M-x cd RET blah RET
>
>This appears to change the default directory of the buffer, not the
>current working directory of the shell, which is not really what I
>want. Both need to happen. 

Unix doesn't provide any way for one process to change the working
directory of another one.

I suppose you could write a command that will send a "cd <wherever>"
command to the shell buffer with process-send-string.

-- 
Barry Margolin, barry.margolin@level3.com
Genuity Managed Services, Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: shell mode, changing directory
  2003-03-19 16:22 Phillip Lord
  2003-03-21 16:18 ` Kevin Rodgers
@ 2003-03-21 18:23 ` Alan Shutko
  1 sibling, 0 replies; 11+ messages in thread
From: Alan Shutko @ 2003-03-21 18:23 UTC (permalink / raw)


Phillip Lord <p.lord@russet.org.uk> writes:

> Can anyone tell me how to force a *shell* buffer to change it's
> current working directory? Effectively I want to fake typing "cd
> blah", but I can't see a good way to do this. 

Send "cd blah" to the process... that's the only way.  You can't
change a process's working directory from outside.

comint-send-string might help.

-- 
Alan Shutko <ats@acm.org> - I am the rocks.
Looking for a developer in St. Louis? http://web.springies.com/~ats/
Hey! You knuckleheads! - Gypsy to Mads

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: shell mode, changing directory
@ 2003-03-21 18:40 Bingham, Jay
  0 siblings, 0 replies; 11+ messages in thread
From: Bingham, Jay @ 2003-03-21 18:40 UTC (permalink / raw)


On Friday, March 21, 2003 12:23 PM Alan Shutko wrote:

>Phillip Lord <p.lord@russet.org.uk> writes:
>
>> Can anyone tell me how to force a *shell* buffer to change it's
>> current working directory? Effectively I want to fake typing "cd
>> blah", but I can't see a good way to do this. 
>
>Send "cd blah" to the process... that's the only way.  You can't
>change a process's working directory from outside.
>
>comint-send-string might help.

There is something that is missing from this discussion.  Phillip and I
had a brief offline conversation about what he is trying to do, I
suggested that he repost the message that he sent directly to me, but
for some reason he has not done that.

Here is what he sent to me:

>I want to change the directory progammatically. The reason is that I
use
>several directories repeatedly, and navigating between them takes ages.
I
>want to store them in a list that I can access easily and then have the
>shell buffer move to that directory.
>
>Specifically I want to write two commands. The first is "move CWD of
shell
>to the same as the file of the current buffer" (currently you can
achieve
>this, by killing the *shell* buffer, and typing M-x shell). And
secondly I
>want to be able to use the ECB's
>(ecb.sourceforge.net) directory window, to move shells CWD. 
>
>Having "cd blah" turn up at the command prompt within the *shell*
buffer
>would be perfectly acceptable to me, and even useful, as it would leave
the
>user with feedback.

I hope that this helps clarify his needs.

-_
J_)
C_)ingham
.    HP - NonStop Austin Software & Services - Software Quality
Assurance
.    Austin, TX
. "Language is the apparel in which your thoughts parade in public.
.  Never clothe them in vulgar and shoddy attire."     -Dr. George W.
Crane-

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: shell mode, changing directory
       [not found] <mailman.3489.1048272184.21513.help-gnu-emacs@gnu.org>
@ 2003-03-21 19:53 ` Alan Shutko
  2003-03-22  9:42 ` Piet van Oostrum
  1 sibling, 0 replies; 11+ messages in thread
From: Alan Shutko @ 2003-03-21 19:53 UTC (permalink / raw)


>>Specifically I want to write two commands. The first is "move CWD of
>>shell to the same as the file of the current buffer" (currently you
>>can achieve this, by killing the *shell* buffer, and typing M-x
>>shell).

Here's a sample for this request.  It shouldn't be too hard to
generalize this.

(defun change-shell-wd-to-current ()
  "Change the directory of the *shell* buffer to the current directory"
  (interactive)
  (save-excursion
    (let ((command (concat "cd " default-directory))
	  (process (get-buffer-process "*shell*")))
      (set-buffer "*shell*")
      (goto-char (point-max))
      (insert command)
      (comint-send-input))))

-- 
Alan Shutko <ats@acm.org> - I am the rocks.
Looking for a developer in St. Louis? http://web.springies.com/~ats/
"Why should I stop just because I've had more than enough?" Draco F.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: shell mode, changing directory
  2003-03-21 17:56   ` Phillip Lord
  2003-03-21 18:11     ` Barry Margolin
@ 2003-03-21 21:15     ` Kevin Rodgers
  2003-03-24 12:40       ` Phillip Lord
  1 sibling, 1 reply; 11+ messages in thread
From: Kevin Rodgers @ 2003-03-21 21:15 UTC (permalink / raw)


Phillip Lord wrote:

>>>>>>"Kevin" == Kevin Rodgers <kevin.rodgers@ihs.com> writes:
>>>>>>
> 
>   Kevin> Phillip Lord wrote:
> 
>   >> Can anyone tell me how to force a *shell* buffer to change it's
>   >> current working directory? Effectively I want to fake typing "cd
>   >> blah", but I can't see a good way to do this.
> 
>   Kevin> M-x cd RET blah RET
> 
> 
> This appears to change the default directory of the buffer, not the
> current working directory of the shell, which is not really what I
> want. 

Sorry, that's just what you asked for.


 > Both need to happen.

Then do what comint-send-input (which is what RET is bound to in the *shell*
buffer) does:

(funcall comint-input-sender
	 (get-buffer-process (current-buffer))
	 (format "cd %s" DIRECTORY))

-- 
<a href="mailto:&lt;kevin.rodgers&#64;ihs.com&gt;">Kevin Rodgers</a>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: shell mode, changing directory
       [not found] <mailman.3489.1048272184.21513.help-gnu-emacs@gnu.org>
  2003-03-21 19:53 ` shell mode, changing directory Alan Shutko
@ 2003-03-22  9:42 ` Piet van Oostrum
  2003-03-24 16:21   ` Phillip Lord
  1 sibling, 1 reply; 11+ messages in thread
From: Piet van Oostrum @ 2003-03-22  9:42 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 869 bytes --]

>>>>> "Bingham, Jay" <Jay.Bingham@hp.com> (BJ) wrote:

BJ> On Friday, March 21, 2003 12:23 PM Alan Shutko wrote:
>> Phillip Lord <p.lord@russet.org.uk> writes:

>> Specifically I want to write two commands. The first is "move CWD of shell
>> to the same as the file of the current buffer" (currently you can achieve
>> this, by killing the *shell* buffer, and typing M-x shell). And secondly I
>> want to be able to use the ECB's
>> (ecb.sourceforge.net) directory window, to move shells CWD. 

[snip]

BJ> I hope that this helps clarify his needs.

I use myself a slightly different approach, which in fact might even be
more confortable:
I have a command that starts a shell in the current directory which
encodes the directory name in the buffer name. If there is already a shell
running in the current directory it uses that buffer rather than starting
a new one.


[-- Attachment #2: sh.el --]
[-- Type: application/emacs-lisp, Size: 855 bytes --]

[-- Attachment #3: Type: text/plain, Size: 114 bytes --]


-- 
Piet van Oostrum <piet@cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: P.van.Oostrum@hccnet.nl

[-- Attachment #4: Type: text/plain, Size: 151 bytes --]

_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://mail.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: shell mode, changing directory
  2003-03-21 21:15     ` Kevin Rodgers
@ 2003-03-24 12:40       ` Phillip Lord
  0 siblings, 0 replies; 11+ messages in thread
From: Phillip Lord @ 2003-03-24 12:40 UTC (permalink / raw)



>>>>> "Kevin" == Kevin Rodgers <kevin.rodgers@ihs.com> writes:

  >> This appears to change the default directory of the buffer, not
  >> the

  >> current working directory of the shell, which is not really what
  >> I want.


  Kevin> Sorry, that's just what you asked for.

I was a little unclear about what I wanted, I agree. 

  >> Both need to happen.

  Kevin> Then do what comint-send-input (which is what RET is bound to
  Kevin> in the *shell* buffer) does:

  Kevin> (funcall comint-input-sender
  Kevin> 	 (get-buffer-process (current-buffer)) (format "cd %s"
  Kevin> 	 DIRECTORY))

Okay, yes, this works.....

 (process-send-string 
   (get-buffer-process 
    (current-buffer)) "cd ~\n")
  (cd "~")
  (insert-string "cd ~\n" ))


which changes the current working directory of the shell, the buffer,
and tells the user what has happened. 

Cheers

Phil

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: shell mode, changing directory
  2003-03-22  9:42 ` Piet van Oostrum
@ 2003-03-24 16:21   ` Phillip Lord
  0 siblings, 0 replies; 11+ messages in thread
From: Phillip Lord @ 2003-03-24 16:21 UTC (permalink / raw)


>>>>> "Piet" == Piet van Oostrum <piet@cs.uu.nl> writes:

>>>>> "Bingham, Jay" <Jay.Bingham@hp.com> (BJ) wrote:

  BJ> On Friday, March 21, 2003 12:23 PM Alan Shutko wrote:
  >>> Phillip Lord <p.lord@russet.org.uk> writes:

  >>> Specifically I want to write two commands. The first is "move
  >>> CWD of shell to the same as the file of the current buffer"
  >>> (currently you can achieve this, by killing the *shell* buffer,
  >>> and typing M-x shell). And secondly I want to be able to use the
  >>> ECB's (ecb.sourceforge.net) directory window, to move shells
  >>> CWD.

  Piet> [snip]

  BJ> I hope that this helps clarify his needs.

  Piet> I use myself a slightly different approach, which in fact
  Piet> might even be more confortable: I have a command that starts a
  Piet> shell in the current directory which encodes the directory
  Piet> name in the buffer name. If there is already a shell running
  Piet> in the current directory it uses that buffer rather than
  Piet> starting a new one.

*Stuff snipped*

Hmmm. I'm not sure. This might actually be more convenient that my
approach, although, its liable to result in a lot of shell buffers
open. I am not sure which is better. I normally only use a single
shell buffer, although this is generally so I can find it (with M-x
shell, or C-xC-b) quickly. This is why I always wanted a *shell*
buffer which I can use manually. 

Possible the solution is a bit of both. If I am navigating around a
Java source hierarchy, then probably I would want the single shell
approach, as generally you want a single shell window, with a single
shared history (full of "ant test" commands!). But if I am using
several directories with different things in (latex document in one,
java source in another, and various application launchers in a
third!), I'd probably want your approach. 

Anyway I put my cheesy and inadequate approach up on the board for
informational purposes. Maybe we should work this up into a more
general "select a shell with a specific directory" kind of package,
with in true emacs fashion, a vast and bewildering array of different
options. 

Cheers

Phil

ps sorry about the terrible "phil-" prefix, but I find it hard to come
up with non clashing, and yet still meaningful prefixes for all my
little fixes, and fiddles)


(global-set-key "\C-cd" 'phil-show-shift-shell-to-current-dir)

(defun phil-show-shift-shell-to-current-dir()
  (interactive)
  (phil-shift-shell-to-current-dir)
  (other-window 1)
  (switch-to-buffer "*shell*"))

(defun phil-shift-shell-to-current-dir()
  (interactive)
  (let ((file-name(buffer-file-name
                   (current-buffer))))
    (if (not file-name)
        (error "Current buffer is not associated with a file"))
    (phil-shift-shell-to-directory
     (file-name-directory file-name))))

(defun phil-shift-shell-to-directory(directory)
  (let* ((poss-shell (get-buffer "*shell*"))
        (shell-buffer
         (if poss-shell
             poss-shell
           (shell)))
        (shell-process 
         (get-buffer-process shell-buffer))
        (directory-string (concat "cd " directory "\n")))
    (save-excursion
      (set-buffer shell-buffer)
      (process-send-string 
       shell-process directory-string)
      (cd directory)
      (process-send-string 
       shell-process "pwd\n"))))

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-03-24 16:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.3489.1048272184.21513.help-gnu-emacs@gnu.org>
2003-03-21 19:53 ` shell mode, changing directory Alan Shutko
2003-03-22  9:42 ` Piet van Oostrum
2003-03-24 16:21   ` Phillip Lord
2003-03-21 18:40 Bingham, Jay
  -- strict thread matches above, loose matches on Subject: below --
2003-03-19 16:22 Phillip Lord
2003-03-21 16:18 ` Kevin Rodgers
2003-03-21 17:56   ` Phillip Lord
2003-03-21 18:11     ` Barry Margolin
2003-03-21 21:15     ` Kevin Rodgers
2003-03-24 12:40       ` Phillip Lord
2003-03-21 18:23 ` Alan Shutko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.