* cd to the user's home dir
@ 2014-05-18 21:11 Andrey Tykhonov
0 siblings, 0 replies; 12+ messages in thread
From: Andrey Tykhonov @ 2014-05-18 21:11 UTC (permalink / raw)
To: help-gnu-emacs
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?
Andrey
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: cd to the user's home dir
[not found] <mailman.1577.1400447529.1147.help-gnu-emacs@gnu.org>
@ 2014-05-18 21:36 ` Emanuel Berg
[not found] ` <87bnuupxib.fsf@gmail.com>
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Emanuel Berg @ 2014-05-18 21:36 UTC (permalink / raw)
To: help-gnu-emacs
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 - with dired, to show
the home directory's files:
(dired "~")
or perhaps:
(dired (getenv "HOME"))
- is that what you look for?
--
underground experts united:
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: cd to the user's home dir
[not found] ` <87bnuupxib.fsf@gmail.com>
@ 2014-05-18 21:56 ` Emanuel Berg
0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2014-05-18 21:56 UTC (permalink / raw)
To: help-gnu-emacs
Andrey Tykhonov <atykhonov@gmail.com> writes:
> I want to be able to change the "default directory"
> of the current buffer to the specific user's home
> directory.
Yeah, so then use (cd DIR) and replace DIR with "the
specific user's home directory"?
PS. Send replies to gnu.emacs.help, not my mail. DS.
--
underground experts united:
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: cd to the user's home dir
2014-05-18 21:36 ` cd to the user's home dir Emanuel Berg
[not found] ` <87bnuupxib.fsf@gmail.com>
@ 2014-05-18 22:58 ` Andrey Tykhonov
2014-05-18 23:31 ` Bob Proulx
2014-05-19 6:07 ` Andreas Röhler
[not found] ` <mailman.1584.1400453956.1147.help-gnu-emacs@gnu.org>
2 siblings, 2 replies; 12+ messages in thread
From: Andrey Tykhonov @ 2014-05-18 22:58 UTC (permalink / raw)
To: help-gnu-emacs
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?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: cd to the user's home dir
[not found] ` <mailman.1584.1400453956.1147.help-gnu-emacs@gnu.org>
@ 2014-05-18 23:12 ` Emanuel Berg
0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2014-05-18 23:12 UTC (permalink / raw)
To: help-gnu-emacs
Andrey Tykhonov <atykhonov@gmail.com> writes:
> Now I just wonder: is there any similar functionality
> in Emacs? Is there any way to cd to specific user's
> home directory?
Well, again - use cd. Or, if you like, put it in a
defun that accepts a username, use that username to
find out the home dir of that user, put it as the
argument to cd. Especially if you know Elisp I can't cd
- I mean see - the problem?
I don't know if there is a standard way of doing it or
if someone else did it before. But it should be so easy
to do so just do it and don't doubt yourself.
> P.S. I'm sorry for the previous mail personally sent
> to you before.
Ha ha, no problem.
--
underground experts united:
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: cd to the user's home dir
2014-05-18 22:58 ` Andrey Tykhonov
@ 2014-05-18 23:31 ` Bob Proulx
2014-05-19 0:32 ` Andrey Tykhonov
2014-05-19 6:07 ` Andreas Röhler
1 sibling, 1 reply; 12+ messages in thread
From: Bob Proulx @ 2014-05-18 23:31 UTC (permalink / raw)
To: help-gnu-emacs
Andrey Tykhonov wrote:
> Emanuel Berg writes:
> > Andrey Tykhonov 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
I don't think I understand either. Because the above works fine for
me. If you use the emacs interactive cd function it will prompt in
the minibuffer with this:
Change default directory: ~/
If I type in ~someuser/somepath that is expanded appropriately and
everything works fine. When you say it does not work for you what is
it about it that does not work?
> 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.
That is fine. But instead of creating a full user account in the
system it would be more typical to create variables and cd there. Or
to create aliases. In the shell, there is even variable name completion:
cd $somelocation
> 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
Look into using the (expand-file-name) function. Use it like this:
(expand-file-name "~/emacs")
It returns the expanded file name. That would be a lot more portable
and easier to use than your brute force grep of the /etc/passwd file.
(Which is fine too but won't catch users in NIS/yp or LDAP or other
type of account database.
> Now I just wonder: is there any similar functionality in Emacs? Is there
> any way to cd to specific user's home directory?
Of course this is where I get a confused look on my face and say, yes,
simply use the emacs 'cd' function.
cd is an interactive compiled Lisp function in `files.el'.
(cd DIR)
Make DIR become the current buffer's default directory.
If your environment includes a `CDPATH' variable, try each one of
that list of directories (separated by occurrences of
`path-separator') when resolving a relative directory name.
The path separator is colon in GNU and GNU-like systems.
Bob
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: cd to the user's home dir
2014-05-18 23:31 ` Bob Proulx
@ 2014-05-19 0:32 ` Andrey Tykhonov
2014-05-19 0:54 ` Drew Adams
2014-05-19 1:02 ` Bob Proulx
0 siblings, 2 replies; 12+ messages in thread
From: Andrey Tykhonov @ 2014-05-19 0:32 UTC (permalink / raw)
To: help-gnu-emacs
Bob Proulx <bob@proulx.com> writes:
> Andrey Tykhonov wrote:
>> Emanuel Berg writes:
>> > Andrey Tykhonov 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
>
> I don't think I understand either. Because the above works fine for
> me. If you use the emacs interactive cd function it will prompt in
> the minibuffer with this:
>
> Change default directory: ~/
>
> If I type in ~someuser/somepath that is expanded appropriately and
> everything works fine.
Oh, I'm sorry! I just tried ~someuser/ and it does really works! Before
I've tried just ~som and hit TAB after that. I expected appropriate
completion but didn't get it and decided that that doesn't work at all,
also I tried cd ~someuser RET (without ending slash)...
Does completion work for you if you type ~someu TAB ?
> When you say it does not work for you what is
> it about it that does not work?
>
>> 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.
>
> That is fine. But instead of creating a full user account in the
> system it would be more typical to create variables and cd there. Or
> to create aliases. In the shell, there is even variable name completion:
>
> cd $somelocation
>
>> 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
>
> Look into using the (expand-file-name) function. Use it like this:
>
> (expand-file-name "~/emacs")
>
> It returns the expanded file name. That would be a lot more portable
> and easier to use than your brute force grep of the /etc/passwd file.
> (Which is fine too but won't catch users in NIS/yp or LDAP or other
> type of account database.
>
>> Now I just wonder: is there any similar functionality in Emacs? Is there
>> any way to cd to specific user's home directory?
>
> Of course this is where I get a confused look on my face and say, yes,
> simply use the emacs 'cd' function.
>
> cd is an interactive compiled Lisp function in `files.el'.
>
> (cd DIR)
>
> Make DIR become the current buffer's default directory.
> If your environment includes a `CDPATH' variable, try each one of
> that list of directories (separated by occurrences of
> `path-separator') when resolving a relative directory name.
> The path separator is colon in GNU and GNU-like systems.
>
> Bob
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: cd to the user's home dir
2014-05-19 0:32 ` Andrey Tykhonov
@ 2014-05-19 0:54 ` Drew Adams
2014-05-19 1:02 ` Bob Proulx
1 sibling, 0 replies; 12+ messages in thread
From: Drew Adams @ 2014-05-19 0:54 UTC (permalink / raw)
To: Andrey Tykhonov, help-gnu-emacs
> Oh, I'm sorry! I just tried ~someuser/ and it does really works! Before
> I've tried just ~som and hit TAB after that. I expected appropriate
> completion but didn't get it and decided that that doesn't work at all,
> also I tried cd ~someuser RET (without ending slash)...
>
> Does completion work for you if you type ~someu TAB ?
Yes, for me it does, on MS Windows, with Emacs 24.3 or 24.4, but
not with prior releases (e.g. 24.2).
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: cd to the user's home dir
2014-05-19 0:32 ` Andrey Tykhonov
2014-05-19 0:54 ` Drew Adams
@ 2014-05-19 1:02 ` Bob Proulx
2014-05-19 1:27 ` Drew Adams
1 sibling, 1 reply; 12+ messages in thread
From: Bob Proulx @ 2014-05-19 1:02 UTC (permalink / raw)
To: help-gnu-emacs
Andrey Tykhonov wrote:
> Bob Proulx writes:
> > Change default directory: ~/
> >
> > If I type in ~someuser/somepath that is expanded appropriately and
> > everything works fine.
>
> Oh, I'm sorry! I just tried ~someuser/ and it does really works! Before
> I've tried just ~som and hit TAB after that. I expected appropriate
> completion but didn't get it and decided that that doesn't work at all,
> also I tried cd ~someuser RET (without ending slash)...
>
> Does completion work for you if you type ~someu TAB ?
Yes. Name completion with TAB works for me. I am running on a Debian
system.
But playing with it I find that it doesn't work exactly the same as
find-file completion. If I have "~/" and I try "~/~rooTAB" it will
not complete to ~root/. I must backup first. "~rooTAB" works. This
is slightly different than find-file. In find-file a slash or tilde
immediately starts a new path. In the graphical client it greys out
the preceding path. I think cd is enough different from find-file
that it would classify as a bug against cd because of the
inconsistency.
Bob
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: cd to the user's home dir
2014-05-19 1:02 ` Bob Proulx
@ 2014-05-19 1:27 ` Drew Adams
0 siblings, 0 replies; 12+ messages in thread
From: Drew Adams @ 2014-05-19 1:27 UTC (permalink / raw)
To: Bob Proulx, help-gnu-emacs
> But playing with it I find that it doesn't work exactly the same as
> find-file completion. If I have "~/" and I try "~/~rooTAB" it will
> not complete to ~root/. I must backup first. "~rooTAB" works. This
> is slightly different than find-file. In find-file a slash or tilde
> immediately starts a new path. In the graphical client it greys out
> the preceding path. I think cd is enough different from find-file
> that it would classify as a bug against cd because of the
> inconsistency.
Emacs command `cd' tries to act like UNIX/Linux command `cd'.
In particular, it uses environment var `CDPATH' to look things up.
The `find-file' (and related commands) behavior you refer to
is something different. What it does is recognize `~/' as your
home directory (env var `HOME'). And it does so also when it
comes immediately after a slash (`/`) - Emacs then ignores that
slash and whatever precedes it. (And in recent Emacs versions
it dims that ignored text.)
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: cd to the user's home dir
2014-05-18 22:58 ` Andrey Tykhonov
2014-05-18 23:31 ` Bob Proulx
@ 2014-05-19 6:07 ` Andreas Röhler
2014-05-19 14:50 ` Eli Zaretskii
1 sibling, 1 reply; 12+ messages in thread
From: Andreas Röhler @ 2014-05-19 6:07 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org List
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 "~"))
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: cd to the user's home dir
2014-05-19 6:07 ` Andreas Röhler
@ 2014-05-19 14:50 ` Eli Zaretskii
0 siblings, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2014-05-19 14:50 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Mon, 19 May 2014 08:07:55 +0200
> From: Andreas Röhler <andreas.roehler@easy-emacs.de>
>
> BTW at windows "expand-file-name" might be needed.
>
> (defun cd ()
> (interactive)
> (dired (expand-file-name "~"))
No, it isn't. Emacs always calls expand-file-name internally before
passing any file names to C file-related interfaces.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2014-05-19 14:50 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.1577.1400447529.1147.help-gnu-emacs@gnu.org>
2014-05-18 21:36 ` cd to the user's home dir Emanuel Berg
[not found] ` <87bnuupxib.fsf@gmail.com>
2014-05-18 21:56 ` Emanuel Berg
2014-05-18 22:58 ` Andrey Tykhonov
2014-05-18 23:31 ` Bob Proulx
2014-05-19 0:32 ` Andrey Tykhonov
2014-05-19 0:54 ` Drew Adams
2014-05-19 1:02 ` Bob Proulx
2014-05-19 1:27 ` Drew Adams
2014-05-19 6:07 ` Andreas Röhler
2014-05-19 14:50 ` Eli Zaretskii
[not found] ` <mailman.1584.1400453956.1147.help-gnu-emacs@gnu.org>
2014-05-18 23:12 ` Emanuel Berg
2014-05-18 21:11 Andrey Tykhonov
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.