Bash function to jump to instance directory
authorFrederic Massart <fred@moodle.com>
Thu, 18 Jul 2013 03:49:04 +0000 (11:49 +0800)
committerFrederic Massart <fred@moodle.com>
Thu, 18 Jul 2013 04:04:06 +0000 (12:04 +0800)
extra/bash_completion
extra/goto_instance [new file with mode: 0644]

index 1e44180..0e0b93a 100644 (file)
 #     ln -s bash_completion /etc/bash_completion.d/mdk
 #     source /etc/bash_completion.d/mdk
 
+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
+}
+
 function _mdk() {
     local BIN CMD CUR PREV OPTS
     COMPREPLY=()
@@ -205,6 +217,13 @@ function _mdk() {
     return 0
 }
 
+# MDK autocomplete
 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
new file mode 100644 (file)
index 0000000..c4f1151
--- /dev/null
@@ -0,0 +1,56 @@
+#
+# 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 a function to quickly go to into an MDK instance.
+#
+# To install on Ubuntu, source this file into your ~/.bashrc file:
+#
+#   if [ -f /usr/share/moodle-sdk/extra/goto_instance ]; then
+#       . /usr/share/moodle-sdk/extra/goto_instance
+#   fi
+#
+# Then source ~/.bashrc:
+#
+#   source ~/.bashrc
+#
+
+# Go to instance directory.
+function gt() {
+    DIR=`mdk config show dirs.www`
+    eval DIR="$DIR/$1"
+    if [[ ! -d $DIR ]]; then
+        echo "Could not resolve path"
+        return
+    fi
+    cd "$DIR"
+}
+
+# Go to instance data directory.
+function gtd() {
+    DIR=`mdk config show dirs.storage`
+    DATADIR=`mdk config show dataDir`
+    eval DIR="$DIR/$1/$DATADIR"
+    if [[ ! -d $DIR ]]; then
+        echo "Could not resolve path"
+        return
+    fi
+    cd $DIR
+}
\ No newline at end of file