[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 6ac176ec7232ef9b2e3c80deacceac53dae6ae00

Ville Skyttä ville.skytta at iki.fi
Thu Jun 17 21:24:15 UTC 2010


The following commit has been merged in the master branch:
commit 6ac176ec7232ef9b2e3c80deacceac53dae6ae00
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Fri Jun 18 00:24:04 2010 +0300

    Add crontab completion.

diff --git a/CHANGES b/CHANGES
index bb09a83..8601d5c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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 at gmail.com>  Wed, 16 Jun 2010 17:53:22 +0200
 
diff --git a/Makefile.am b/Makefile.am
index 93574a7..d34b028 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -29,6 +29,7 @@ bashcomp_DATA = contrib/abook \
 		contrib/cowsay \
 		contrib/cpan2dist \
 		contrib/cpio \
+		contrib/crontab \
 		contrib/cups \
 		contrib/cryptsetup \
 		contrib/cvs \
diff --git a/contrib/crontab b/contrib/crontab
new file mode 100644
index 0000000..cb440a6
--- /dev/null
+++ b/contrib/crontab
@@ -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
diff --git a/test/completion/crontab.exp b/test/completion/crontab.exp
new file mode 100644
index 0000000..2a64949
--- /dev/null
+++ b/test/completion/crontab.exp
@@ -0,0 +1 @@
+assert_source_completions crontab
diff --git a/test/lib/completions/abook.exp b/test/lib/completions/crontab.exp
similarity index 82%
copy from test/lib/completions/abook.exp
copy to test/lib/completions/crontab.exp
index 3f4e301..b7398e6 100644
--- a/test/lib/completions/abook.exp
+++ b/test/lib/completions/crontab.exp
@@ -11,7 +11,7 @@ proc teardown {} {
 setup
 
 
-assert_complete_any "abook "
+assert_complete_any "crontab "
 
 
 sync_after_int

-- 
bash-completion



More information about the Bash-completion-commits mailing list