Skip to content

Commit

Permalink
Basic implementation of extended glob.
Browse files Browse the repository at this point in the history
Several tests in spec/extended-glob.test.sh now pass.

TODO: We might want to allow it only within [[ and case (fnmatch), but
not file system globbing.

Progress with bash_completion: now running into associative array
problem.
  • Loading branch information
Andy Chu committed Sep 22, 2018
1 parent 8baaa40 commit f264a83
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 6 additions & 4 deletions core/word_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,12 @@ def _EvalWordPart(self, part, part_vals, quoted=False):
part_vals.append(v)

elif part.tag == word_part_e.ExtGlobPart:
e_die('Unxpected extglob', part=part)
#log('part %s', part)
#v = runtime.StringPartValue('TODO', False)
#part_vals.append(v)
part_vals.append(runtime.StringPartValue(part.op.val, False))
for i, w in enumerate(part.arms):
if i != 0:
part_vals.append(runtime.StringPartValue('|', False)) # separator
self._EvalWordToParts(w, True, part_vals) # eval like quoted
part_vals.append(runtime.StringPartValue(')', False)) # closing )

else:
raise AssertionError(part.__class__.__name__)
Expand Down
9 changes: 9 additions & 0 deletions native/libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <limits.h>
#include <stdlib.h>

// Enable GNU extensions in fnmatch.h.
// TODO: Need a configure option for this.
#define _GNU_SOURCE 1

#include <fnmatch.h>
#include <glob.h>
#ifdef __FreeBSD__
Expand Down Expand Up @@ -55,7 +59,12 @@ func_fnmatch(PyObject *self, PyObject *args) {
return NULL;
}

#ifdef _GNU_SOURCE
int flags = FNM_EXTMATCH;
#else
int flags = 0;
#endif

int ret = fnmatch(pattern, str, flags);

switch (ret) {
Expand Down
6 changes: 6 additions & 0 deletions scripts/complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,10 @@ git-demo() {
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
}

"$@"

0 comments on commit f264a83

Please sign in to comment.