From b8d1d6ccfd42517f8b43c91d5383d3d0dbc2c2f1 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 24 Jul 2013 13:08:17 +0800 Subject: [PATCH] Fix auto complete of extra/goto_instance --- extra/bash_completion | 6 ------ extra/goto_instance | 1 + extra/goto_instance.bash_completion | 42 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 extra/goto_instance.bash_completion diff --git a/extra/bash_completion b/extra/bash_completion index 975a6e2..e6448cf 100644 --- a/extra/bash_completion +++ b/extra/bash_completion @@ -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 diff --git a/extra/goto_instance b/extra/goto_instance index c4f1151..d99f7cb 100644 --- a/extra/goto_instance +++ b/extra/goto_instance @@ -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 index 0000000..408053e --- /dev/null +++ b/extra/goto_instance.bash_completion @@ -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://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 -- 2.11.0