zsh-users
 help / color / mirror / code / Atom feed
* Re: using precmd() to get hostnames out of commands
@ 2001-07-29 16:33 Bart Schaefer
  2001-07-29 16:55 ` Paul Lew
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2001-07-29 16:33 UTC (permalink / raw)
  To: zsh-users

[Apologies if this shows up twice.  I'm concerned that the list server
is silently discarding mail from the brasslantern.com domain for some
reason, so I'm resending from another account as a test.]

On Jul 29,  2:57pm, Alan Third wrote:
} Subject: using precmd() to get hostnames out of commands
}
} Right, a while ago I decided that I wanted my hostname completion to
} include any hostnames that I typed on the command line during a
} session
}
} Is there a better way to do this?

  histhosts() {
    if (( $+_histhosts_cache ))
    then
      set -- ${(z)history[$[${(%):-%h}-1]]}
    else
      typeset -ag _histhosts_cache
      set -- $historywords
    fi
    while (( $# ))
    do
      [[ $1 == (<1-255>.<0-255>.<0-255>.<0-255>|*.org|*.com|*.net|*.edu) ||
	 $1 == *.??~*.<-> ]] && _histhosts_cache[1,0]=$1
      shift
    done
    reply=( $_histhosts_cache )
  }

  zstyle -e ':completion:*:hosts' hosts histhosts

You don't usually want `||' in a glob pattern.  That means "or empty or".
Just one `|'.

About that `_histhosts_cache[1,0]' -- the subscript [1,0] refers to the
non-existent element to the left of element 1, so assigning to that
element is roughly equivalent to perl `unshift'.  This only works in
some late versions of 3.1.9-dev and later.

About `*.??~*.<->' -- that means any two characters that are not digits.
But I think you might be better off with `[^/]#.[[:alpha:]][[:alpha:]]',
which at least omits file paths although `foobar.tar.gz' sneaks past.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net


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

* Re: using precmd() to get hostnames out of commands
  2001-07-29 16:33 using precmd() to get hostnames out of commands Bart Schaefer
@ 2001-07-29 16:55 ` Paul Lew
  2001-07-29 17:13   ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Lew @ 2001-07-29 16:55 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

>>>>> "Bart" == Bart Schaefer <schaefer@zanshin.com> writes:

    Bart> On Jul 29,  2:57pm, Alan Third wrote:
    Bart> } Subject: using precmd() to get hostnames out of commands
    Bart> }
    Bart> } Right, a while ago I decided that I wanted my hostname
    Bart> } completion to } include any hostnames that I typed on the
    Bart> } command line during a } session } } Is there a better way to
    Bart> } do this?

    <snip>

Is there a way to do dynamic completion like emacs (M-/) in zsh?  Wont
this be a more generic solution to this problem?


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

* Re: using precmd() to get hostnames out of commands
  2001-07-29 16:55 ` Paul Lew
@ 2001-07-29 17:13   ` Bart Schaefer
  2001-07-29 23:42     ` dynamic completion like emacs (M-/) Paul Lew
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2001-07-29 17:13 UTC (permalink / raw)
  To: zsh-users

On Sun, 29 Jul 2001, Paul Lew wrote:

> >>>>> "Bart" == Bart Schaefer <schaefer@zanshin.com> writes:
>
> Is there a way to do dynamic completion like emacs (M-/) in zsh?  Wont
> this be a more generic solution to this problem?

Yes, it's already bound to <ESC /> which is bothering some vi-mode users.
But you still need to filter the words somehow so as to offer only the
ones that look like host names as completions.


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

* Re: dynamic completion like emacs (M-/)
  2001-07-29 17:13   ` Bart Schaefer
@ 2001-07-29 23:42     ` Paul Lew
  2001-07-30  0:41       ` Bart Schaefer
  2001-07-30  0:51       ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Paul Lew @ 2001-07-29 23:42 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

>>>>> "Bart" == Bart Schaefer <schaefer@brasslantern.com> writes:

    Bart> On Sun, 29 Jul 2001, Paul Lew wrote:

    paul>> Is there a way to do dynamic completion like emacs (M-/) in
    paul>> zsh?  Wont this be a more generic solution to this problem?

    Bart> Yes, it's already bound to <ESC /> which is bothering some
    Bart> vi-mode users.

Which version is this binding added?  I could not find in both the
4.0.2 and the 4.1.0-dev-1.  I have tried both the emacs and vi mode
and the M-/ is bind to:

    "\M-/" self-insert

A note on dynamic completion key binding: In vim (Vi Improved), the
dynamic completion is available in the insert mode as c-p and c-n.
How about bind it to M-/ in emacs mode and c-p in vi insert mode?


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

* Re: dynamic completion like emacs (M-/)
  2001-07-29 23:42     ` dynamic completion like emacs (M-/) Paul Lew
