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 03:32:21 +0300 Message-ID: <87ppjaobfu.fsf@gmail.com> References: <87ha4m6a7g.fsf@debian.uxu> <87y4xyofrl.fsf@gmail.com> <20140518233147.GA20842@hysteria.proulx.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1400459577 2245 80.91.229.3 (19 May 2014 00:32:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 19 May 2014 00:32:57 +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 02:32:50 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 1WmBVY-0004uV-Sl for geh-help-gnu-emacs@m.gmane.org; Mon, 19 May 2014 02:32:49 +0200 Original-Received: from localhost ([::1]:45054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmBVY-0000zw-BN for geh-help-gnu-emacs@m.gmane.org; Sun, 18 May 2014 20:32:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51796) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmBVJ-0000zm-OY for help-gnu-emacs@gnu.org; Sun, 18 May 2014 20:32:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WmBVE-0004tA-CT for help-gnu-emacs@gnu.org; Sun, 18 May 2014 20:32:33 -0400 Original-Received: from mail-lb0-x22f.google.com ([2a00:1450:4010:c04::22f]:59269) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WmBVE-0004t5-0X for help-gnu-emacs@gnu.org; Sun, 18 May 2014 20:32:28 -0400 Original-Received: by mail-lb0-f175.google.com with SMTP id l4so3503586lbv.34 for ; Sun, 18 May 2014 17:32:26 -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=v6hl6ikVSkzjNg3I7kl8gDKpH9Vs3osH635sUl82H6k=; b=FfHiY8VZaEHSvQZHjndDTxGoRwcGNVmN8m1Kx0qgLFMLXnsp3Mov2rdUj3NYtppo5Z FzK14f/4pt7eIDSzC7v9ENXaFQg0DG/zrMSaj0WrkAac7YsNEEiU7D1Ui6w3t0F5zmiA FzIXuQtPJhqy82H3Ejc9ZZutiZp9kr3V5gm8/6Nw+WGvTvjWhKA3XXbBEEUhZEuD0nbY y8dhv4l2c3pWuiG9Rq4csRgRxhg+ToPdMFH4boBiKCxCKEr3U0lQtvpmQQ4KrOzoRlcI QT0YuuaTebZG9cWL8ue87wdjObZVn4MTUxUdeovQeIRno7JpEsVfH0MNHHnv/yVBMmmx rW0w== X-Received: by 10.112.17.102 with SMTP id n6mr22757943lbd.39.1400459546827; Sun, 18 May 2014 17:32:26 -0700 (PDT) Original-Received: from demi ([193.84.22.38]) by mx.google.com with ESMTPSA id m2sm16043743lbp.31.2014.05.18.17.32.25 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 18 May 2014 17:32:25 -0700 (PDT) In-Reply-To: <20140518233147.GA20842@hysteria.proulx.com> (Bob Proulx's message of "Sun, 18 May 2014 17:31:47 -0600") 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:c04::22f 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:97748 Archived-At: Bob Proulx 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