Skip to content

Commit

Permalink
Respect -a and -A flags to declare/typeset.
Browse files Browse the repository at this point in the history
This gets us a bit further in the bash_completion script.
  • Loading branch information
Andy Chu committed Sep 22, 2018
1 parent 1413294 commit 4ff4f25
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
8 changes: 7 additions & 1 deletion core/cmd_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,13 @@ def _Dispatch(self, node, fork_external):
assert isinstance(val, runtime.value), val
else:
# e.g. 'readonly x' or 'local x'
val = None # only changing flags
if var_flags_e.Array in flags:
val = runtime.StrArray([])
elif var_flags_e.AssocArray in flags:
# TODO: AssocArray
val = runtime.StrArray([])
else:
val = None # 'export a' -- only changing flags, may exist

# NOTE: In bash and mksh, declare -a myarray makes an empty cell with
# Undef value, but the 'array' attribute.
Expand Down
2 changes: 1 addition & 1 deletion core/runtime.asdl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module runtime
-- For storing a variable.
cell = (value val, bool exported, bool readonly)

var_flags = Exported | ReadOnly
var_flags = Exported | ReadOnly | Array | AssocArray
scope = TempEnv | LocalOnly | GlobalOnly | Dynamic

-- For assignment, evaluated to osh_ast.lhs_expr
Expand Down
6 changes: 5 additions & 1 deletion core/word_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ def ParseAssignFlags(flag_args):
flags.append(var_flags_e.Exported)
elif char == 'r':
flags.append(var_flags_e.ReadOnly)
elif char == 'a':
flags.append(var_flags_e.Array)
elif char == 'A':
flags.append(var_flags_e.AssocArray)
else:
# -a is ignored right now?
# TODO: Throw an error?
pass
return flags

12 changes: 8 additions & 4 deletions scripts/complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ list-distro() {
}

# After running this, source testdata/completion/git-completion.bash
git-demo() {
env -i OSH_CRASH_DUMP_DIR=_tmp bin/osh
fresh-osh-with-dump() {
env -i OSH_CRASH_DUMP_DIR=_tmp bin/osh "$@"
}

bash-completion() {
# This is a patched version
env -i OSH_CRASH_DUMP_DIR=_tmp bin/osh \
/usr/share/bash-completion/bash_completion.osh
fresh-osh-with-dump /usr/share/bash-completion/bash_completion.osh
}

# This should do nothing
git-completion() {
fresh-osh-with-dump testdata/completion/git-completion.bash
}

"$@"

0 comments on commit 4ff4f25

Please sign in to comment.