From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2742 invoked by alias); 20 Apr 2011 19:14:21 -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: 15976 Received: (qmail 20912 invoked from network); 20 Apr 2011 19:14:19 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at np.by designates 91.149.189.205 as permitted sender) From: ZyX Reply-To: zyx@np.by To: John Eikenberry , zsh-users@zsh.org Subject: Re: Suffix alias for README files Date: Wed, 20 Apr 2011 22:40:22 +0400 User-Agent: KMail/1.13.5 (Linux/2.6.36-zen1; KDE/4.6.2; x86_64; ; ) References: <20110419135909.GA21897@cosy.cit.nih.gov> <110420080625.ZM16423@torch.brasslantern.com> <20110420172543.GK6935@mollari.zhar.net> In-Reply-To: <20110420172543.GK6935@mollari.zhar.net> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1750596.mSVCiXIbm5"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201104202240.22873@-zyx> --nextPart1750596.mSVCiXIbm5 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Reply to message =C2=ABRe: Suffix alias for README files=C2=BB,=20 sent 21:25:43 20 April 2011, Wednesday by John Eikenberry: > Is there any way to get either of these to work without changing the > command that is stored in history? So the history contains > '/some/path/README' and not 'less /some/path/README'? Yes, of course. I personally use the following code: function zshaddhistory() { emulate -L zsh if ! [[ -z "${_HISTLINE}" ]] ; then print -sr -- "${_HISTLINE}" unset _HISTLINE else print -sr -- "${1%%$'\n'}" fi fc -p } With this function if you set variable _HISTLINE somewhere before zshaddhis= tory=20 hook is run then contents of _HISTLINE will be put into the history. Widget= =20 accept-line is called before zshaddhistory. Here is where I actually use _HISTLINE (with just the same purpose: execute= one=20 command, but add to history another): function _-accept-line() { emulate -L zsh local -r autopushd=3D${options[autopushd]} options[autopushd]=3Doff cd $PWD || cd options[autopushd]=3D$autopushd if [[ ${BUFFER[1,3]} =3D=3D ":h " ]] ; then _HISTLINE=3D$BUFFER BUFFER=3D":h ${(q)BUFFER[4,-1]}" elif [[ ${BUFFER[1,4]} =3D=3D "zmw " ]] ; then _HISTLINE=3D$BUFFER BUFFER=3D"zmw "${(j. .)${(q)${(z)BUFFER[5,-1]}}} fi zle .accept-line } Original message: > Bart Schaefer wrote: > > > I can use suffix aliases to display various .txt files. > > > Can I do a similar thing for README files? So the "command" > > >=20 > > > /some/path/README > > >=20 > > > will really run the command > > >=20 > > > less /some/path/README > >=20 > > Depending on your version of zsh, you can do this either with the > > zle-line-finish widget or by replacing the accept-line widget. > >=20 > > zle-line-finish() { > >=20 > > setopt localoptions extendedglob > > if [[ -z "$PREBUFFER" && "$BUFFER" =3D ([^[:space:]]#/)#README ]] > > then BUFFER=3D"less $BUFFER" > > fi > >=20 > > } > > zle -N zle-line-finish > >=20 > > Or > >=20 > > accept-line() { > >=20 > > setopt localoptions extendedglob > > if [[ -z "$PREBUFFER" && "$BUFFER" =3D ([^[:space:]]#/)#README ]] > > then BUFFER=3D"less $BUFFER" > > fi > > zle .accept-line "$@" > >=20 > > } > > zle -N accept-line >=20 > Is there any way to get either of these to work without changing the > command that is stored in history? So the history contains > '/some/path/README' and not 'less /some/path/README'? --nextPart1750596.mSVCiXIbm5 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iEYEABECAAYFAk2vKJYACgkQTFU0h8DxG4NmRgCePDV3L7nsgaR6qFUarAei/ycn Fb8AmwURV6q4vqfoCozj/hvB8C3arQgl =D9qQ -----END PGP SIGNATURE----- --nextPart1750596.mSVCiXIbm5--