zsh-users
 help / color / mirror / code / Atom feed
* comptctl help
@ 2001-07-26 23:52 Will Yardley
  2001-07-27 13:42 ` Sven Wischnowsky
  0 siblings, 1 reply; 4+ messages in thread
From: Will Yardley @ 2001-07-26 23:52 UTC (permalink / raw)
  To: zsh-users

i was wondering if someone could give me a little help with a couple of my
compctls.  i'd prefer not to use the menu configuration for these - i like
having it in a file, and i don't have a recent version of zsh on all of the
machines i use.

this works great for me, but if i try to cd into a hidden directory (say
.ssh / .netscape whatever) it won't autocomplete.  presumably i need to add
.??*(-/) somehow but i haven't been able to figure out how to do 'or' for
this particular expression.  i tried adding both separately with -g for each,
and i tried putting them between parenthesis with a pipe in between.  sorry
for the dumb question.

here's what i currently have.

# cd, rmdir etc. only accept dirs as arguments
compctl -g '*(-/)' cd chdir dirs pushd rmdir

also, i have this for scp:

# for scp or rcp we look for filenames or hostnames

filehosts() {
   local argc argv pref filenames hostnames
   read -nc argc
   read -Ac argv

   pref=$argv[$argc]
   setopt nullglob
   filenames=( ${pref}* )
   hostnames=( ${(M@)hosts:#${pref}*} )
   if [[ ${#filenames} -eq 0 && ${#hostnames} -eq 1 ]]; then
       reply=
   else
      reply=( $filenames $hostnames )
   fi
   return
}

compctl -K filehosts + -k hosts -S ':' + -u -S '@' \
       -x 'n[1,@]' -k hosts -S ':' - 'W[1,*:*]' -f -- rcp scp scp2

this works, but if i'm trying to copy a file that is in a different
directory, it completes the directory as if it's a file; ie if i'm trying to
copy:
junk/rfc2317.txt
and i type scp ju<tab>
it will complete to scp junk[space]
instead of junk/
so that i can then tab complete the filename.

it also doesn't work so well on older versions of zsh - sometimes it will
complete the username wrong or only give me some of the usernames as options.

anyway hope someone can help me out on this.

will


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

* Re: comptctl help
  2001-07-26 23:52 comptctl help Will Yardley
@ 2001-07-27 13:42 ` Sven Wischnowsky
  2001-07-27 18:37   ` Will Yardley
  0 siblings, 1 reply; 4+ messages in thread
From: Sven Wischnowsky @ 2001-07-27 13:42 UTC (permalink / raw)
  To: zsh-users; +Cc: Will Yardley

Will Yardley wrote:

> i was wondering if someone could give me a little help with a couple of my
> compctls.  i'd prefer not to use the menu configuration for these - i like
> having it in a file, and i don't have a recent version of zsh on all of the
> machines i use.

Hm.

> this works great for me, but if i try to cd into a hidden directory (say
> .ssh / .netscape whatever) it won't autocomplete.  presumably i need to add
> .??*(-/) somehow but i haven't been able to figure out how to do 'or' for
> this particular expression.  i tried adding both separately with -g for each,
> and i tried putting them between parenthesis with a pipe in between.  sorry
> for the dumb question.
> 
> here's what i currently have.
> 
> # cd, rmdir etc. only accept dirs as arguments
> compctl -g '*(-/)' cd chdir dirs pushd rmdir

Depending on your preference, use either:

  compctl -g '*(D-/)' cd ...

or

  compctl -g '*(-/)' + -g '.*(-/)' cd ...


> also, i have this for scp:
> 
> # for scp or rcp we look for filenames or hostnames
> 
> filehosts() {
>    local argc argv pref filenames hostnames
>    read -nc argc
>    read -Ac argv
> 
>    pref=$argv[$argc]
>    setopt nullglob

If you set an option in a function, you'll also setopt localoptions on
zsh version that support it.  But in this case you could just use the
glob qualifier `(N)', so...

>    filenames=( ${pref}* )

you could use (and this should also solve the other problem you have
with this function):

  filenames=( ${pref}*(N-^/) ${pref}*/ )

