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; 6+ 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] 6+ messages in thread

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

Thread overview: 6+ 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

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