Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: the function to show a digit argument while it is being typed
- X-seq: zsh-users 14540
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Dmitry Bolshakov <bdimych@xxxxxxxx>
- Subject: Re: the function to show a digit argument while it is being typed
- Date: Wed, 11 Nov 2009 03:22:14 +0100
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=6VozBr1tJJVlno8hTivBThft+c06YCbceaB/hz282Lg=; b=A8zpnRqq8nfYtgX8PXD5FXLf4lDl3p/sJ7BN8cdSBDX9qaAzj/HJgJJpWs+BdwfrXL I8eXmulrmTjy1T3H/S5Q9Lwg2scYMIjhsgOkVoRQsqBHiFMgGEP6yP8JiKg+OZ44d0qD SsRIqn3/RlPC3cbIxB1lr/jL+XMT0hUNkSE7o=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=F91u+w8UpIHW0a4/wuEeHw0Bk8ZR6nWo/+i9DvzdU8pIgtLMDYIy2+MW+TuI1Fl0mN 0mhKfvGnblVfrB3UGf4OmBA9EBOYRoK27w2Px2fXM3vM2fvMvdzcIqSx3RwzUeyawMvo iwTaNUXc4172Q8ShfXu3WEdd6AjzvfxBNIxhc=
- In-reply-to: <10081257897632@xxxxxxxxxxxxxxxxxxx>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <10081257897632@xxxxxxxxxxxxxxxxxxx>
2009/11/11 Dmitry Bolshakov <bdimych@xxxxxxxx>:
> hi
>
> in bash a digit argument is showed when it is being typed
>
> i have writed small function which do the same
>
> #####
> function digit-argument-show-while-entering {
> arg="${KEYS[2]}"
> if [[ $arg == - ]]
> then
> zle .neg-argument
> else
> zle .digit-argument
> fi
> while true
> do
> PREDISPLAY="(arg: $arg) "
> zle -R
>
> read -k k1
> if [[ $k1 == $'\C-g' ]]
> then
> NUMERIC=1
> break
> elif [[ $k1 != $'\e' ]]
> then
> zle -U $k1
> break
> fi
>
> read -k k2
> if [[ $k2 == <0-9> ]]
> then
> arg=$arg$k2
> NUMERIC=$arg
> else
> zle -U "$k1$k2"
> break
> fi
> done
> PREDISPLAY=""
> }
> zle -N digit-argument digit-argument-show-while-entering
> zle -N neg-argument digit-argument-show-while-entering
> #####
>
> it is not well tested but seems to be working
You probably want to declare local variables so they don't overwrite
things in the main shell, ie "local arg k1 k2" in the beginning.
I have a similar function, it doesn't work well for negative arguments though:
function _digit_argument () {
zle -M "$NUMERIC$KEYS[-1]"
zle .digit-argument
}
The problem is $NUMERIC is -1 after pressing just -, so pressing -1
shows -11. After the first digit it shows things correctly though.
(I've tried the obvious thing of swapping the order of the lines and
showing just $NUMERIC, but it doesn't seem to be updated at that
point).
You can do zle .$WIDGET instead of your first if condition.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author