[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.90-76-gafb2fdd

Ville Skyttä ville.skytta at iki.fi
Sat Nov 26 21:33:14 UTC 2011


The following commit has been merged in the master branch:
commit afb2fdd010c34283314fc44ec3e7c8dbfea98a47
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Sat Nov 26 23:28:08 2011 +0200

    export: Fix many use cases, add option completion.

diff --git a/completions/export b/completions/export
index 557c52c..42273a9 100644
--- a/completions/export
+++ b/completions/export
@@ -3,23 +3,59 @@
 _export()
 {
     local cur prev words cword
-    _init_completion || return
+    _init_completion -n = || return
 
-    case ${words[@]} in
-        *=\$*)
-            COMPREPLY=( $( compgen -v -P '$' -- "${cur#*=\$}" ) )
+    local i action=variable remove=false
+    for (( i=1; i < cword; i++ )); do
+        case ${words[i]} in
+            -p)
+                return
+                ;;
+            -*f*)
+                action=function
+                ;;&
+            -*n*)
+                remove=true
+                ;;
+            -*)
+                continue
+                ;;
+        esac
+        break
+    done
+
+    [[ $cur == *=\$* ]] && { cur=${cur#*=}; _variables; } && return
+
+    case $cur in
+        *=)
+            local pval=$( quote "$( eval printf %s \"\$${cur%=}\" )" )
+            # Complete previous value if it's not empty.
+            if [[ $pval != \'\' ]]; then
+                COMPREPLY=( "$pval" )
+            else
+                cur=${cur#*=}
+                _filedir
+            fi
             ;;
-        *[^=])
-            COMPREPLY=( $( compgen -v -S '=' -- "$cur" ) )
+        *=*)
+            cur=${cur#*=}
+            _filedir
             ;;
-        *=)
-            COMPREPLY=( "$( eval echo -n \"$`echo ${cur%=}`\" |
-                ( echo -n \'
-                  sed -e 's/'\''/'\''\\\'\'''\''/g'
-                  echo -n \' ) )" )
+        *)
+            if [[ $cword -eq 1 && $cur == -* ]]; then
+                COMPREPLY=( $( compgen -W \
+                    '-p $( _parse_usage "$1" )' -- "$cur" ) )
+                return
+            fi
+            local suffix
+            if ! $remove; then
+                suffix+==
+                compopt -o nospace
+            fi
+            COMPREPLY=( $( compgen -A $action -S "$suffix" -- "$cur" ) )
             ;;
     esac
 } &&
-complete -F _export -o default -o nospace export
+complete -F _export export
 
 # ex: ts=4 sw=4 et filetype=sh
diff --git a/test/completion/export.exp b/test/completion/export.exp
new file mode 100644
index 0000000..bab517a
--- /dev/null
+++ b/test/completion/export.exp
@@ -0,0 +1 @@
+assert_source_completions export
diff --git a/test/lib/completions/export.exp b/test/lib/completions/export.exp
new file mode 100644
index 0000000..84cb917
--- /dev/null
+++ b/test/lib/completions/export.exp
@@ -0,0 +1,55 @@
+proc setup {} {
+    save_env
+}
+
+
+proc teardown {} {
+    assert_env_unmodified {
+        /OLDPWD=/d
+    }
+}
+
+
+setup
+
+
+assert_complete_any "export BASH"
+sync_after_int
+
+
+assert_complete_any "export -n BASH"
+sync_after_int
+
+
+assert_no_complete "export -p "
+sync_after_int
+
+
+assert_complete_dir {bar "bar bar.d/" foo foo.d/} "export FOO=" \
+    fixtures/shared/default
+sync_after_int
+
+
+assert_complete_dir {foo foo.d/} "export FOO=f" fixtures/shared/default "" \
+    -expect-cmd-minus f
+sync_after_int
+
+
+# Functions: _export, _expand, ...
+assert_complete_any "export -fn _ex"
+sync_after_int
+
+
+assert_complete_any "export -f -n _ex"
+sync_after_int
+
+
+assert_complete_any "export FOO=\$BASH"
+sync_after_int
+
+
+assert_complete_any "export -"
+sync_after_int
+
+
+teardown

-- 
bash-completion



More information about the Bash-completion-commits mailing list