From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andrey Tykhonov Newsgroups: gmane.emacs.help Subject: Re: cd to the user's home dir Date: Mon, 19 May 2014 01:58:54 +0300 Message-ID: <87y4xyofrl.fsf@gmail.com> References: <87ha4m6a7g.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1400453978 1318 80.91.229.3 (18 May 2014 22:59:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 18 May 2014 22:59:38 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 19 00:59:31 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WmA3G-00045a-RM for geh-help-gnu-emacs@m.gmane.org; Mon, 19 May 2014 00:59:30 +0200 Original-Received: from localhost ([::1]:44895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmA3G-00072Y-Fg for geh-help-gnu-emacs@m.gmane.org; Sun, 18 May 2014 18:59:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmA2v-00072S-PD for help-gnu-emacs@gnu.org; Sun, 18 May 2014 18:59:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WmA2n-0002sF-Sr for help-gnu-emacs@gnu.org; Sun, 18 May 2014 18:59:09 -0400 Original-Received: from mail-la0-x22d.google.com ([2a00:1450:4010:c03::22d]:56846) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmA2n-0002s2-Ky for help-gnu-emacs@gnu.org; Sun, 18 May 2014 18:59:01 -0400 Original-Received: by mail-la0-f45.google.com with SMTP id gl10so3520058lab.32 for ; Sun, 18 May 2014 15:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:in-reply-to:references:user-agent:date:message-id :mime-version:content-type; bh=uKxaQDN6P4rXwPK1AxpiIS7Nnw+0+znqpjATe/e8djY=; b=Yn70FPO8sbeQ7gNFcvrTn0M0t7N0tP847RrhlWcz+vJVHY/12y9tBf0TkBgxqlQZ/y XbCoZtyzyca+u0MHVnzX0xQDJRyZ2kpbJC/oIx2rfH7Z7fzYcpSqAiilqNsTd+9jMxyh 84gbs+nQ9fbL9bC55qYKA604LZDL062OTPCXLMeFgDjIpMJFZliOIBG+3YJsVYh2yL7r 3krOaatbUX6eV+BvD0/KXPT8+ZnDV4uYgZtS071sNMryH/kYb9CChMD0aYTVllj7+fH3 G3XS4Q95niv9CCznSN9Qtjl4VgS2OfRpi+pd13tVD7te6nvfja8ypoT+94ljmAtM2H1F KANA== X-Received: by 10.112.50.241 with SMTP id f17mr17480494lbo.7.1400453939956; Sun, 18 May 2014 15:58:59 -0700 (PDT) Original-Received: from demi ([193.84.22.38]) by mx.google.com with ESMTPSA id eo12sm15871849lbb.13.2014.05.18.15.58.58 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 18 May 2014 15:58:59 -0700 (PDT) In-Reply-To: <87ha4m6a7g.fsf@debian.uxu> (Emanuel Berg's message of "Sun, 18 May 2014 23:36:19 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::22d X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:97745 Archived-At: 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 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?