Skip to content

Commit

Permalink
Minor work on ~/.bashrc and completion.
Browse files Browse the repository at this point in the history
- Define common -A actions for 'complete' and 'compgen'.
- Make shopt -s extglob and progcomp no-ops.
  • Loading branch information
Andy Chu committed Sep 15, 2018
1 parent 6a2e17e commit 04e2cf9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
38 changes: 30 additions & 8 deletions core/comp_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@


def _DefineOptions(spec):
"""Common -o options for complete and compgen."""

# bashdefault, default, filenames, nospace are used in git
spec.Option(None, 'bashdefault',
help='If nothing matches, perform default bash completions')
Expand All @@ -24,17 +26,39 @@ def _DefineOptions(spec):
spec.Option(None, 'nospace',
help="Don't append a space to words completed at the end of the line")

def _DefineActions(spec):
"""Common -A actions for complete and compgen."""

# NOTE: git-completion.bash uses -f and -v.
# My ~/.bashrc on Ubuntu uses -d, -u, -j, -v, -a, -c, -b
spec.InitActions()
spec.Action(None, 'function')
spec.Action('a', 'alias')
spec.Action('b', 'binding')
spec.Action('c', 'command')
spec.Action('d', 'directory')
spec.Action('f', 'file')
spec.Action('j', 'job')
spec.Action('u', 'user')
spec.Action('v', 'variable')
spec.Action(None, 'helptopic') # help
spec.Action(None, 'setopt') # set -o
spec.Action(None, 'shopt') # shopt -s
spec.Action(None, 'signal') # kill -s


# git-completion.sh uses complete -o and complete -F
COMPLETE_SPEC = args.FlagsAndOptions()
COMPLETE_SPEC.ShortFlag('-E', args.Str,

_DefineOptions(COMPLETE_SPEC)
_DefineActions(COMPLETE_SPEC)

COMPLETE_SPEC.ShortFlag('-E',
help='Define the compspec for an empty line')
COMPLETE_SPEC.ShortFlag('-D', args.Str,
COMPLETE_SPEC.ShortFlag('-D',
help='Define the compspec that applies when nothing else matches')
COMPLETE_SPEC.ShortFlag('-F', args.Str, help='Complete with this function')

_DefineOptions(COMPLETE_SPEC)


def Complete(argv, ex, funcs, comp_lookup):
"""complete builtin - register a completion function.
Expand Down Expand Up @@ -75,11 +99,9 @@ def Complete(argv, ex, funcs, comp_lookup):


COMPGEN_SPEC = args.FlagsAndOptions() # for -o and -A
COMPGEN_SPEC.InitActions()
COMPGEN_SPEC.Action(None, 'function')
COMPGEN_SPEC.Action('f', 'file')
COMPGEN_SPEC.Action('v', 'variable')

_DefineOptions(COMPGEN_SPEC)
_DefineActions(COMPGEN_SPEC)


def CompGen(argv, funcs, mem):
Expand Down
6 changes: 5 additions & 1 deletion core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,11 @@ def __init__(self, mem, readline):
# these.
self.nullglob = False
self.failglob = False

# No-op for bash compatibility. We always expand aliases.
self.expand_aliases = False
self.extglob = False # No-op for bash compatibility.
self.progcomp = False # ditto

#
# OSH-specific options that are not yet implemented.
Expand Down Expand Up @@ -251,7 +254,8 @@ def SetOption(self, opt_name, b):
new_val = runtime.Str(':'.join(names))
self.mem.InternalSetGlobal('SHELLOPTS', new_val)

SHOPT_OPTIONS = ('nullglob', 'failglob', 'expand_aliases')
SHOPT_OPTIONS = ('nullglob', 'failglob', 'expand_aliases', 'extglob',
'progcomp')

def SetShoptOption(self, opt_name, b):
""" For shopt -s/-u. """
Expand Down

0 comments on commit 04e2cf9

Please sign in to comment.