You are not logged in.

#1 2010-05-05 11:53:00

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

[solved] zsh, looking for compctl help

Hi guys,

i found this handy function in one of the .{bash,zsh}rc threads:

dstart() { # start a daemon
    for arg in $*; do
      sudo /etc/rc.d/$arg start
    done
}

Now i want the command dstart to be completed with the content of /etc/rc.d/ so i can do "dstart a(TAB)" and see all daemons starting with "a".

Now, this line:

compctl -g '/etc/rc.d/*' dstart

pretty much does that, but it prepends /etc/rc.d/ before the name of the daemon (i.e. it shows the whole path).
What i want is only the daemon name, not the full path name.

Maybe you guys can give me a hint on how to do this.

Greets,
demian

Last edited by demian (2010-05-05 12:20:47)


no place like /home
github

Offline

#2 2010-05-05 12:03:49

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: [solved] zsh, looking for compctl help

I asked the exact same thing on zsh's IRC channel! I have the same function too, just (imo) better written:

dstart() { for d; sudo /etc/rc.d/$d start || return 1 }

I hope someone can answer.

Offline

#3 2010-05-05 12:06:41

Leffe
Member
Registered: 2006-05-30
Posts: 47

Re: [solved] zsh, looking for compctl help

Here's what I found at the end of the zshcompctl manpage:

compctl -g '/etc/rc.d/*(:t)' dstart

Offline

#4 2010-05-05 12:08:45

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: [solved] zsh, looking for compctl help

Thank you.

Offline

#5 2010-05-05 12:23:56

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: [solved] zsh, looking for compctl help

Thanks, Leffe. I feel sheepish now since it was so easy.

With that completion one can use

dstart() { for d; $d start || return 1 }

.

Last edited by demian (2010-05-05 12:26:16)


no place like /home
github

Offline

#6 2010-05-05 12:31:53

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: [solved] zsh, looking for compctl help

dstart() { for d; sudo /etc/rc.d/$d start || return 1 }
dstop() { for d; sudo /etc/rc.d/$d stop || return 1 }
drestart() { for d; sudo /etc/rc.d/$d restart || return 1 }
compctl -g '/etc/rc.d/*(:t)' dstart
compctl -g '/var/run/daemons/*(:t)' dstop drestart

Offline

#7 2010-05-05 13:04:49

bluewind
Administrator
From: Austria
Registered: 2008-07-13
Posts: 172
Website

Re: [solved] zsh, looking for compctl help

rc() {
    sudo /etc/rc.d/$1 $2
}

function _rc () { 
  case $CURRENT in
    2) compadd $(find /etc/rc.d/ -maxdepth 1 -type f -executable -printf '%f ');;
    3) compadd $(/etc/rc.d/$words[2] 2> /dev/null | grep -i usage | sed 's/.*{\(.*\)}/\1/; s/|/ /g');;
  esac
}
compdef _rc rc

usage: rc sshd start (parameters are completed)

That's what I use and it works pretty well. Doesn't work the rc script has 744 permissions (think some aur packages) because it needs +x for other.

Offline

Board footer

Powered by FluxBB