2009-06-05 08:29:09 +02:00
|
|
|
# update-rc.d(8) completion
|
|
|
|
#
|
|
|
|
# Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
|
2009-10-01 20:54:51 +03:00
|
|
|
|
2009-06-05 08:29:09 +02:00
|
|
|
have update-rc.d &&
|
|
|
|
_update_rc_d()
|
|
|
|
{
|
|
|
|
local cur prev sysvdir services options valid_options
|
|
|
|
|
|
|
|
cur=`_get_cword`
|
|
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
|
|
|
|
|
|
|
[ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
|
|
|
|
|| sysvdir=/etc/init.d
|
|
|
|
|
|
|
|
services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm@(orig|new|save))) )
|
|
|
|
services=( ${services[@]#$sysvdir/} )
|
|
|
|
options=( -f -n )
|
|
|
|
|
|
|
|
if [[ $COMP_CWORD -eq 1 || "$prev" == -* ]]; then
|
|
|
|
valid_options=( $( \
|
|
|
|
echo "${COMP_WORDS[@]} ${options[@]}" \
|
|
|
|
| tr " " "\n" \
|
|
|
|
| sed -ne "/$( echo "${options[@]}" | sed "s/ /\\|/g" )/p" \
|
|
|
|
| sort | uniq -u \
|
|
|
|
) )
|
|
|
|
COMPREPLY=( $( compgen -W '${options[@]} ${services[@]}' \
|
Quote unquoted $cur to prevent globbing.
Closes Alioth #311614
Globbing might occur if $cur contains one of these globbing characters: * ? [ ]
The bug becomes apparent:
On Cygwin if the glob-string contains backslashes as well, causing a warning (Cygwin >= 1.7):
MS-DOS style path detected: ...
Preferred POSIX equivalent is: ...
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
On Linux, using strace, you can see bash-completion doing an unnecessary `open' system call.
Steps to reproduce on Linux using `strace':
Environment: Linux, bash-completion-1.0
1. Start bash with bash-completion loaded and find out PID ($$):
$ echo $$
MYPID
2. In a second bash shell, `strace' the above PID:
$ strace -e trace=open -f -o strace.log -p MYPID
3. Within the first bash shell, type:
$ cur="?"; _kernel_versions
4. In the second bash shell, type ^C to quick `strace'.
5. Check `strace.log', here you can see bash accessing
something it shouldn't:
...
open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3
...
6. The above call to `open' disappears if $cur in _kernel_versions gets
quoted, and you repeat the steps above:
_kernel_versions()
{
COMPREPLY=( $( compgen -W '$( command ls /lib/modules )' -- "$cur" ) )
}
2009-09-25 09:36:29 +02:00
|
|
|
-X '$( echo ${COMP_WORDS[@]} | tr " " "|" )' -- "$cur" ) )
|
2009-06-05 08:29:09 +02:00
|
|
|
elif [[ "$prev" == ?($( echo ${services[@]} | tr " " "|" )) ]]; then
|
Quote unquoted $cur to prevent globbing.
Closes Alioth #311614
Globbing might occur if $cur contains one of these globbing characters: * ? [ ]
The bug becomes apparent:
On Cygwin if the glob-string contains backslashes as well, causing a warning (Cygwin >= 1.7):
MS-DOS style path detected: ...
Preferred POSIX equivalent is: ...
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
On Linux, using strace, you can see bash-completion doing an unnecessary `open' system call.
Steps to reproduce on Linux using `strace':
Environment: Linux, bash-completion-1.0
1. Start bash with bash-completion loaded and find out PID ($$):
$ echo $$
MYPID
2. In a second bash shell, `strace' the above PID:
$ strace -e trace=open -f -o strace.log -p MYPID
3. Within the first bash shell, type:
$ cur="?"; _kernel_versions
4. In the second bash shell, type ^C to quick `strace'.
5. Check `strace.log', here you can see bash accessing
something it shouldn't:
...
open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3
...
6. The above call to `open' disappears if $cur in _kernel_versions gets
quoted, and you repeat the steps above:
_kernel_versions()
{
COMPREPLY=( $( compgen -W '$( command ls /lib/modules )' -- "$cur" ) )
}
2009-09-25 09:36:29 +02:00
|
|
|
COMPREPLY=( $( compgen -W 'remove defaults start stop' -- "$cur" ) )
|
2009-06-05 08:29:09 +02:00
|
|
|
elif [[ "$prev" == defaults && "$cur" == [0-9] ]]; then
|
|
|
|
COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
|
|
|
|
elif [[ "$prev" == defaults && "$cur" == [sk]?([0-9]) ]]; then
|
|
|
|
COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
|
|
|
|
elif [[ "$prev" == defaults && -z "$cur" ]]; then
|
|
|
|
COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 s k )
|
|
|
|
elif [[ "$prev" == ?(start|stop) ]]; then
|
|
|
|
if [[ "$cur" == [0-9] || -z "$cur" ]]; then
|
|
|
|
COMPREPLY=( 0 1 2 3 4 5 6 7 8 9 )
|
|
|
|
elif [[ "$cur" == [0-9][0-9] ]]; then
|
|
|
|
COMPREPLY=( $cur )
|
|
|
|
else
|
|
|
|
COMPREPLY=()
|
|
|
|
fi
|
|
|
|
elif [[ "$prev" == ?([0-9][0-9]|[0-6S]) ]]; then
|
|
|
|
if [[ -z "$cur" ]]; then
|
|
|
|
if [[ $prev == [0-9][0-9] ]]; then
|
|
|
|
COMPREPLY=( 0 1 2 3 4 5 6 S )
|
|
|
|
else
|
|
|
|
COMPREPLY=( 0 1 2 3 4 5 6 S . )
|
|
|
|
fi
|
|
|
|
elif [[ "$cur" == [0-6S.] ]]; then
|
|
|
|
COMPREPLY=( $cur )
|
|
|
|
else
|
|
|
|
COMPREPLY=()
|
|
|
|
fi
|
|
|
|
elif [[ "$prev" == "." ]]; then
|
Quote unquoted $cur to prevent globbing.
Closes Alioth #311614
Globbing might occur if $cur contains one of these globbing characters: * ? [ ]
The bug becomes apparent:
On Cygwin if the glob-string contains backslashes as well, causing a warning (Cygwin >= 1.7):
MS-DOS style path detected: ...
Preferred POSIX equivalent is: ...
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
On Linux, using strace, you can see bash-completion doing an unnecessary `open' system call.
Steps to reproduce on Linux using `strace':
Environment: Linux, bash-completion-1.0
1. Start bash with bash-completion loaded and find out PID ($$):
$ echo $$
MYPID
2. In a second bash shell, `strace' the above PID:
$ strace -e trace=open -f -o strace.log -p MYPID
3. Within the first bash shell, type:
$ cur="?"; _kernel_versions
4. In the second bash shell, type ^C to quick `strace'.
5. Check `strace.log', here you can see bash accessing
something it shouldn't:
...
open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3
...
6. The above call to `open' disappears if $cur in _kernel_versions gets
quoted, and you repeat the steps above:
_kernel_versions()
{
COMPREPLY=( $( compgen -W '$( command ls /lib/modules )' -- "$cur" ) )
}
2009-09-25 09:36:29 +02:00
|
|
|
COMPREPLY=( $(compgen -W "start stop" -- "$cur") )
|
2009-06-05 08:29:09 +02:00
|
|
|
else
|
|
|
|
COMPREPLY=()
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
} &&
|
|
|
|
complete -F _update_rc_d update-rc.d
|
|
|
|
|
|
|
|
# invoke-rc.d(8) completion
|
|
|
|
#
|
|
|
|
# Copyright (C) 2004 Servilio Afre Puentes <servilio@gmail.com>
|
|
|
|
#
|
|
|
|
have invoke-rc.d &&
|
|
|
|
_invoke_rc_d()
|
|
|
|
{
|
|
|
|
local cur prev sysvdir services options valid_options
|
|
|
|
|
|
|
|
cur=`_get_cword`
|
|
|
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
|
|
|
|
|
|
|
[ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d \
|
|
|
|
|| sysvdir=/etc/init.d
|
|
|
|
|
|
|
|
services=( $(echo $sysvdir/!(README*|*.sh|*.dpkg*|*.rpm@(orig|new|save))) )
|
|
|
|
services=( ${services[@]#$sysvdir/} )
|
|
|
|
options=( --help --quiet --force --try-anyway --disclose-deny --query --no-fallback )
|
|
|
|
|
|
|
|
if [[ ($COMP_CWORD -eq 1) || ("$prev" == --* ) ]]; then
|
|
|
|
valid_options=( $( \
|
|
|
|
echo ${COMP_WORDS[@]} ${options[@]} \
|
|
|
|
| tr " " "\n" \
|
|
|
|
| sed -ne "/$( echo ${options[@]} | sed "s/ /\\\\|/g" )/p" \
|
|
|
|
| sort | uniq -u \
|
|
|
|
) )
|
|
|
|
COMPREPLY=( $( compgen -W '${valid_options[@]} ${services[@]}' -- \
|
Quote unquoted $cur to prevent globbing.
Closes Alioth #311614
Globbing might occur if $cur contains one of these globbing characters: * ? [ ]
The bug becomes apparent:
On Cygwin if the glob-string contains backslashes as well, causing a warning (Cygwin >= 1.7):
MS-DOS style path detected: ...
Preferred POSIX equivalent is: ...
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
On Linux, using strace, you can see bash-completion doing an unnecessary `open' system call.
Steps to reproduce on Linux using `strace':
Environment: Linux, bash-completion-1.0
1. Start bash with bash-completion loaded and find out PID ($$):
$ echo $$
MYPID
2. In a second bash shell, `strace' the above PID:
$ strace -e trace=open -f -o strace.log -p MYPID
3. Within the first bash shell, type:
$ cur="?"; _kernel_versions
4. In the second bash shell, type ^C to quick `strace'.
5. Check `strace.log', here you can see bash accessing
something it shouldn't:
...
open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3
...
6. The above call to `open' disappears if $cur in _kernel_versions gets
quoted, and you repeat the steps above:
_kernel_versions()
{
COMPREPLY=( $( compgen -W '$( command ls /lib/modules )' -- "$cur" ) )
}
2009-09-25 09:36:29 +02:00
|
|
|
"$cur" ) )
|
2009-06-05 08:29:09 +02:00
|
|
|
elif [ -x $sysvdir/$prev ]; then
|
|
|
|
COMPREPLY=( $( compgen -W '`sed -ne "y/|/ /; \
|
|
|
|
s/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}\"]*\).*$/\1/p" \
|
|
|
|
$sysvdir/$prev`' -- \
|
Quote unquoted $cur to prevent globbing.
Closes Alioth #311614
Globbing might occur if $cur contains one of these globbing characters: * ? [ ]
The bug becomes apparent:
On Cygwin if the glob-string contains backslashes as well, causing a warning (Cygwin >= 1.7):
MS-DOS style path detected: ...
Preferred POSIX equivalent is: ...
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
On Linux, using strace, you can see bash-completion doing an unnecessary `open' system call.
Steps to reproduce on Linux using `strace':
Environment: Linux, bash-completion-1.0
1. Start bash with bash-completion loaded and find out PID ($$):
$ echo $$
MYPID
2. In a second bash shell, `strace' the above PID:
$ strace -e trace=open -f -o strace.log -p MYPID
3. Within the first bash shell, type:
$ cur="?"; _kernel_versions
4. In the second bash shell, type ^C to quick `strace'.
5. Check `strace.log', here you can see bash accessing
something it shouldn't:
...
open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3
...
6. The above call to `open' disappears if $cur in _kernel_versions gets
quoted, and you repeat the steps above:
_kernel_versions()
{
COMPREPLY=( $( compgen -W '$( command ls /lib/modules )' -- "$cur" ) )
}
2009-09-25 09:36:29 +02:00
|
|
|
"$cur" ) )
|
2009-06-05 08:29:09 +02:00
|
|
|
else
|
|
|
|
COMPREPLY=()
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
} &&
|
|
|
|
complete -F _invoke_rc_d invoke-rc.d
|
2009-10-01 20:54:51 +03:00
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: shell-script
|
|
|
|
# sh-basic-offset: 8
|
|
|
|
# sh-indent-comment: t
|
|
|
|
# indent-tabs-mode: t
|
|
|
|
# End:
|
|
|
|
# ex: ts=8 sw=8 noet filetype=sh
|