Fix auto complete of extra/goto_instance
authorFrederic Massart <fred@moodle.com>
Wed, 24 Jul 2013 05:08:17 +0000 (13:08 +0800)
committerFrederic Massart <fred@moodle.com>
Wed, 24 Jul 2013 05:08:17 +0000 (13:08 +0800)
extra/bash_completion
extra/goto_instance
extra/goto_instance.bash_completion [new file with mode: 0644]

index 975a6e2..e6448cf 100644 (file)
@@ -221,9 +221,3 @@ function _mdk() {
 if [[ -n "$(which mdk)" ]]; then
     complete -F _mdk mdk
 fi
-
-# Autocomplete for extra/goto_instance
-if [[ -n "$(type -t gt)" ]]; then
-    complete -F _gt gt
-    complete -F _gt gtd
-fi
index c4f1151..d99f7cb 100644 (file)
@@ -25,6 +25,7 @@
 #
 #   if [ -f /usr/share/moodle-sdk/extra/goto_instance ]; then
 #       . /usr/share/moodle-sdk/extra/goto_instance
+#       . /usr/share/moodle-sdk/extra/goto_instance.bash_completion
 #   fi
 #
 # Then source ~/.bashrc:
diff --git a/extra/goto_instance.bash_completion b/extra/goto_instance.bash_completion
new file mode 100644 (file)
index 0000000..408053e
--- /dev/null
@@ -0,0 +1,42 @@
+#
+# Moodle Development Kit
+#
+# Copyright (c) 2013 Frédéric Massart - FMCorz.net
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# http://github.com/FMCorz/mdk
+#
+
+# This file defines the functions the Bash completion of extra/goto_instance.
+#
+# This file has to be loaded after the goto_instance one, so it cannot be placed
+# into /etc/bash_completion.d.
+
+function _gt() {
+    local BIN CUR OPTS
+    BIN="mdk"
+    CUR="${COMP_WORDS[COMP_CWORD]}"
+    OPTS=""
+    if [[ "${COMP_CWORD}" == 1 ]]; then
+        OPTS=$($BIN info -ln 2> /dev/null)
+    fi
+    COMPREPLY=( $(compgen -W "${OPTS}" -- ${CUR}) )
+    return 0
+}
+
+if [[ -n "$(type -t gt)" ]]; then
+    complete -F _gt gt
+    complete -F _gt gtd
+fi