export: Fix many use cases, add option completion.
This commit is contained in:
parent
3a7f1d3de3
commit
afb2fdd010
@ -3,23 +3,59 @@
|
|||||||
_export()
|
_export()
|
||||||
{
|
{
|
||||||
local cur prev words cword
|
local cur prev words cword
|
||||||
_init_completion || return
|
_init_completion -n = || return
|
||||||
|
|
||||||
case ${words[@]} in
|
local i action=variable remove=false
|
||||||
*=\$*)
|
for (( i=1; i < cword; i++ )); do
|
||||||
COMPREPLY=( $( compgen -v -P '$' -- "${cur#*=\$}" ) )
|
case ${words[i]} in
|
||||||
|
-p)
|
||||||
|
return
|
||||||
;;
|
;;
|
||||||
*[^=])
|
-*f*)
|
||||||
COMPREPLY=( $( compgen -v -S '=' -- "$cur" ) )
|
action=function
|
||||||
|
;;&
|
||||||
|
-*n*)
|
||||||
|
remove=true
|
||||||
;;
|
;;
|
||||||
|
-*)
|
||||||
|
continue
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
break
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ $cur == *=\$* ]] && { cur=${cur#*=}; _variables; } && return
|
||||||
|
|
||||||
|
case $cur in
|
||||||
*=)
|
*=)
|
||||||
COMPREPLY=( "$( eval echo -n \"$`echo ${cur%=}`\" |
|
local pval=$( quote "$( eval printf %s \"\$${cur%=}\" )" )
|
||||||
( echo -n \'
|
# Complete previous value if it's not empty.
|
||||||
sed -e 's/'\''/'\''\\\'\'''\''/g'
|
if [[ $pval != \'\' ]]; then
|
||||||
echo -n \' ) )" )
|
COMPREPLY=( "$pval" )
|
||||||
|
else
|
||||||
|
cur=${cur#*=}
|
||||||
|
_filedir
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*=*)
|
||||||
|
cur=${cur#*=}
|
||||||
|
_filedir
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
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
|
esac
|
||||||
} &&
|
} &&
|
||||||
complete -F _export -o default -o nospace export
|
complete -F _export export
|
||||||
|
|
||||||
# ex: ts=4 sw=4 et filetype=sh
|
# ex: ts=4 sw=4 et filetype=sh
|
||||||
|
1
test/completion/export.exp
Normal file
1
test/completion/export.exp
Normal file
@ -0,0 +1 @@
|
|||||||
|
assert_source_completions export
|
55
test/lib/completions/export.exp
Normal file
55
test/lib/completions/export.exp
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user