From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2182 invoked by alias); 22 Jan 2013 21:41:48 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17602 Received: (qmail 28441 invoked from network); 22 Jan 2013 21:41:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: neutral (ns1.primenet.com.au: 74.125.83.51 is neither permitted nor denied by SPF record at ntlworld.com) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-proxyuser-ip:date:from:to:subject:message-id :in-reply-to:references:x-mailer:mime-version:content-type :content-transfer-encoding:x-gm-message-state; bh=PaRVYR4PCGSsHqRYVl47htTjJL1aMzbbi0fLy2L/Aac=; b=Bj3S3wBcMQTvP+3OA9qhm6VIGIDEiCgOkLi5fB7E7be5VlP8zmnM1S01gG2+MaVe0D bE8UbvsUo+WaUv+F2vurUVUMvXdepPvxV2ZsdJRrq0J1NsLJ86EMfiGX8URWTgVI4eM+ h8x0c2CHU4ILRO0FhxLFhp0LA995qRh2hyWz0sdHM7b2/1cVZHaomubCyL7XVAp/V7TO fXn5nu69IvdsvGAuLuYqx43KQPcGXtI1uw4HxXiowTPLx8j4SWIn2vc5U7OjMvhAt4Ny GnM6czLzIVXeOwZsm8yYa7LPWqC8PcXyKb0VURZvMx0MfDEmfC6wiJNfkVLArPgStDoP xtqg== X-Received: by 10.14.3.195 with SMTP id 43mr75535366eeh.36.1358883962142; Tue, 22 Jan 2013 11:46:02 -0800 (PST) X-ProxyUser-IP: 86.26.6.143 Date: Tue, 22 Jan 2013 19:45:59 +0000 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: Resolving absolute path of named directory Message-ID: <20130122194559.0d59be6e@pws-pc.ntlworld.com> In-Reply-To: References: <20130122101440.GA8372@picard.franken.de> X-Mailer: Claws Mail 3.8.0 (GTK+ 2.24.7; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQnQyk9xgAfq3TQMVQxhH/Vgpjmh4/20cBgEHlfQjsVRayqUa4cfybOz0bTGEsDxdRg8kFXa On Tue, 22 Jan 2013 11:58:44 +0100 Jesper Nyg=C3=A5rds wrote: > Thank you for your help, Thomas, but I believe my example obscured what I > am trying to do, so I will try to clarify with a better example. Consider > this zle widget that I believe I have picked up from this list: >=20 > current-argument-absolute-path() { > modify-current-argument '$ARG:a' > } > zle -N current-argument-absolute-path > bindkey '\e+' current-argument-absolute-path >=20 > As its name implies, it takes the current word on the command line, and > replaces it with its corresponding absolute path. However, it does not wo= rk > for named directories. If I write ls ~<\e+> when standing in, say, > /usr/lib, it expands the "~" to "/usr/lib/~", not "/home/jesper". And the > same for named directories that I have defined myself. So my question is, > can I rewrite this function so that if what's on the command line is a > named directory, it is expanded into its correct absolute path? And I sti= ll > want it to work for arguments that are not named directories, of course. Well, you could do something like current-argument-absolute-path() { modify-current-argument '${$(print -r -- ${~ARG}):a}' } =20 but it seems cheating, and if ARG contains special characters for globbing you're in trouble. I couldn't offhand think of a direct way of getting ~ expansion within a double-quoted expression, which is what's happening internally. Actually, the key chunk of modify-current-argument that does this, local ARG=3D"${reply[REPLY]}" repl eval repl=3D\"$1\" is a real hack that's crying out for something a bit more sophisticated. --=20 Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/