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

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

Re: cd to the user's home dir


From: Andreas Röhler
Subject: Re: cd to the user's home dir
Date: Mon, 19 May 2014 08:07:55 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Icedove/24.5.0

On 19.05.2014 00:58, Andrey Tykhonov wrote:
Emanuel Berg <embe8573@student.uu.se> writes:

Andrey Tykhonov <atykhonov@gmail.com> writes:

I would like to be able to `cd' into the user's home
directory in the same way as I can `cd' in the shell:

cd ~admin

I try in Emacs:

M-x cd RET ~admin RET

but it doesn't work. Emacs seems doesn't provide such
functionality. Am I wrong?

`cd' changes the "default directory" of the current
buffer - e.g., so when you `find-file' in that buffer,
the prompt will by default be pointed at that
directory, as the most likely place you would want to
look.

I don't really get what you want


Well, I have many projects which paths are long and it is very often
required to `cd' to one of them. Very often and time consuming. For a shell
I resolved such an issue by means of creating system user (I'm on Linux)
and now I can just (with auto completion and quite nice representation in
the PS1):

cd ~username

where username is a system user's home directory which is the project
root. Well, `username' in my case is just a project's name.

Such thing is quite good and handy for me and I would like the same but in
Emacs, thus I want to be able to change "default directory" of the current
buffer to the user's home directory.

I just wrote these simple functions which does allow to do described thing:

(defun system-users ()
   (split-string
    (shell-command-to-string "grep -o '^[^:]*' /etc/passwd | tr '\n' ' '") " "))

(defun cu (user)
   "cd to the USER's home directory."
   (interactive
    (list
     (completing-read "User: " (system-users))))
   (setq default-directory
        (replace-regexp-in-string "\n" "" (shell-command-to-string
                                           (format "grep %s /etc/passwd | cut -f 6 
-d :" user))))
   (call-interactively 'ido-find-file))

Well, it doesn't change default-directory but just calls ido-find-file with
the user's home directory which is good.

Now I just wonder: is there any similar functionality in Emacs? Is there
any way to cd to specific user's home directory?

P.S. I'm sorry for the previous mail personally sent to you before.

- with dired, to show
the home directory's files:

(dired "~")

or perhaps:

(dired (getenv "HOME"))

- is that what you look for?



BTW at windows "expand-file-name" might be needed.

(defun cd ()
  (interactive)
  (dired (expand-file-name "~"))





reply via email to

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