From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29301 invoked by alias); 22 Oct 2010 08:47:37 -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: 15471 Received: (qmail 23154 invoked from network); 22 Oct 2010 08:47:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 74.125.82.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=Cm03gIuix91KZVHPuZiyHV4pQ7lrKO0PVMwLdIq2kTY=; b=dbwsAlWiefc6NKFmsf8HZnLxw5ApHmA7lCSuXikzI4lVGBMYtjBFrzbGIIZnmdXS6s INU/MKPvrH3JZ9WssX/hSkaYIf3EPiyE4Ju5D91qGb33psEhWMMhQzNft1aE7xf68Zoh 7PTgI8GdN4yX2RCpk0I4BbOiMbHdz6xGBlQec= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=cJ6WUxp14FJ3whJBw+a4G7Fz7JshmF30m6MkCRW7c5SaDjUuCtvUsY7ma86cKGrt1O 0noJiU1O+EIUuZwWBznjZnkDUNnbamzsPwzPFp8dvcW2tF91Jw986B8c6SJZTExj9D+f 7v/241PBkmMuSDwMg11Tocd2Hz71yLeCLkSKc= MIME-Version: 1.0 In-Reply-To: References: <101021210513.ZM30802@torch.brasslantern.com> From: =?UTF-8?B?SsOpcsOpbWllIFJvcXVldA==?= Date: Fri, 22 Oct 2010 10:39:27 +0200 Message-ID: Subject: Re: Neat hash -d trick To: Zsh Users Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 2010/10/22 Mikael Magnusson : > # just type '...' to get '../..' > rationalise-dot() { > local MATCH > if [[ $LBUFFER =3D~ '(^|/| | =C2=A0 =C2=A0 =C2=A0|'$'\n''|\||;|&)\.\.$' ]= ]; then > =C2=A0LBUFFER+=3D/ > =C2=A0zle self-insert > =C2=A0zle self-insert > else > =C2=A0zle self-insert > fi > } > zle -N rationalise-dot > bindkey . rationalise-dot > # without this, typing a . aborts incremental history search > bindkey -M isearch . self-insert > > You only need the last line to avoid the problem of course. I'm using something similar, though I'll probably use your test now because the expansion isn't always appropriate :) function magic-dot() { if [[ $LBUFFER =3D *. ]]; then LBUFFER+=3D./ display-path $LBUFFER elif [[ $LBUFFER =3D *../ ]]; then LBUFFER+=3D../ display-path $LBUFFER else zle self-insert fi } zle -N magic-dot .. gives ../ so you can use completion without typing the / ... gives ../../ and so on display-path() prints the target path under the current line, so that I know where I'm going. It's a simple trick using xterm control sequences; I don't guarantee it'll work everywhere but at least it works everywhere I've tested it. function display-path() { local newpath newpath=3D`pwd`/`echo $1 | sed 's_\(.* \)\?\([^ ]\+\)$_\2_'` echo -n "\e7\n\e[40m$newpath:A\e[0m\e[0K\e8\e[B\e[A" } The only problem I've with these tricks is when pasting paths with dots in my shell, because ../../foo/bar becomes ../../../foo/bar Best regards, --=20 J=C3=A9r=C3=A9mie