You are not logged in.
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
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
Here's what I found at the end of the zshcompctl manpage:
compctl -g '/etc/rc.d/*(:t)' dstart
Offline
Thank you.
Offline
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
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
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