You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2013/08/01 17:49:33 UTC

[1/2] git commit: Add command-line completion script, with installation docs

Updated Branches:
  refs/heads/master 4c9bbbc0a -> 753214ca7


Add command-line completion script, with installation docs


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/18ff4405
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/18ff4405
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/18ff4405

Branch: refs/heads/master
Commit: 18ff440559126d02a46c1ae185b6cd8b2f69f9fe
Parents: 4c9bbbc
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Aug 1 11:28:32 2013 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Thu Aug 1 11:28:42 2013 -0400

----------------------------------------------------------------------
 doc/bash.md                |  21 ++++++++
 scripts/cordova.completion | 105 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 126 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/18ff4405/doc/bash.md
----------------------------------------------------------------------
diff --git a/doc/bash.md b/doc/bash.md
new file mode 100644
index 0000000..b870071
--- /dev/null
+++ b/doc/bash.md
@@ -0,0 +1,21 @@
+Bash shell support
+==================
+
+Cordova CLI comes bundled with a script which provides command-line tab-completion for Bash. If you're running a sufficiently
+Unix-y operating system (Linux, BSD, OS X) you can install this to make typing cordova command lines easier.
+
+Installation
+------------
+
+### Linux
+
+To install on a Linux or BSD system, copy the `scripts/cordova.completion` file to your `/etc/bash_completion.d` directory. This will be read the next time you start a new shell.
+
+### OS X
+
+On OS X, put the `scripts/cordova.completion` file anywhere readable, and add the following line to the end of your `~/.bashrc` file:
+
+    source <path to>/cordova.completion
+
+This will be read the next time you start a new shell.
+

http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/18ff4405/scripts/cordova.completion
----------------------------------------------------------------------
diff --git a/scripts/cordova.completion b/scripts/cordova.completion
new file mode 100644
index 0000000..b6ddefd
--- /dev/null
+++ b/scripts/cordova.completion
@@ -0,0 +1,105 @@
+platforms() {
+    get_cordova && COMPREPLY=( $(compgen -W "$(${CORDOVA_BIN} platform ls  | tr -d "[]',")" -- $1) )
+}
+
+plugins() {
+    get_cordova && COMPREPLY=( $(compgen -W "$(${CORDOVA_BIN} plugin ls  | tr -d "[]',")" -- $1) )
+}
+
+get_cordova() {
+    local cordova
+    if [[ -n "${CORDOVA_BIN}" ]]; then return 0; fi
+    cordova=$(eval echo ${COMP_WORDS[0]})
+    if [[ -x $cordova ]]; then CORDOVA_BIN=$cordova; return 0; fi
+    cordova=$(which cordova)
+    if [[ $? -eq 0 ]]; then CORDOVA_BIN=$cordova; return 0; fi
+    return 1
+}
+
+get_top_level_dir() {
+    local path
+    path=$(pwd)
+    while [ $path != '/' ]; do
+        if [ -d $path/.cordova ]; then
+            echo $path
+            return 0
+        fi
+        path=$(dirname $path)
+    done
+    return 1
+}
+
+_cordova()
+{
+    local cur prev opts
+    COMPREPLY=()
+    cur="${COMP_WORDS[COMP_CWORD]}"
+
+    # Skip over any initial command line switches
+    local i=1
+    while [[ $i -lt ${#COMP_WORDS[*]} ]] && [[ "${COMP_WORDS[${i}]}" == -* ]]; do
+        i=$((i+1));
+    done
+
+    # For the first word, supply all of the valid top-level commands
+    if [[ ${COMP_CWORD} -eq $i ]]; then
+        opts="create platform plugin prepare compile build emulate serve"
+        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+        return 0
+    fi
+
+    case "${COMP_WORDS[$i]}" in
+        create)
+            if [[ ${COMP_CWORD} -eq $((i+1)) ]]; then
+                COMPREPLY=( $(compgen -d -- ${cur}) )
+                return 0
+            fi
+            ;;
+        platform)
+            if [[ ${COMP_CWORD} -eq $((i+1)) ]]; then
+                opts="add rm remove ls"
+                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+                return 0
+            fi
+            case "${COMP_WORDS[$((i+1))]}" in
+                add)
+                    opts="ios android wp7 wp8 blackberry www"
+                    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+                    return 0;
+                    ;;
+                rm|remove)
+                    platforms ${cur}
+                    return 0
+                    ;;
+            esac
+            ;;
+        plugin)
+            if [[ ${COMP_CWORD} -eq $((i+1)) ]]; then
+                opts="add rm remove ls"
+                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
+                return 0
+            fi
+            case "${COMP_WORDS[$((i+1))]}" in
+                add)
+                    COMPREPLY=( $(compgen nospace -d -- ${cur}) )
+                    return 0;
+                ;;
+                rm|remove)
+                    plugins ${cur}
+                    return 0
+                    ;;
+            esac
+            ;;
+        prepare|compile|build|emulate)
+            platforms ${cur}
+            return 0
+            ;;
+        serve)
+            if [[ ${COMP_CWORD} -eq $((i+1)) ]]; then
+                platforms ${cur}
+                return 0
+            fi
+            ;;
+    esac
+}
+complete -F _cordova cordova


[2/2] git commit: [CB-4200] Add Bash command-line completion

Posted by ia...@apache.org.
[CB-4200] Add Bash command-line completion


Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/753214ca
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/753214ca
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/753214ca

Branch: refs/heads/master
Commit: 753214ca77171b8b35bc5687b044c52de9756bf5
Parents: 18ff440
Author: Ian Clelland <ic...@chromium.org>
Authored: Thu Aug 1 11:45:26 2013 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Thu Aug 1 11:45:26 2013 -0400

----------------------------------------------------------------------
 doc/bash.md | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/753214ca/doc/bash.md
----------------------------------------------------------------------
diff --git a/doc/bash.md b/doc/bash.md
index b870071..af30490 100644
--- a/doc/bash.md
+++ b/doc/bash.md
@@ -19,3 +19,27 @@ On OS X, put the `scripts/cordova.completion` file anywhere readable, and add th
 
 This will be read the next time you start a new shell.
 
+Usage
+------
+
+It's easy! As long as your command line begins with an executable called 'cordova', just hit `<TAB>` at any point to see a list of valid completions.
+
+Examples:
+
+    $ cordova <TAB>
+    build     compile   create    emulate   platform  plugin    prepare   serve
+
+    $ cordova pla<TAB>
+
+    $ cordova platform <TAB>
+    add ls remove rm
+
+    $ cordova platform a<TAB>
+
+    $ cordova platform add <TAB>
+    android     blackberry  ios         wp7         wp8         www
+
+    $ cordova plugin rm <TAB>
+
+    $ cordova plugin rm org.apache.cordova.<TAB>
+    org.apache.cordova.file    org.apache.cordova.inappbrowser