zsh-users
 help / color / mirror / code / Atom feed
* alias hl='$(history -n -2 -2) '
@ 2006-02-19 18:23 zzapper
  2006-02-20 11:18 ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: zzapper @ 2006-02-19 18:23 UTC (permalink / raw)
  To: zsh-users

hi

alias hl='$(history -n -2 -2) '

The following attempts to emulate !-2 however if the command that is 
recalled is itself an alias, it fails to interpret the alias.

Is this just hard-luck?


-- 
zzapper
Success for Techies
http://SuccessTheory.com/ vim, zsh & success tips



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: alias hl='$(history -n -2 -2) '
  2006-02-19 18:23 alias hl='$(history -n -2 -2) ' zzapper
@ 2006-02-20 11:18 ` Peter Stephenson
  2006-02-20 13:17   ` zzapper
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Stephenson @ 2006-02-20 11:18 UTC (permalink / raw)
  To: Zsh users list

zzapper wrote:
> hi
> 
> alias hl='$(history -n -2 -2) '
> 
> The following attempts to emulate !-2 however if the command that is 
> recalled is itself an alias, it fails to interpret the alias.
> 
> Is this just hard-luck?

An overall summary is probably yes...  The $(...) construct doesn't
cause the text it outputs to be completely reevaluated, just output
onto the command line as a set of words.  This is substantially
different from what you want.

You could get the history part working better with

alias hl='eval "$(history -n -2 -2)" '

which takes the output from the history commands and treats it as a
command line (which is, of course, what it is).  The problem is
that the eval applies to the entire line, including anything you type
after "hl ".  I can think of nasty tricks involving functions to work
round that, but not any simple fix.

I presume you're trying to avoid bang-history for some reason.  If you're
not wedded to aliases you could use a zle function to retrieve specific
stuff from the history.

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: alias hl='$(history -n -2 -2) '
  2006-02-20 11:18 ` Peter Stephenson
@ 2006-02-20 13:17   ` zzapper
  2006-02-20 14:19     ` swapping keys Francisco Borges
  0 siblings, 1 reply; 5+ messages in thread
From: zzapper @ 2006-02-20 13:17 UTC (permalink / raw)
  To: zsh-users; +Cc: zsh-workers

Peter Stephenson <pws@csr.com> wrote in news:EXCHANGE03bJjyve2q70000ee73
@exchange03.csr.com:


> You could get the history part working better with
> 
> alias hl='eval "$(history -n -2 -2)" '
> 
That fixes it, thnx
> 
> I presume you're trying to avoid bang-history for some reason.  If you're
> not wedded to aliases you could use a zle function to retrieve specific
> stuff from the history.
> 
It's just that !-2 is a bit a pain to type (sorry)!


-- 
zzapper
Success for Techies
http://SuccessTheory.com/ vim, zsh & success tips



^ permalink raw reply	[flat|nested] 5+ messages in thread

* swapping keys
  2006-02-20 13:17   ` zzapper
@ 2006-02-20 14:19     ` Francisco Borges
  2006-02-20 14:50       ` Peter Stephenson
  0 siblings, 1 reply; 5+ messages in thread
From: Francisco Borges @ 2006-02-20 14:19 UTC (permalink / raw)
  To: zsh-users

» On Mon, Feb 20, 2006 at 01:17PM +0000, zzapper wrote:

> It's just that !-2 is a bit a pain to type (sorry)!

One possible solution is to switch keys like "`~" and "1!" (I have to
confess I have only swapped "`~").

Since I am at it... Is it possible to swap keys inside zsh?

I know I can use

% bindkey -s 1 !

but then I can't do the reverse ("bindkey -s ! 1").

I have swapped some keys but I did it globally (i.e. xmodmap), while
that is what I want for some keys (like ESC and CapsLock) I did rather
keep some key changes within the shell only.

Cheers!
Francisco


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: swapping keys
  2006-02-20 14:19     ` swapping keys Francisco Borges
@ 2006-02-20 14:50       ` Peter Stephenson
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2006-02-20 14:50 UTC (permalink / raw)
  To: zsh-users

Francisco Borges wrote:
> One possible solution is to switch keys like "`~" and "1!" (I have to
> confess I have only swapped "`~").
> 
> Since I am at it... Is it possible to swap keys inside zsh?

Yes, it's fairly straightforward.  As written it doesn't work for
multibyte characters (e.g. you can't swap with a Euro or Yen or Pound
Sterling in multibyte mode).  That wouldn't be too hard to fix (but it's
not as simple as just removing the test: you need a loop over bytes in
the argument).


# start
# swapkeys X Y
#   swap keys X and Y so typing X gives Y and vice versa
# swapkeys -d X Y
#   completely remove a previous swapping

emulate -L zsh
setopt cbases

integer delete i
local key hexkey

if [[ $1 = -d ]]; then
  delete=1
  shift
fi

if [[ $# -ne 2 || ${#1} -ne 1 || ${#2} -ne 1 ]]; then
  print "Usage: $0 [-d] key1 key2" >&2
  return 1
fi

for (( i = 1; i <= 2; i++ )); do
  key=$argv[i]
  hexkey=$(( [#16] #key ))
  if (( delete )); then
    zle -D insert-key-$hexkey
    bindkey $key self-insert
  else
    eval "insert-key-$hexkey () { LBUFFER+=\$'\\x${hexkey##0x}'; }"
    zle -N insert-key-$hexkey
    bindkey ${argv[3-i]} insert-key-$hexkey
  fi
done
# end

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-02-20 14:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-19 18:23 alias hl='$(history -n -2 -2) ' zzapper
2006-02-20 11:18 ` Peter Stephenson
2006-02-20 13:17   ` zzapper
2006-02-20 14:19     ` swapping keys Francisco Borges
2006-02-20 14:50       ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).