You are not logged in.
Pages: 1
Hi,
I've now finished my bash_completion script for the command rc.d which was introduced some time ago.
If you have some advices just post them here.
# rc.d completion
#
# Author: Andrwe Lord Weber
# Mail: lord-weber-andrwe <at> andrwe <dot> org
#
which rc.d >/dev/null 2>&1 &&
_rc_d()
{
local cur prev initdir long_opts cmds shoptExtglob
shoptExtglob="$(shopt -p | grep extglob)"
shopt -s extglob
long_opts='list help'
initdir=/etc/rc.d
cmds="$(sed '/#.*sh/,/^.*case\s*"*\${*1}*"*.*/ { /^.*case\s*"*\${*1}*"*.*/!d };s/^.*case\s*"*\${*1}*"*.*/;;/g;/;;/,/^\s*.*)\s*$/ !d;/^\s*.*)\s*$/ !d;/\*/d;/;;/d;s/\s*//g;s/)//g;s/|/ /g' ${initdir}/!(*functions*) | LANG=C sort -u | tr '\n' ' ')"
_get_comp_words_by_ref cur prev
cmd="${COMP_WORDS[1]}"
if [[ "${cmd}" =~ ^(${cmds// /|}|${long_opts// /|})$ ]] && [ -n "${cmd}" ]; then
COMPREPLY+=( $( compgen -W '`grep -El "^[ ]*[^ ]*${cmd}[|\)][^ ]*\)*[ ]*$" ${initdir}/* | sed 's#${initdir}/##'`' -- "$cur" ) )
else
COMPREPLY=( $( compgen -W '${long_opts} ${cmds}' -- "$cur" ) )
fi
${shoptExtglob}
return 0
} &&
complete -F _rc_d rc.d
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# vim: ts=2 sw=2 et filetype=sh
Maybe it could be added to initscripts-package.
Kind regards,
Andrwe
Website: andrwe.org
Offline
I haven't really looked at the code, but how does it deal with https://bugs.archlinux.org/task/24356 ?
many initscripts have their own actions, like force-restart or reload. Some of the scripts, f.e. network, has even actions with additional arguments, like 'ifup eth0', which would not work with current version of rc.d
As initscripts is a core package, I think you should post this on the ML if you want to hear from the devs.
Offline
It can handle all own actions I could find in the initscripts out there.
I've initially wrote a completion for arch-daemon and created a sed command which can get all commands as long as they are part of the "case $1 in" part.
This sed command is also used here.
Website: andrwe.org
Offline
Just merged functionality of https://github.com/seblu/arch-initscrip … completion.
# rc.d completion
#
# Author: Andrwe Lord Weber
# Mail: lord-weber-andrwe <at> andrwe <dot> org
#
which rc.d >/dev/null 2>&1 &&
_rc_d()
{
local cur prev initdir long_opts cmds shoptExtglob
shoptExtglob="$(shopt -p | grep extglob)"
shopt -s extglob
long_opts='list help'
initdir=/etc/rc.d
cmds="$(sed '/#.*sh/,/^.*case\s*"*\${*1}*"*.*/ { /^.*case\s*"*\${*1}*"*.*/!d };s/^.*case\s*"*\${*1}*"*.*/;;/g;/;;/,/^\s*.*)\s*$/ !d;/^\s*.*)\s*$/ !d;/\*/d;/;;/d;s/\s*//g;s/)//g;s/|/ /g' ${initdir}/!(*functions*) | LANG=C sort -u | tr '\n' ' ')"
_get_comp_words_by_ref cur prev
cmd="${COMP_WORDS[1]}"
if [[ "${cmd}" =~ ^(${cmds// /|}|${long_opts// /|})$ ]] && [ -n "${cmd}" ]; then
daemons="$(ls -1 /run/daemons/ | tr '\n' '|')"
case "${cmd}" in
start)
COMPREPLY+=( $( compgen -W '`grep -El "^[ ]*[^ ]*${cmd}[|\)][^ ]*\)*[ ]*$" ${initdir}/* | sed 's#${initdir}/##' | grep -vE "^(${daemons})$"`' -- "$cur" ) )
;;
stop|restart|reload)
COMPREPLY+=( $( compgen -W '`grep -El "^[ ]*[^ ]*${cmd}[|\)][^ ]*\)*[ ]*$" ${initdir}/* | sed 's#${initdir}/##' | grep -E "^(${daemons})$"`' -- "$cur" ) )
;;
*)
COMPREPLY+=( $( compgen -W '`grep -El "^[ ]*[^ ]*${cmd}[|\)][^ ]*\)*[ ]*$" ${initdir}/* | sed 's#${initdir}/##'`' -- "$cur" ) )
;;
esac
else
COMPREPLY=( $( compgen -W '${long_opts} ${cmds}' -- "$cur" ) )
fi
${shoptExtglob}
return 0
} &&
complete -F _rc_d rc.d
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# vim: ts=2 sw=2 et filetype=sh
Website: andrwe.org
Offline
I have only one small issue with this script: If I type in the first letter of a daemon (e.g. "l" in laptop-mode), it doesn't complete it, but rather, forces me to cycle through all the available daemons; also, if I type "rc.d start", and then tab, I receive the output "comm: file 1 is not in sorted order" and on the next line "comm: file 2 is not in sorted order". I don't receive this output when doing rc.d stop|restart|reload.
Thanks for the nifty script.
Registed Linux User 483618
Offline
I have only one small issue with this script: If I type in the first letter of a daemon (e.g. "l" in laptop-mode), it doesn't complete it, but rather, forces me to cycle through all the available daemons; also, if I type "rc.d start", and then tab, I receive the output "comm: file 1 is not in sorted order" and on the next line "comm: file 2 is not in sorted order". I don't receive this output when doing rc.d stop|restart|reload.
Thanks for the nifty script.
Here my suggestion, you updated your system today.
With the update of initscripts today the simple bash-completion of the maintainer was installed.
I'm pretty sure that your completion is done by this one because I don't use comm but the version of the maintainer does.
I'm currently working on the ML to get my version accepted.
Unfortunately and forunately the standard of scripts for core-functions is very high which is why it may take some time.
Website: andrwe.org
Offline
Wow, you were right. Thanks for the head's up, and I will be looking forward to seeing your version .
Last edited by Sara (2011-06-08 22:39:50)
Registed Linux User 483618
Offline
Pages: 1