Add crontab completion.

This commit is contained in:
Ville Skyttä 2010-06-18 00:24:04 +03:00
parent 1f8b55a92a
commit 6ac176ec72
5 changed files with 83 additions and 0 deletions

View File

@ -5,6 +5,7 @@ bash-completion (2.x)
[ Ville Skyttä ]
* Activate hping2 completion also for hping and hping3.
* Add crontab completion.
-- David Paleino <d.paleino@gmail.com> Wed, 16 Jun 2010 17:53:22 +0200

View File

@ -29,6 +29,7 @@ bashcomp_DATA = contrib/abook \
contrib/cowsay \
contrib/cpan2dist \
contrib/cpio \
contrib/crontab \
contrib/cups \
contrib/cryptsetup \
contrib/cvs \

60
contrib/crontab Normal file
View File

@ -0,0 +1,60 @@
# crontab(1) completion
have crontab &&
_crontab()
{
local cur prev
COMPREPLY=()
_get_comp_words_by_ref cur prev
case $prev in
-u)
COMPREPLY=( $( compgen -u -- "$cur" ) )
return 0
;;
esac
local i opts=" -u -l -r -e" # leading space at start is significant...
[ "$(uname -s)" = Linux ] && opts="$opts -i"
[ -e /etc/selinux ] && opts="$opts -s"
for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
case "${COMP_WORDS[i]}" in
-l)
opts=${opts// -l -r -e/}
opts=${opts// -i/}
opts=${opts// -s/}
;;
-e)
opts=${opts// -l -r -e/}
opts=${opts// -i/}
;;
-r)
opts=${opts// -l -r -e/}
;;
-u)
opts=${opts// -u/}
opts=${opts// -i/}
;;
-i|-s)
opts=${opts// ${COMP_WORDS[i]}/}
;;
esac
done
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '$opts' -- "$cur" ) )
return 0
fi
# do filenames only if we did not have -l, -r, or -e
[[ "${COMP_LINE}" == *\ -@(l|r|e)* ]] || _filedir
} &&
complete -F _crontab -o filenames crontab
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh

View File

@ -0,0 +1 @@
assert_source_completions crontab

View File

@ -0,0 +1,20 @@
proc setup {} {
save_env
}; # setup()
proc teardown {} {
assert_env_unmodified
}; # teardown()
setup
assert_complete_any "crontab "
sync_after_int
teardown