@ 2001-07-30  0:41       ` Bart Schaefer
  2001-07-30  0:51       ` Bart Schaefer
  1 sibling, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2001-07-30  0:41 UTC (permalink / raw)
  To: Paul Lew; +Cc: zsh-users

On Jul 29,  4:42pm, Paul Lew wrote:
}
}     paul>> Is there a way to do dynamic completion like emacs (M-/) in
}     paul>> zsh?
} 
}     Bart> Yes, it's already bound to <ESC /> which is bothering some
}     Bart> vi-mode users.
} 
} Which version is this binding added?  I could not find in both the
} 4.0.2 and the 4.1.0-dev-1.

It's only added if you're using the new completion system.  It gets
installed by `compinit'.

} How about bind it to M-/ in emacs mode and c-p in vi insert mode?

Ideally, that's what we'd do.  But at present, the `#compdef' tags used
by `compinit' to define key bindings only allow you to say what key to
use, not what keymap to install it in.  It goes into whatever map is in
effect at the time `compinit' runs.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* Re: dynamic completion like emacs (M-/)
  2001-07-29 23:42     ` dynamic completion like emacs (M-/) Paul Lew
  2001-07-30  0:41       ` Bart Schaefer
@ 2001-07-30  0:51       ` Bart Schaefer
  1 sibling, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2001-07-30  0:51 UTC (permalink / raw)
  To: zsh-users

On Jul 29,  4:42pm, Paul Lew wrote:
} 
} Which version is this binding added?  I could not find in both the
} 4.0.2 and the 4.1.0-dev-1.  I have tried both the emacs and vi mode
} and the M-/ is bind to:
} 
}     "\M-/" self-insert

Oh -- didn't catch this at first -- it quite literally is bound to the
two-character sequence ESC / and NOT bound to the single character M-/.

[Aside to anyone who cares -- I still can't send mail to zsh-users from
my home machine.  I'm using a procmail hack to relay it through zanshin.]

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


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

* using precmd() to get hostnames out of commands
@ 2001-07-29 13:57 Alan Third
  0 siblings, 0 replies; 7+ messages in thread
From: Alan Third @ 2001-07-29 13:57 UTC (permalink / raw)
  To: zsh-users mailing list

Right, a while ago I decided that I wanted my hostname completion to
include any hostnames that I typed on the command line during a
session so I could do things like:


grover:/home/alan>ping  penglet.org
<snip>
grover:/home/alan>ssh pen<tab>

So I came up with this:


iplegal()
{
if [[ $1 == ([1-9]||[1-9][0-9]||1[0-9][0-9]||[2[0-4][0-9]||25[0-5]).\
([0-9]||[1-9][0-9]||1[0-9][0-9]||[2[0-4][0-9]||25[0-5]).\
([0-9]||[1-9][0-9]||1[0-9][0-9]||[2[0-4][0-9]||25[0-5]).\
([0-9]||[1-9][0-9]||1[0-9][0-9]||[2[0-4][0-9]||25[0-5]) ]]
then
        echo legal
else
        echo illegal
fi
}

precmd()
{
        # add any hostnames from the last command to the 
        # hostname completion array
        lastargs=(`fc -ln -1`)

        for stuff in $lastargs
        do
                if [[ $stuff == (*.org||*.com||*.net||*.edu||*.??~*.\
[[:digit:]][[:digit:]]) || `iplegal $stuff` == legal ]]
                then
                        hosts=($hosts $stuff)
                        zstyle ':completion:*:hosts' hosts $hosts
                fi
        done
}

It also recognises IPs and sticks them in too.

Is there a better way to do this? 

Thanks.
-- 
Alan Third

Cows go moo!


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

end of thread, other threads:[~2001-07-30  0:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-29 16:33 using precmd() to get hostnames out of commands Bart Schaefer
2001-07-29 16:55 ` Paul Lew
2001-07-29 17:13   ` Bart Schaefer
2001-07-29 23:42     ` dynamic completion like emacs (M-/) Paul Lew
2001-07-30  0:41       ` Bart Schaefer
2001-07-30  0:51       ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2001-07-29 13:57 using precmd() to get hostnames out of commands Alan Third

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).