>    hostnames=( ${(M@)hosts:#${pref}*} )
>    if [[ ${#filenames} -eq 0 && ${#hostnames} -eq 1 ]]; then
>        reply=

  reply=()

would be nicer

>    else
>       reply=( $filenames $hostnames )
>    fi
>    return
> }
> 
> compctl -K filehosts + -k hosts -S ':' + -u -S '@' \
>        -x 'n[1,@]' -k hosts -S ':' - 'W[1,*:*]' -f -- rcp scp scp2
> 
> this works, but if i'm trying to copy a file that is in a different
> directory, it completes the directory as if it's a file; ie if i'm trying to
> copy:
> junk/rfc2317.txt
> and i type scp ju<tab>
> it will complete to scp junk[space]
> instead of junk/
> so that i can then tab complete the filename.
> 
> it also doesn't work so well on older versions of zsh - sometimes it will
> complete the username wrong or only give me some of the usernames as options.

This isn't enough information to enable to help you.  No way to get
newer versions running there?


Bye
  Sven


-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

* Re: comptctl help
  2001-07-27 13:42 ` Sven Wischnowsky
@ 2001-07-27 18:37   ` Will Yardley
  2001-07-30  7:29     ` Sven Wischnowsky
  0 siblings, 1 reply; 4+ messages in thread
From: Will Yardley @ 2001-07-27 18:37 UTC (permalink / raw)
  To: zsh-users

On Fri, Jul 27, 2001 at 03:42:22PM +0200, Sven Wischnowsky wrote:
>   compctl -g '*(D-/)' cd ...

that works perfectly... thanks!

> you could use (and this should also solve the other problem you have
> with this function):
> 
>   filenames=( ${pref}*(N-^/) ${pref}*/ )
> 
> >    hostnames=( ${(M@)hosts:#${pref}*} )
> >    if [[ ${#filenames} -eq 0 && ${#hostnames} -eq 1 ]]; then
> >        reply=

this works too. _except_ it puts a space after completing the directory name
still ie:
scp ju<tab>
completes to
scp junk/[space]
instead of scp junk/[wait for filename completion still]
i suppose that sometimes you might want to copy a whole directory (and it
would be really fancy to take a directory arg if you did scp -r but a
filename only if you just did scp)
don't know if it's possible to do this.

> This isn't enough information to enable to help you.  No way to get
> newer versions running there?

ok here's one example:
vader% scp williargv=(willi '')
am@

it completes it but does this (this is the same .compctl as on the other
machine).

this also messes up my spacing - if i hit control-u i still have:
vader% scp williargv=(willi '')
vader% echo $ZSH_VERSION
3.0.7

this isn't really such a big deal since it's only one machine - i may just
ignore certain completions based on ZSH_VERSION

my personal machines are all 4.0.1, but the majority of the machines i use
for work are 3.1.9-dev-6 - the stable debian package.  aside from building a
package myself or adapting the unstable package and building it on stable not
really going to happen (ie there are 110 machines or so and i'm not going to
install it from source on all of them :>)

an example from one of these machines:

yakko% kill -Bad syntax, perhaps a bogus '-'?
Bad syntax, perhaps a bogus '-'?

ABRT     CLD      FPE      INT      POLL     QUIT     STOP     TRAP     TTOU
USR2     XCPU
ALRM     CONT     HUP      KILL     PROF     SEGV     SYS      TSTP     URG
VTALRM   XFSZ
BUS      EXIT     ILL      PIPE     PWR      STKFLT   TERM     TTIN     USR1
WINCH

this doesn't happen on my 4.0.1 machines but perhaps it's just being picky.
(also leaves the line placement a bit messed up even if i clear line)
i think i just copied this from the defaults or from someone so it's possible 
there's an error

or is there just something in here that needs to be different between linux / 
BSD? my personal machines are all freebsd so it's possible that that's the
difference.  anyway i hardly ever use this completion anyway so it's not a
huge deal - just annoying when i try to use it.

compctl -j -P '%' + -s '`ps -x | tail +2 | cut -c1-5`' + \
        -x 's[-] p[1]' -k "($signals[1,-3])" -- kill

thanks for the help!

will


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

* Re: comptctl help
  2001-07-27 18:37   ` Will Yardley
@ 2001-07-30  7:29     ` Sven Wischnowsky
  0 siblings, 0 replies; 4+ messages in thread
From: Sven Wischnowsky @ 2001-07-30  7:29 UTC (permalink / raw)
  To: zsh-users; +Cc: Will Yardley

Will Yardley wrote:

> ...
> 
> this works too. _except_ it puts a space after completing the directory name
> still ie:
> scp ju<tab>
> completes to
> scp junk/[space]
> instead of scp junk/[wait for filename completion still]

Err, right.  Add -S '' to the compctl-line.  But that leaves the cursor
directly after normal files, too.  If you want to fix this, the easiest
solution would probably be to use two different functions...

> i suppose that sometimes you might want to copy a whole directory (and it
> would be really fancy to take a directory arg if you did scp -r but a
> filename only if you just did scp)
> don't know if it's possible to do this.
> 
> > This isn't enough information to enable to help you.  No way to get
> > newer versions running there?
> 
> ok here's one example:
> vader% scp williargv=(willi '')
> am@

Get rid of the loacl-declaration of `argv', it's automatically local anyway.

> it completes it but does this (this is the same .compctl as on the other
> machine).
> 
> this also messes up my spacing - if i hit control-u i still have:
> vader% scp williargv=(willi '')
> vader% echo $ZSH_VERSION
> 3.0.7
> 
> this isn't really such a big deal since it's only one machine - i may just
> ignore certain completions based on ZSH_VERSION
> 
> my personal machines are all 4.0.1, but the majority of the machines i use
> for work are 3.1.9-dev-6 - the stable debian package.  aside from building a
> package myself or adapting the unstable package and building it on stable not
> really going to happen (ie there are 110 machines or so and i'm not going to
> install it from source on all of them :>)

Given that, I'd strongly suggest you use the new completion system on
all those 3.1.9 and 4.0.1 machines.

> an example from one of these machines:
> 
> yakko% kill -Bad syntax, perhaps a bogus '-'?
> Bad syntax, perhaps a bogus '-'?
> 
> ...
> 
> or is there just something in here that needs to be different between linux / 
> BSD? my personal machines are all freebsd so it's possible that that's the
> difference.  anyway i hardly ever use this completion anyway so it's not a
> huge deal - just annoying when i try to use it.
> 
> compctl -j -P '%' + -s '`ps -x | tail +2 | cut -c1-5`' + \
>         -x 's[-] p[1]' -k "($signals[1,-3])" -- kill
> 
> thanks for the help!

One of them has problems with `ps -x', I guess.


Bye
  Sven


-- 
Sven Wischnowsky                         wischnow@informatik.hu-berlin.de


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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-26 23:52 comptctl help Will Yardley
2001-07-27 13:42 ` Sven Wischnowsky
2001-07-27 18:37   ` Will Yardley
2001-07-30  7:29     ` Sven Wischnowsky

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